Cascading Events

#VRML V2.0 utf8

PROTO GlowBall [
		eventIn SFTime startTime
		eventOut SFTime finishTime
		field SFVec3f position 0 0 0
	       ]
{
   Group {
      children [
	 Transform {
	    translation IS position
	    children [
	       Shape {
		  appearance Appearance {
		     material DEF MAT Material {
			diffuseColor .3 .3 .3
		     }
		  }
		  geometry Sphere {}
	       }
	      ]
	 }
	 DEF TIMER TimeSensor { 
	    cycleInterval 1
	    startTime IS startTime
	 }
	 DEF COLORER ColorInterpolator {
	    key [ 0 .5 1 ]
	    keyValue [ 0 0 0, .9 .9 .6, 0 0 0 ]
	 }
	 DEF SCRIPT Script {
	    eventIn SFTime cycleTime
	    eventOut SFTime secondOne IS finishTime
	    field SFBool first TRUE
	    url "vrmlscript:
              function cycleTime(val) {
                if(first) {
                  first = FALSE;
                }
                else {
                  secondOne = val;
                  first = TRUE;
                }
              }"
	 }
      ]
   }
   ROUTE TIMER.fraction_changed TO COLORER.set_fraction
   ROUTE COLORER.value_changed TO MAT.emissiveColor
   ROUTE TIMER.cycleTime TO SCRIPT.cycleTime
}

Group {
   children [
      DEF TOUCH TouchSensor {}
      DEF GB1 GlowBall { position -4 0 0 }
      DEF GB2 GlowBall { position -2 0 0 }
      DEF GB3 GlowBall { position 0 0 0 }
      DEF GB4 GlowBall { position 2 0 0 }
      DEF GB5 GlowBall { position 4 0 0 }
   ]
}

ROUTE TOUCH.touchTime TO GB1.startTime
ROUTE GB1.finishTime TO GB2.startTime
ROUTE GB2.finishTime TO GB3.startTime
ROUTE GB3.finishTime TO GB4.startTime
ROUTE GB4.finishTime TO GB5.startTime


mrl