Switch
と書いて、その後に { } をつけて、
{ } の中にいくつかのシーンを書きます。
Switch を使ったアニメの実例を見ましょう。
以下の例では、Switch の後の { } の中で
Sphere(球)、Box(直方体)、Cone(円すい)が
記述されており、交互に1個づつ選択表示されます。
#VRML V2.0 utf8
Switch {
whichChoice -1
choice [
DEF Shape1 Group {
children Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
}
}
geometry Sphere { }
}
},
DEF Shape2 Group {
children [
Transform {
rotation 1 1 1 1
children Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 0
}
}
geometry Box { }
}
}
]
},
DEF Shape3 Group {
children [
Transform {
rotation 1 1 1 1
children Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 1
}
}
geometry Cone { }
}
}
]
},
]
}
DEF Timer1 TimeSensor {
cycleInterval 2.0
loop TRUE
startTime 1.0
stopTime 0.0
}
DEF Sw1 Switch {
choice [
USE Shape1,
USE Shape2,
USE Shape3,
]
}
DEF Sc1 Script {
eventIn SFTime cycleTime
eventOut SFInt32 whichChoice
url "javascript:
function initialize() {
whichChoice = 0;
}
function cycleTime( value, time ) {
if ( whichChoice == 2 ) whichChoice = 0;
else ++whichChoice;
}"
}
ROUTE Timer1.cycleTime_changed TO Sc1.set_cycleTime
ROUTE Sc1.whichChoice_changed TO Sw1.set_whichChoice
|