#VRML V2.0 utf8 ## ##@+ interpolator prototype ##@ proto (Bulb) PROTO Bulb [ exposedField SFVec3f translation 0 0 0 exposedField SFVec3f scale 1 1 1 ]{ ##@ body (part 1) Transform { translation IS translation scale IS scale children [ Shape { geometry Sphere { radius 2 } appearance Appearance { material DEF MATERIAL Material { # diffuseColor 1 0 0 } } } # ## # We add a TouchSensor DEF TOUCH TouchSensor { } DEF TIME TimeSensor { enabled FALSE loop TRUE } # ## # Now the Script has multiple functions ##@ body (part 2) -- script DEF SCRIPT Script { eventIn SFFloat set_fraction eventOut SFColor value_changed eventIn SFTime touched eventOut SFBool enabled field SFBool on FALSE ##@ script (continued) url "javascript: function touched(time) { if (!on) { on = 'TRUE'; enabled = 'TRUE'; } else { on = 'FALSE'; enabled = 'FALSE'; } } ##@ script (continued) function set_fraction(value) { if (value < 0.5) value_changed = '1 0 0'; else value_changed = '0 1 1'; } " }# ##@ routing ## # The bulb reacts to an isOver event ROUTE TOUCH.touchTime TO SCRIPT.touched ROUTE SCRIPT.enabled TO TIME.enabled ROUTE TIME.fraction_changed TO SCRIPT.set_fraction ROUTE SCRIPT.value_changed TO MATERIAL.diffuseColor ] } } ##@ instances Bulb { translation -8 0 0 scale 0.5 0.5 0.5 } Bulb { translation -5 0 0 } Bulb { scale 1.5 1.5 1.5 } Bulb { translation 5 0 0 } Bulb { translation 8 0 0 scale 0.5 0.5 0.5 } ##