{ "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":"ScriptComplexStateEvents.x3d"
          },
          {
            "@name":"description",
            "@content":"A lamp with 4 intensities (off low medium high) and a push-button switcher, all controlled by a Script node."
          },
          {
            "@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/ScriptComplexStateEvents.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"17 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":"ScriptComplexStateEvents.x3d"
            }
          },
          { "Background":
            {
              "@skyColor":[1,1,1]
            }
          },
          { "Viewpoint":
            {
              "@description":"Control 3-way lamp",
              "@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":"Push button to change state"
                        }
                      },
                      { "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,0.5,1],
                          "@keyValue":[0,0.25,0,0,0.05,0,0,0.25,0]
                        }
                      },
                      { "TimeSensor":
                        {
                          "@DEF":"ButtonTimer",
                          "@cycleInterval":0.3,
                          "@stopTime":1
                        }
                      },
                      { "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":
                              {
                                "-children":[
                                  {
                                    "#comment":"be sure to match initial color of script so that toggling is smooth and predictable"
                                  }
                                ],
                                "-material":
                                  { "Material":
                                    {
                                      "@DEF":"LightBulbMaterial",
                                      "@diffuseColor":[0.2,0.2,0.2]
                                    }
                                  }
                              }
                            },
                          "-geometry":
                            { "Sphere":
                              {
                                "@radius":0.5
                              }
                            }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          { "Script":
            {
              "@DEF":"ControlScript",
              "@url":["ScriptComplexStateEvents.js","https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptComplexStateEvents.js"],
              "field": [
                {
                  "@name":"buttonMotionDone",
                  "@accessType":"inputOnly",
                  "@type":"SFBool"
                },
                {
                  "@name":"buttonPushCount",
                  "@accessType":"inputOutput",
                  "@appinfo":"the buttonPushCount value toggles 0..1..2..3 to represent four states, off/low/medium/high",
                  "@type":"SFInt32",
                  "@value":0
                },
                {
                  "@name":"lightBulbColor",
                  "@accessType":"outputOnly",
                  "@appinfo":"color of lightBulb indicates off/low/medium/high",
                  "@type":"SFColor"
                }
              ]
            }
          },
          { "ROUTE":
            {
              "@fromField":"isActive",
              "@fromNode":"ButtonTimer",
              "@toField":"buttonMotionDone",
              "@toNode":"ControlScript"
            }
          },
          { "ROUTE":
            {
              "@fromField":"lightBulbColor",
              "@fromNode":"ControlScript",
              "@toField":"diffuseColor",
              "@toNode":"LightBulbMaterial"
            }
          },
          { "Transform":
            {
              "@translation":[-1,-2,0],
              "-children":[
                { "Billboard":
                  {
                    "@axisOfRotation":[0,0,0],
                    "-children":[
                      { "Switch":
                        {
                          "@DEF":"TextSwitch",
                          "@whichChoice":0,
                          "-children":[
                            {
                              "#comment":"States: 0=Off, 1=Low, 2=Medium, 3=High"
                            },
                            { "Shape":
                              {
                                "-geometry":
                                  { "Text":
                                    {
                                      "@string":["Off"],
                                      "-fontStyle":
                                        { "FontStyle":
                                          {
                                            "@DEF":"TextStyle",
                                            "@family":["SANS"],
                                            "@justify":["BEGIN","MIDDLE"],
                                            "@style":"BOLD"
                                          }
                                        }
                                    }
                                  },
                                "-appearance":
                                  { "Appearance":
                                    {
                                      "@DEF":"OffAppearance",
                                      "-material":
                                        { "Material":
                                          {
                                            "@diffuseColor":[0.6,0.6,0.6]
                                          }
                                        }
                                    }
                                  }
                              }
                            },
                            { "Shape":
                              {
                                "-geometry":
                                  { "Text":
                                    {
                                      "@string":["Low"],
                                      "-fontStyle":
                                        { "FontStyle":
                                          {
                                            "@USE":"TextStyle"
                                          }
                                        }
                                    }
                                  },
                                "-appearance":
                                  { "Appearance":
                                    {
                                      "@DEF":"LowAppearance",
                                      "-material":
                                        { "Material":
                                          {
                                            "@diffuseColor":[1,0.6,0.6]
                                          }
                                        }
                                    }
                                  }
                              }
                            },
                            { "Shape":
                              {
                                "-geometry":
                                  { "Text":
                                    {
                                      "@string":["Medium"],
                                      "-fontStyle":
                                        { "FontStyle":
                                          {
                                            "@USE":"TextStyle"
                                          }
                                        }
                                    }
                                  },
                                "-appearance":
                                  { "Appearance":
                                    {
                                      "@DEF":"MediumAppearance",
                                      "-material":
                                        { "Material":
                                          {
                                            "@diffuseColor":[0.6,1,0.6]
                                          }
                                        }
                                    }
                                  }
                              }
                            },
                            { "Shape":
                              {
                                "-geometry":
                                  { "Text":
                                    {
                                      "@string":["High"],
                                      "-fontStyle":
                                        { "FontStyle":
                                          {
                                            "@USE":"TextStyle"
                                          }
                                        }
                                    }
                                  },
                                "-appearance":
                                  { "Appearance":
                                    {
                                      "@DEF":"HighAppearance",
                                      "-material":
                                        { "Material":
                                          {
                                            "@diffuseColor":[0.6,0.6,1]
                                          }
                                        }
                                    }
                                  }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          { "ROUTE":
            {
              "@fromField":"buttonPushCount",
              "@fromNode":"ControlScript",
              "@toField":"whichChoice",
              "@toNode":"TextSwitch"
            }
          }
        ]
    }
  }
}