#VRML V2.0 utf8 WorldInfo { info "Touch the light switch and light the dark blue one" } # Let it be dark ! # NavigationInfo { headlight FALSE } DEF Entry Viewpoint { position 0 2 7 description "Use this viewpoint" } # The touchsensor for putting the Light ON # Transform { translation -0.5 1 5 children [ DEF LightONSwitch TouchSensor { } Inline { url ["light-switch.wrl"] } ] } # The light, off when the file is loaded # DEF LIGHT PointLight { on FALSE location -3 2 2 } # The object to be lit, a simple dark blue ball # Shape { appearance Appearance { material Material { diffuseColor 0.0 0.0 0.4 shininess 1 } } geometry Sphere { radius 1 } } # Clicking on the green Light Switch (ON/OFF) # DEF lightONScript Script { eventIn SFBool lightONIsActive eventOut SFBool lightIsON field SFBool ON FALSE # won't work (like below) # Probably have to replace the button with a switch # url "javascript: function lightONIsActive(active) { if (ON) ON = 1; else ON = 1; lightIsON = ON; }" } # This would not work, as soon as mouse is released it flips # url "javascript: # function lightONIsActive(active) { # lightIsON = active; # }" # link activation of lightON to evenIn of lightONScript # ROUTE LightONSwitch.isActive TO lightONScript.lightONIsActive # # link "output" of lightONScript to RightView # ROUTE lightONScript.lightIsON TO LIGHT.set_on