{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.3",
    "@xsd:noNamespaceSchemaLocation":"https://www.web3d.org/specifications/x3d-3.3.xsd",
    "JSON schema":"https://www.web3d.org/specifications/x3d-4.0-JSONSchema.autogenerated.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"ScriptSimpleStateEvents.x3d"
          },
          {
            "@name":"description",
            "@content":"A Script node drives an animated push button that turns a light on and off."
          },
          {
            "@name":"creator",
            "@content":"Leonard Daly and Don Brutzman"
          },
          {
            "@name":"created",
            "@content":"10 June 2006"
          },
          {
            "@name":"modified",
            "@content":"20 October 2019"
          },
          {
            "@name":"reference",
            "@content":"https://X3dGraphics.com"
          },
          {
            "@name":"reference",
            "@content":"https://www.web3d.org/x3d/content/examples/X3dResources.html"
          },
          {
            "@name":"rights",
            "@content":"Copyright 2006, Daly Realism and Don Brutzman"
          },
          {
            "@name":"subject",
            "@content":"X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptSimpleStateEvents.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"25 March 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":"ScriptSimpleStateEvents.x3d"
            }
          },
          { "Background":
            {
              "@skyColor":[1,1,1]
            }
          },
          { "Viewpoint":
            {
              "@description":"click switch to toggle light",
              "@orientation":[-0.993,0.101,-0.063,1.06],
              "@position":[0.06,3.63,2.29]
            }
          },
          { "Transform":
            {
              "@DEF":"PushBox",
              "@translation":[-2,0,0],
              "-children":[
                { "Transform":
                  {
                    "@DEF":"ControlBox",
                    "-children":[
                      { "Shape":
                        {
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@diffuseColor":[0,0.8,0]
                                    }
                                  }
                              }
                            },
                          "-geometry":
                            { "Box":
                              {
                                "@size":[1,0.5,1]
                              }
                            }
                        }
                      }
                    ]
                  }
                },
                { "Transform":
                  {
                    "@DEF":"ControlButton",
                    "@translation":[0,0.25,0],
                    "-children":[
                      { "TouchSensor":
                        {
                          "@DEF":"ButtonTouch",
                          "@description":"touch to toggle"
                        }
                      },
                      { "Shape":
                        {
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@diffuseColor":[1,0,0]
                                    }
                                  }
                              }
                            },
                          "-geometry":
                            { "Cylinder":
                              {
                                "@DEF":"Button",
                                "@bottom":false,
                                "@height":0.5,
                                "@radius":0.25
                              }
                            }
                        }
                      },
                      { "PositionInterpolator":
                        {
                          "@DEF":"ButtonMover",
                          "@key":[0,1],
                          "@keyValue":[0,0.25,0,0,0.05,0]
                        }
                      },
                      { "TimeSensor":
                        {
                          "@DEF":"ButtonTimer"
                        }
                      },
                      { "ROUTE":
                        {
                          "@fromField":"touchTime",
                          "@fromNode":"ButtonTouch",
                          "@toField":"startTime",
                          "@toNode":"ButtonTimer"
                        }
                      },
                      { "ROUTE":
                        {
                          "@fromField":"fraction_changed",
                          "@fromNode":"ButtonTimer",
                          "@toField":"set_fraction",
                          "@toNode":"ButtonMover"
                        }
                      },
                      { "ROUTE":
                        {
                          "@fromField":"value_changed",
                          "@fromNode":"ButtonMover",
                          "@toField":"translation",
                          "@toNode":"ControlButton"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          { "Transform":
            {
              "@DEF":"Lamp",
              "@translation":[1,0,0],
              "-children":[
                { "Transform":
                  {
                    "@DEF":"Base",
                    "-children":[
                      { "Shape":
                        {
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                    }
                                  }
                              }
                            },
                          "-geometry":
                            { "Cylinder":
                              {
                                "@height":0.5,
                                "@radius":0.25
                              }
                            }
                        }
                      }
                    ]
                  }
                },
                { "Transform":
                  {
                    "@DEF":"Bulb",
                    "@translation":[0,0.5,0],
                    "-children":[
                      { "Shape":
                        {
                          "-appearance":
                            { "Appearance":
                              {
                                "-material":
                                  { "Material":
                                    {
                                      "@DEF":"LightBulbMaterial",
                                      "@diffuseColor":[0.4,0.4,0.4]
                                    }
                                  }
                              }
                            },
                          "-geometry":
                            { "Sphere":
                              {
                                "@radius":0.5
                              }
                            }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          { "Script":
            {
              "@DEF":"ControlScript",
              "@url":["ScriptSimpleStateEvents.js","https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptSimpleStateEvents.js"],
              "field": [
                {
                  "@name":"buttonDown",
                  "@accessType":"initializeOnly",
                  "@type":"SFBool",
                  "@value":false
                },
                {
                  "@name":"buttonTimerActive",
                  "@accessType":"inputOnly",
                  "@type":"SFBool"
                },
                {
                  "@name":"newButtonPath",
                  "@accessType":"outputOnly",
                  "@type":"MFVec3f"
                },
                {
                  "@name":"lightColor",
                  "@accessType":"outputOnly",
                  "@type":"SFColor"
                }
              ]
            }
          },
          { "ROUTE":
            {
              "@fromField":"isActive",
              "@fromNode":"ButtonTimer",
              "@toField":"buttonTimerActive",
              "@toNode":"ControlScript"
            }
          },
          { "ROUTE":
            {
              "@fromField":"newButtonPath",
              "@fromNode":"ControlScript",
              "@toField":"keyValue",
              "@toNode":"ButtonMover"
            }
          },
          { "ROUTE":
            {
              "@fromField":"lightColor",
              "@fromNode":"ControlScript",
              "@toField":"diffuseColor",
              "@toNode":"LightBulbMaterial"
            }
          }
        ]
    }
  }
}