#X3D V3.0 utf8 # Demonstration of a few event utility nodes. # # This example illustrates a push-on/push-off switch. # The TouchSensor on the green cone controls the geometry of # the red object. It alternates between a cube and a sphere. # # The EventUtility nodes wrapped up in the external PROTO # switchLocking. See switchLocking.x3dv for more details. # One of the output events (state) from the prototype is # sent to the Switch node for choosing the geometry. # # The blue cone (on the left) also implements a locking switch # using the Script node. This is done for illustrative purposes. # # Copyright 2005, Leonard Daly PROFILE Immersive # --> Define the API to the external PROTO EXTERNPROTO LockingSwitch [ inputOnly SFBool press outputOnly SFBool on outputOnly SFBool off outputOnly SFBool isOn outputOnly SFInt32 state ] "switches.x3dv#LockingSwitch" # --> Set up the environment DirectionalLight { direction -1 -1 -1 } NavigationInfo { headlight FALSE } # --> Green Cone uses EventUtilities to control geometry Transform { translation 3 0 0 children [ DEF TouchRight TouchSensor {} Shape { appearance Appearance { material Material { diffuseColor 0 1 0 } } geometry Cone {} } ] } # --> Blue Cone uses Script to control geometry Transform { translation -3 0 0 size -1 -1 -1 children [ DEF TouchLeft TouchSensor {} Shape { appearance Appearance { material Material { diffuseColor 0 0 1 } } geometry Cone {} } ] } # --> Controlled Geometry DEF GeomChoice Switch { whichChoice 0 children [ Shape { appearance Appearance { material Material { diffuseColor 1 0 0 } } geometry Box {} } Shape { appearance Appearance { material Material { diffuseColor 1 0 0 } } geometry Sphere {} } ] } # --> Define the switch mechanism (and routes) DEF Toggle LockingSwitch {} ROUTE TouchRight.isActive TO Toggle.press ROUTE Toggle.state TO GeomChoice.whichChoice # --> Define the switch mechanism (using a Script node) DEF ScriptSwitch Script { inputOnly SFBool alternate outputOnly SFInt32 choose initializeOnly SFInt32 iChoice 0 url ["switch.js"] } ROUTE TouchLeft.isActive TO ScriptSwitch.alternate ROUTE ScriptSwitch.choose TO GeomChoice.whichChoice