#VRML V2.0 utf8 NavigationInfo { type "EXAMINE" } DEF ROOT Group { children [ Group { children [ DEF TOUCH TouchSensor {} Shape { appearance Appearance { material DEF MAT Material {} } geometry Sphere {} } ] } ] } Sound { spatialize FALSE minFront 100 maxFront 100 minBack 100 maxBack 100 source DEF CLIP AudioClip { url "Sounds/drm_snare.wav" } } DEF SCRIPT Script { directOutput TRUE eventIn SFBool clicked eventOut MFNode newNodes field SFNode mat USE MAT field SFNode clip USE CLIP url "vrmlscript: function clicked(val, ts) { if(val) { choice = Math.random() * 3; // create a randomly placed box if(choice < 1) { size = 8; halfsize = size / 2.0; x = Math.random() * size - halfsize; y = Math.random() * size - halfsize; z = Math.random() * size - halfsize; newNodes = Browser.createVrmlFromString('Transform {' + ' translation ' + x + ' ' + y + ' ' + z + ' children Shape {' + ' appearance Appearance {' + ' material Material {}' + ' }' + ' geometry Box { size 1 1 1 }' + ' }' + '}'); } // change the sphere's color else if(choice < 2) { mat.diffuseColor = new SFColor(Math.random(), Math.random(), Math.random()); } // play an audio clip else { clip.stopTime = 0; clip.startTime = ts+.5; } } } " } ROUTE TOUCH.isActive TO SCRIPT.clicked ROUTE SCRIPT.newNodes TO ROOT.addChildren
mrl