6.回転させる
変形の有難味を見せるために回転させましょう。
回転させるだけなら TimeSensor ノードと
OrientationInterpolator ノードだけで良いのですが、
クリックして回転を開始させるには Script ノードも必要です。
#VRML V2.0 utf8
#視点設定
Viewpoint {
position 0 0 3
}
#光源設定
DirectionalLight {
direction 0 -1 0
}
#折り紙
DEF origami Transform {
translation 0 -0.707 0
children [
DEF TS TouchSensor {
}
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 1
}
}
geometry IndexedFaceSet {
coord DEF origamiPoint Coordinate {
point [
-1 0 1 #0
0 0 1 #1
1 0 1 #2
1 0 0 #3
1 0 -1 #4
0 0 -1 #5
-1 0 -1 #6
-1 0 0 #7
0 0 0 #8
]
}
coordIndex [
0 1 8 -1
1 2 8 -1
2 3 8 -1
3 4 8 -1
4 5 8 -1
5 6 8 -1
6 7 8 -1
7 0 8 -1
]
solid FALSE
}
}
]
}
#変形設定
DEF TIMER TimeSensor {
cycleInterval 15
}
DEF CI CoordinateInterpolator {
key [0 1]
keyValue [
-1 0 1 #変形前
0 0 1
1 0 1
1 0 0
1 0 -1
0 0 -1
-1 0 -1
-1 0 0
0 0 0
-0.01 0 0.01 #変形後
0 0.707 0.707
0.01 0 0.01
0.707 0.707 0
0.01 0 -0.01
0 0.707 -0.707
-0.01 0 -0.01
-0.707 0.707 0
0 1.414 0
]
}
ROUTE TS.touchTime TO TIMER.startTime
ROUTE TIMER.fraction_changed TO CI.set_fraction
ROUTE CI.value_changed TO origamiPoint.set_point
#回転
DEF roundScript Script {
eventIn SFTime touchTime
eventOut SFBool loop
url "javascript:
function touchTime(value){
loop=TRUE;
}"
}
DEF roundTIMER TimeSensor {
cycleInterval 10
}
DEF OI OrientationInterpolator {
key [0 0.5 1]
keyValue [0 1 0 0, 0 1 0 3.14, 0 1 0 6.28]
}
ROUTE TS.touchTime TO roundScript.touchTime
ROUTE TS.touchTime TO roundTIMER.startTime
ROUTE roundScript.loop TO roundTIMER.loop
ROUTE roundTIMER.fraction_changed TO OI.set_fraction
ROUTE OI.value_changed TO origami.set_rotation
|
そろそろ VRML の楽しさが表れてきましたね。