#X3D V3.0 utf8 WorldInfo { title "Hello World" info "A small (clickable) sample world." } DEF BoxTransform Transform { children [ DEF tSensor TouchSensor { } DEF cylinder Shape { geometry Cylinder { height 2 radius 1 } # initial size appearance Appearance { material DEF mat Material { diffuseColor 1 0 0 } } } ] } DEF changeColor Script { eventIn SFTime touch eventOut SFColor newColor field SFInt32 flag 0 url [ "javascript: function initialize() { // Initialize } function touch (val, t) { //Browser.print('Hit'); if (flag == 0) { newColor[0] = 0; newColor[1] = 1; newColor[2] = 0; flag = 1; } else { newColor[0] = 1; newColor[1] = 0; newColor[2] = 0; flag = 0; } } "] } ROUTE tSensor.touchTime TO changeColor.touch ROUTE changeColor.newColor TO mat.diffuseColor