#VRML V2.0 utf8 # a simple touch and VRML script example Group { children [ DEF TouchBox TouchSensor{ } Shape { geometry Box { size 0.5 2 1 } appearance Appearance { material DEF BoxColor Material { diffuseColor 0.8 0.2 0.2 # light red } } } ] } DEF ExampleScript Script { eventOut SFColor chColor # will be set by the script eventIn SFTime tb # event connects to routine tb() field SFColor redColor 0.8 0.2 0.2 field SFColor blueColor 0.2 0.2 0.8 field SFInt32 state 0 url "vrmlscript: // VRML script is essentially JavaScript function tb() { state = (state + 1) & 1; // toggle state if(state == 0) chColor = redColor; else chColor = blueColor; }" } ROUTE TouchBox.touchTime TO ExampleScript.tb ROUTE ExampleScript.chColor TO BoxColor.set_diffuseColor Transform # give instructions { children Shape { appearance Appearance { material Material { diffuseColor 0.8 0.8 0.8 } } geometry Text { string "touch the box" } } translation 1 0 0 } # L. Allison, Department of Computer Science, Monash University, Australia