#VRML V2.0 utf8 #Prototype of xbar. PROTO XBAR4 [ eventIn MFInt32 connections field SFVec3f translation 0 0 0 ] { EXTERNPROTO GLASS[] "glass.wrl" EXTERNPROTO EBEAD[exposedField SFColor color] "ebead.wrl" PROTO EXTR [ eventIn MFVec3f set_spine field MFVec3f spine [0 0 0, 1 0 0] ] { Extrusion { crossSection [ 1 1, 1 -1, -1 -1, -1 1, 1 1 ] spine IS spine set_spine IS set_spine scale 0.05 0.05 } } Transform { translation IS translation children [ Shape { geometry Box { size 2 1 0.5 } appearance Appearance { material GLASS {} } } Shape { geometry DEF B1 EXTR { spine [-0.75 -.5 0, -.75 0.5 0] } appearance Appearance { material DEF MYBEAD EBEAD {color 0 1 1} } } Shape { geometry DEF B2 EXTR { spine [-0.25 -.5 0, -.25 0.5 0] } appearance Appearance { material USE MYBEAD } } Shape { geometry DEF B3 EXTR { spine [0.25 -.5 0, 0.25 0.5 0] } appearance Appearance { material USE MYBEAD } } Shape { geometry DEF B4 EXTR { spine [0.75 -.5 0, 0.75 0.5 0] } appearance Appearance { material USE MYBEAD } } DEF TS TouchSensor {} ] } DEF CI ColorInterpolator { key [0 0.5 1] keyValue [1 0 0,0 1 0, 0 0 1] } DEF CT TimeSensor { enabled TRUE cycleTime 20.0 loop FALSE } DEF CAP Script { eventIn SFTime touchTime # Touch time eventOut SFTime startTime eventOut SFTime stopTime field SFInt32 state 0 url "javascript: function touchTime(value) { stopTime = value; startTime = value; // if (state==0) {stopTime = value; state = 1;} // else if (state==1) {startTime = value; state = 0;} }" } DEF MS Script { eventIn SFTime tt eventIn MFInt32 connections IS connections eventOut MFVec3f b1pos eventOut MFVec3f b2pos eventOut MFVec3f b3pos eventOut MFVec3f b4pos field MFInt32 lastcon [0,1,2,3] url "javascript: function initialise() { connections(lastcon); } function tt(value) { tmp = lastcon[0]; lastcon[0] = lastcon[1]; lastcon[1] = lastcon[2]; lastcon[2] = lastcon[3]; lastcon[3] = tmp; connections(lastcon); } function connections(value) { b1pos = new MFVec3f( new SFVec3f(-0.75,-0.5,0), new SFVec3f((-0.75+0.5*value[0]), 0.5,0 )); b2pos = new MFVec3f( new SFVec3f(-0.25,-0.5,0), new SFVec3f((-0.75+0.5*value[1]), 0.5,0 )); b3pos = new MFVec3f( new SFVec3f(0.25,-0.5,0), new SFVec3f((-0.75+0.5*value[2]), 0.5,0 )); b4pos = new MFVec3f( new SFVec3f(0.75,-0.5,0), new SFVec3f((-0.75+0.5*value[3]), 0.5,0 )); } " } ROUTE MS.b1pos TO B1.set_spine ROUTE MS.b2pos TO B2.set_spine ROUTE MS.b3pos TO B3.set_spine ROUTE MS.b4pos TO B4.set_spine ROUTE TS.touchTime TO MS.tt ROUTE TS.touchTime TO CAP.touchTime ROUTE CAP.startTime TO CT.startTime ROUTE CAP.stopTime TO CT.stopTime ROUTE CT.fraction_changed TO CI.set_fraction ROUTE CI.value_changed TO MYBEAD.set_color } XBAR4 {}