#VRML V2.0 utf8 #EXTERNPROTO ROD [field SFInt32 onoff # field SFVec3f translation # field MFRotation rotations ] "rod.wrl" PROTO TimeToColor [ eventIn SFTime startCol eventOut SFColor outCol field SFColor defCol 1 0 0 ] { Script { eventIn SFTime startCol IS startCol eventOut SFColor outCol IS outCol field SFColor defCol IS defCol url "javascript: function startCol(value) { outCol = defCol; }" } } PROTO BoolToInt [ eventIn SFBool onoff eventOut SFInt32 outint ] { Script { url "javascript: function onoff(value) { if (value) outint = 1; else outint = 0; }" } } #Prototype of a on/off switch PROTO SWITCH [ field SFInt32 onoff 0 field SFVec3f translation 0 0 0 field MFString ontext "Switch ON" field MFString offtext "Switch OFF" ] { Transform { translation IS translation children [ Shape { geometry Box { size .95 .95 0.1 } appearance Appearance { material Material { ambientIntensity 0.5 diffuseColor .8 .8 .8 } } }, Transform { translation -.3 -.4 .1 children DEF TXTSW Switch { choice [ Shape { geometry Text{ string IS offtext fontStyle FontStyle { family "SANS" size 0.1} #length .6 } appearance Appearance { material Material { diffuseColor 0 0 0 } } } Shape { geometry Text{ string IS ontext fontStyle FontStyle { family "SANS" size 0.1 } #length .6 } appearance Appearance { material Material { diffuseColor 0 0 0 } } } ] whichChoice 0 } } DEF BUTTON Transform { translation 0 0 .1 children [ Shape { geometry Box { size .2 0.2 0.1 } appearance Appearance { material DEF BUTMAT Material { ambientIntensity 0.8 diffuseColor .8 .0 .0 emissiveColor .0 .0 .0 } } }, DEF TOUCH TouchSensor {}, DEF TON TimeSensor { cycleInterval .25 startTime -1 loop FALSE }, DEF TOFF TimeSensor { cycleInterval .25 startTime -1 loop FALSE }, DEF SON PositionInterpolator { key [ 0 .8 1 ] keyValue [ 0 0 .1, 0 0 0, 0 0 0.01 ] } DEF SOFF PositionInterpolator { key [ 0 .2 1 ] keyValue [ 0 0 .01, 0 0 0, 0 0 0.1 ] } DEF TORED TimeToColor { defCol 1 0 0 } DEF TOBLUE TimeToColor { defCol 0 0 1 } DEF TOBLACK TimeToColor { defCol 0 0 0 } DEF CTRLSW BoolToInt {} DEF SwitchScript Script { eventIn SFTime startOrStopEngine eventOut SFTime startEngine eventOut SFTime stopEngine eventOut SFInt32 onoff field SFBool engineStarted FALSE url "javascript: function startOrStopEngine(value) { // start or stop engine: if (!engineStarted) { startEngine = value; engineStarted = TRUE; onoff = 1; // outCol = new SFColor(0.8,0.0,0.0); } else { stopEngine = value; engineStarted = FALSE; onoff = 0; // outCol = new SFColor(0.0,0.0,0.0); } }" } DEF OnSound AudioClip { url "bassoon.wav" } DEF OffSound AudioClip { url "cymride1.wav" } Sound { source USE OnSound } Sound { source USE OffSound } ] } ] } ROUTE TOUCH.touchTime TO SwitchScript.startOrStopEngine ROUTE SwitchScript.startEngine TO TON.startTime ROUTE SwitchScript.stopEngine TO TOFF.startTime ROUTE SwitchScript.stopEngine TO OffSound.startTime ROUTE SwitchScript.startEngine TO TORED.startCol ROUTE SwitchScript.stopEngine TO TOBLACK.startCol ROUTE TORED.outCol TO BUTMAT.set_emissiveColor ROUTE TOBLACK.outCol TO BUTMAT.set_emissiveColor ROUTE TON.fraction_changed TO SON.set_fraction ROUTE SwitchScript.startEngine TO OnSound.startTime ROUTE TOFF.fraction_changed TO SOFF.set_fraction ROUTE SON.value_changed TO BUTTON.set_translation ROUTE SOFF.value_changed TO BUTTON.set_translation ROUTE SwitchScript.onoff TO TXTSW.set_whichChoice } Transform { children [ SWITCH { translation 0 0 0 } SWITCH { translation 1 0 0 } SWITCH { translation 2 0 0 } SWITCH { translation 0 1 0 } SWITCH { translation 1 1 0 } SWITCH { translation 2 1 0 } ] }