#VRML V2.0 utf8
Viewpoint {
position 0 0 5
}
NavigationInfo {
type "EXAMINE"
}
DEF Sw Switch {
choice [
# 0 球
DEF Sp0 Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
}
}
geometry Sphere {}
}
# 1 円錐
DEF Sp1 Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 1
}
}
geometry Cone {}
}
# 2 円柱
DEF Sp2 Shape {
appearance Appearance {
material Material {
diffuseColor 0 1 1
}
}
geometry Cylinder {}
}
]
}
# メニュー
Transform {
translation -1 -1.5 0
scale 0.2 0.2 0.2
children [
USE Sp0
DEF ThS0 TouchSensor {}
]
}
Transform {
translation 0 -1.5 0
scale 0.2 0.2 0.2
children [
USE Sp1
DEF ThS1 TouchSensor {}
]
}
Transform {
translation 1 -1.5 0
scale 0.2 0.2 0.2
children [
USE Sp2
DEF ThS2 TouchSensor {}
]
}
# スクリプト
DEF Sc Script {
eventIn SFTime choiceSp
eventOut SFInt32 whichChoice
field MFNode ThSs [ USE ThS0 USE ThS1 USE ThS2 ]
field SFNode thisSc USE Sc
url "javascript:
function initialize () {
// ROUTE from TouchSensor to this script is added.
for ( var i = 0; i < ThSs.length; i++ ) {
Browser.addRoute ( ThSs[i], 'touchTime', thisSc, 'choiceSp' );
}
}
function choiceSp () {
// Shape relevant to TouchSensor whose isOver is TRUE is chosen.
for ( var i = 0; i < ThSs.length; i++ ) {
if ( ThSs[i].isOver ) whichChoice = i;
}
}
"
}
ROUTE Sc.whichChoice TO Sw.whichChoice