{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.1",
    "@xsd:noNamespaceSchemaLocation":"https://www.web3d.org/specifications/x3d-3.1.xsd",
    "JSON schema":"https://www.web3d.org/specifications/x3d-4.0-JSONSchema.autogenerated.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"CreateVrmlFromStringRandomBoxes.x3d"
          },
          {
            "@name":"description",
            "@content":"Sample world constructed in a Script node using the EcmaScript Browser call createVrmlFromString."
          },
          {
            "@name":"creator",
            "@content":"Vincent Gardet"
          },
          {
            "@name":"translator",
            "@content":"Curt Blais"
          },
          {
            "@name":"contributor",
            "@content":"Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"23 April 2002"
          },
          {
            "@name":"modified",
            "@content":"12 October 2023"
          },
          {
            "@name":"reference",
            "@content":"CreateX3dFromStringRandomSpheres.x3d"
          },
          {
            "@name":"Image",
            "@content":"CreateVrmlFromStringRandomBoxes.png"
          },
          {
            "@name":"reference",
            "@content":"See CreateVrmlFromString tutorial at"
          },
          {
            "@name":"reference",
            "@content":"http://www.gardet.nom.fr/vrmlcity/tut_cvfs.htm"
          },
          {
            "@name":"subject",
            "@content":"create VRML from string, javascript"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/Basic/course/CreateVrmlFromStringRandomBoxes.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"20 April 2026"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, https://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"reference",
            "@content":"X3D JSON encoding: https://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "WorldInfo":
            {
              "@title":"CreateVrmlFromStringRandomBoxes.x3d"
            }
          },
          { "NavigationInfo":
            {
              "@avatarSize":[0.1,1.6,2.0],
              "@headlight":false,
              "@speed":5,
              "@type":["EXAMINE","WALK","ANY"]
            }
          },
          { "Background":
            {
              "@skyAngle":[1.1,1.57],
              "@skyColor":[0.3,0.3,1,0.4,0.4,1,0.7,0.7,0.9]
            }
          },
          { "DirectionalLight":
            {
              "@direction":[0,-0.5,-1]
            }
          },
          { "DirectionalLight":
            {
              "@direction":[-1,-0.5,0.5],
              "@intensity":0.9
            }
          },
          { "DirectionalLight":
            {
              "@direction":[1,-0.5,0.5],
              "@intensity":0.8
            }
          },
          { "Viewpoint":
            {
              "@description":"Interaction view",
              "@position":[50,1.6,150]
            }
          },
          { "Viewpoint":
            {
              "@description":"Plan (top-down) view",
              "@orientation":[1,0,0,-1.54],
              "@position":[50,200,50]
            }
          },
          { "Shape":
            {
              "-appearance":
                { "Appearance":
                  {
                    "-material":
                      { "Material":
                        {
                          "@diffuseColor":[0.3,0.3,1],
                          "@transparency":0.5
                        }
                      }
                  }
                },
              "-geometry":
                { "Box":
                  {
                    "@size":[1000,0.01,1000]
                  }
                }
            }
          },
          { "Transform":
            {
              "@translation":[50,1.6,140],
              "-children":[
                { "Billboard":
                  {
                    "-children":[
                      { "Shape":
                        {
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@diffuseColor":[0.1,0.3,0.2],
                                      "@emissiveColor":[0.3,0.6,0.9]
                                    }
                                  }
                              }
                            },
                          "-geometry":
                            { "Text":
                              {
                                "@string":["Ten random boxes","computed at runtime","(select text to recompute)"],
                                "-fontStyle":
                                  { "FontStyle":
                                    {
                                      "@justify":["MIDDLE","MIDDLE"]
                                    }
                                  }
                              }
                            }
                        }
                      },
                      { "TouchSensor":
                        {
                          "@DEF":"TouchText",
                          "@description":"Touch text to recompute random boxes"
                        }
                      },
                      {
                        "#comment":"Transparent Box makes the text much more accessible/clickable"
                      },
                      { "Shape":
                        {
                          "-geometry":
                            { "Box":
                              {
                                "@size":[8,2,0.1]
                              }
                            },
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@transparency":1
                                    }
                                  }
                              }
                            }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          {
            "#comment":"ROOT is used at initialize time as parent for randomly generated Shape children"
          },
          { "Group":
            {
              "@DEF":"HoldsAutogeneratedContent",
              "-children":[
                {
                  "#comment":"content added here at run time"
                }
              ]
            }
          },
          { "Script":
            {
              "@DEF":"BoxGeneratorScript",
              "@directOutput":true,
              "field": [
                {
                  "@name":"ModifiableExternalNode",
                  "@accessType":"initializeOnly",
                  "@type":"SFNode",
                  "-children":[
                    { "Group":
                      {
                        "@USE":"HoldsAutogeneratedContent"
                      }
                    }
                  ]
                },
                {
                  "@name":"recompute",
                  "@accessType":"inputOnly",
                  "@type":"SFBool"
                }
              ],
              "#sourceCode":[
"",
"",
"ecmascript:",
"",
"function R () {",
"\treturn Math.random();",
"}",
"function recompute (isActive) {",
"\tif (isActive==true) initialize();",
"}",
"",
"function initialize() {",
"  for (i=0; i < 10; i++) {",
"    rand1 = 100*R();",
"    rand2 = 100*R();",
"    rand3 = 20*R();",
"    rand4 = 40*R();",
"    rand5 = 20*R();",
"    sceneString ='Transform {                                                    \n' +",
"                      '   translation ' + rand1 + ' 0 ' + rand2 + ' \n' +",
"                      '   children [                                            \n' +",
"                      '           Shape {                                       \n' +",
"                      '                   appearance Appearance {               \n' +",
"                      '                      material Material {                \n' +",
"                      '                         diffuseColor ' + R() + ' ' + R() + ' ' + R() + '\n' +",
"                      '                      }                                  \n' +",
"                      '                   }                                     \n' +",
"                      '                   geometry Box {                        \n' +",
"                      '                      size ' + rand3 + ' ' + rand4 + ' ' + rand5 + '\n' +",
"                      '                   }                                     \n' +",
"                      '           }                                             \n' +",
"                      '   ]                                                     \n' +",
"                      '}                                                        \n' +",
"                      '#########################################################\n';",
"       Browser.println (sceneString);",
"       newNode = Browser.createVrmlFromString(sceneString);",
"//     newNode = Browser.createX3dFromString(sceneString);",
"       ModifiableExternalNode.children[i] = newNode[0];",
"  }",
"}",
"",
""
]
            }
          },
          { "ROUTE":
            {
              "@fromField":"isActive",
              "@fromNode":"TouchText",
              "@toField":"recompute",
              "@toNode":"BoxGeneratorScript"
            }
          }
        ]
    }
  }
}