{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.0",
    "@xsd:noNamespaceSchemaLocation":"http://www.web3d.org/specifications/x3d-3.0.xsd",
    "JSON schema":"http://www.web3d.org/specifications/x3d-3.3-JSONSchema.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"Figure31.6DonutPrototype.x3d"
          },
          {
            "@name":"creator",
            "@content":"Figure 31.6, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland"
          },
          {
            "@name":"reference",
            "@content":"http://www.wiley.com/legacy/compbooks/vrml2sbk/ch31/31fig06.htm"
          },
          {
            "@name":"translator",
            "@content":"Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"30 March 2001"
          },
          {
            "@name":"modified",
            "@content":"11 January 2014"
          },
          {
            "@name":"description",
            "@content":"A donut (torus) node prototype. Also see Figures 30.5 and 31.7 for comparison."
          },
          {
            "@name":"identifier",
            "@content":"http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter31-Prototypes/Figure31.6DonutPrototype.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../../license.html"
          },
          {
            "@name":"translated",
            "@content":"19 March 2017"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"warning",
            "@content":"An experimental version of X3D JSON encoding is used for this scene.  Status online at http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "ProtoDeclare":
            {
              "@name":"Donut",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"crossSectionRadius",
                      "@accessType":"initializeOnly",
                      "@type":"SFFloat",
                      "@value":1
                    },
                    {
                      "@name":"spineRadius",
                      "@accessType":"initializeOnly",
                      "@type":"SFFloat",
                      "@value":2
                    },
                    {
                      "@name":"crossSectionResolution",
                      "@accessType":"initializeOnly",
                      "@type":"SFInt32",
                      "@value":16
                    },
                    {
                      "@name":"spineResolution",
                      "@accessType":"initializeOnly",
                      "@type":"SFInt32",
                      "@value":16
                    },
                    {
                      "@name":"set_crossSectionRadius",
                      "@accessType":"inputOnly",
                      "@type":"SFFloat"
                    },
                    {
                      "@name":"set_spineRadius",
                      "@accessType":"inputOnly",
                      "@type":"SFFloat"
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    { "Extrusion":
                      {
                        "@DEF":"DonutExtrusion",
                        "@beginCap":false,
                        "@creaseAngle":1.57,
                        "@endCap":false
                      }
                    },
                    {
                      "#comment":"Donut maker creates torus on initialization - external script. Modified script to add endpoints matching startpoints."
                    },
                    { "Script":
                      {
                        "@DEF":"DonutMakerInternalScript",
                        "field": [
                          {
                            "@name":"crossSectionRadius",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"spineRadius",
                            "@accessType":"initializeOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"crossSectionResolution",
                            "@accessType":"initializeOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"spineResolution",
                            "@accessType":"initializeOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"set_crossSectionRadius",
                            "@accessType":"inputOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"set_spineRadius",
                            "@accessType":"inputOnly",
                            "@type":"SFFloat"
                          },
                          {
                            "@name":"crossSection_changed",
                            "@accessType":"outputOnly",
                            "@type":"MFVec2f"
                          },
                          {
                            "@name":"spine_changed",
                            "@accessType":"outputOnly",
                            "@type":"MFVec3f"
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"crossSectionRadius",
                                "@protoField":"crossSectionRadius"
                              },
                              {
                                "@nodeField":"spineRadius",
                                "@protoField":"spineRadius"
                              },
                              {
                                "@nodeField":"crossSectionResolution",
                                "@protoField":"crossSectionResolution"
                              },
                              {
                                "@nodeField":"spineResolution",
                                "@protoField":"spineResolution"
                              },
                              {
                                "@nodeField":"set_crossSectionRadius",
                                "@protoField":"set_crossSectionRadius"
                              },
                              {
                                "@nodeField":"set_spineRadius",
                                "@protoField":"set_spineRadius"
                              }
                            ]
                        },
                        "#sourceText":[
"ecmascript:",
"",
"function initialize( ) {",
"    generateCrossSection( );",
"    generateSpine( );",
"}",
"",
"function set_crossSectionRadius( csr, ts )",
"{",
"    crossSectionRadius = csr;",
"//  Browser.print ('crossSectionRadius =' + crossSectionRadius);",
"    generateCrossSection( );",
"}",
"",
"function set_spineRadius( sr, ts )",
"{",
"    spineRadius = sr;",
"//  Browser.print ('spineRadius =' + spineRadius);",
"    generateSpine( );",
"}",
"",
"function generateCrossSection( )",
"{",
"    newCrossSection = new MFVec2f(); // temporary hold variable",
"    angle = 0.0;",
"    delta = 6.28 / crossSectionResolution;",
"    for ( i = 0; i <= crossSectionResolution + 1; i++ ) {",
"        newCrossSection[i][0] =  crossSectionRadius * Math.cos( angle );",
"        newCrossSection[i][1] = -crossSectionRadius * Math.sin( angle );",
"        angle += delta;",
"    }",
"    // make ends meet",
"    newCrossSection[crossSectionResolution + 1][0] = newCrossSection[0][0];",
"    newCrossSection[crossSectionResolution + 1][1] = newCrossSection[0][1];",
"",
"    crossSection_changed = newCrossSection;",
"}",
"",
"function generateSpine( )",
"{",
"    newSpine = new MFVec3f(); // temporary hold variable",
"    angle = 0.0;",
"    delta = (2 * 3.141592653) / spineResolution;",
"    for ( i = 0; i <= spineResolution; i++ ) {",
"        newSpine[i][0] = spineRadius * Math.cos( angle );",
"        newSpine[i][1] = 0.0;",
"        newSpine[i][2] = -spineRadius * Math.sin( angle );",
"        angle += delta;",
"    }",
"    // make ends meet",
"    newSpine[spineResolution + 1][0] = newSpine[0][0];",
"    newSpine[spineResolution + 1][1] = 0.0;",
"    newSpine[spineResolution + 1][2] = newSpine[0][2];",
"",
"    spine_changed = newSpine;",
"}"
]
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"spine_changed",
                        "@fromNode":"DonutMakerInternalScript",
                        "@toField":"set_spine",
                        "@toNode":"DonutExtrusion"
                      }
                    },
                    { "ROUTE":
                      {
                        "@fromField":"crossSection_changed",
                        "@fromNode":"DonutMakerInternalScript",
                        "@toField":"set_crossSection",
                        "@toNode":"DonutExtrusion"
                      }
                    }
                  ]
              }
            }
          },
          {
            "#comment":"It is a good practice to include default message linking to an example scene, in case a user tries to view this Prototype library directly."
          },
          { "Anchor":
            {
              "@description":"Figure31.7DonutExternalPrototype example",
              "@parameter":["target=_blank"],
              "@url":["Figure31.7DonutExternalPrototype.x3d","http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter31-Prototypes/Figure31.7DonutExternalPrototype.x3d","Figure31.7DonutExternalPrototype.wrl","http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter31-Prototypes/Figure31.7DonutExternalPrototype.wrl"],
              "-children":[
                { "Shape":
                  {
                    "-geometry":
                      { "Text":
                        {
                          "@string":["Figure31.6DonutPrototype","contains a prototype definition","","Click on text to see a Donut in","Figure31.7DonutExternalPrototype"],
                          "-fontStyle":
                            { "FontStyle":
                              {
                                "@justify":["MIDDLE","MIDDLE"],
                                "@size":0.8
                              }
                            }
                        }
                      },
                    "-appearance":
                      { "Appearance":
                        {
                          "-material":
                            { "Material":
                              {
                                "@diffuseColor":[0,0.6,0.6]
                              }
                            }
                        }
                      }
                  }
                }
              ]
            }
          }
        ]
    }
  }
}