door.wrl source
#VRML V2.0 utf8

# 視点
Viewpoint {
position 0 1.6 10
}

# ナビゲーション情報
NavigationInfo {
type "WALK"
headlight FALSE
speed 3
}

# 太陽光
DirectionalLight {
direction -1 -1 -1
ambientIntensity 1
}

# 背景
Background {
skyColor [ 0 0.3 1, 0.7 1 1 ]
skyAngle 1.57
}


# 地面
Transform {
translation 0 -0.05 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0 0.8 0
}
texture ImageTexture {
url "green.jpg"
}
textureTransform TextureTransform {
scale 50 50
}
}
geometry Box {
size 100 0.1 100
}
}
]
}

# 木の家
Group {
children [
# 壁
DEF WoodWall Group {
children [
Transform {
translation -1.5 0.25 0
rotation 0 0 1 1.5708
children [
DEF Wood Shape {
appearance Appearance {
material Material {
diffuseColor 0.6 0.2 0.0
}
texture ImageTexture {
url "wood.jpg"
}
textureTransform TextureTransform {
scale 5 2
}
}
geometry Cylinder {
radius 0.25
height 2
}
}
]
}
Transform {
translation 1.5 0.25 0
rotation 0 0 1 1.5708
children USE Wood
}
Transform {
translation -2.25 0.25 -2
rotation 1 0 0 1.5708
scale 1 2 1
children USE Wood
}
Transform {
translation 2.25 0.25 -2
rotation 1 0 0 1.5708
scale 1 2 1
children USE Wood
}
Transform {
translation 0 0.25 -4
rotation 0 0 1 1.5708
scale 1 2.5 1
children USE Wood
}
]
}
Transform {
translation 0 0.5 0
children USE WoodWall
}
Transform {
translation 0 1.0 0
children USE WoodWall
}
Transform {
translation 0 1.5 0
children USE WoodWall
}
Transform {
translation 0 2.0 0
children [
USE WoodWall
Transform {
translation 0 0.25 0
rotation 0 0 1 1.5708
scale 1 0.5 1
children USE Wood
}
]
}

]
}

# ドア
DEF Door-Tf Transform {
translation 0 1 0
center 0.495 0 0
children [
Shape {
appearance DEF Door-Ap Appearance {
material Material {
diffuseColor 0.6 0.2 0
}
texture ImageTexture {
url "wood.jpg"
}
}
geometry Box {
size 1 2 0.05
}
}
Transform {
translation -0.4 0 0
rotation 1 0 0 1.5708
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.7 0.7 0.7
}
}
geometry Cylinder {
radius 0.04
height 0.1
}
}
]
}
DEF ThS TouchSensor {}
]
}


# タイムセンサー
DEF Open-TiS TimeSensor {
cycleInterval 2
}
DEF Close-TiS TimeSensor {
cycleInterval 2
}

# ドア開閉アニメ
DEF Open-OI OrientationInterpolator {
key [ 0.0 1.0 ]
keyValue [
0 1 0 0
0 1 0 1.5708
]
}
DEF Close-OI OrientationInterpolator {
key [ 0.0 1.0 ]
keyValue [
0 1 0 1.5708
0 1 0 0
]
}

ROUTE Open-TiS.fraction_changed TO Open-OI.set_fraction
ROUTE Open-OI.value_changed TO Door-Tf.rotation
ROUTE Close-TiS.fraction_changed TO Close-OI.set_fraction
ROUTE Close-OI.value_changed TO Door-Tf.rotation


# ドア開閉スクリプト
DEF Sc Script {
eventIn SFTime touchedDoor
eventOut SFTime startTime_Open
eventOut SFTime startTime_Close
field SFBool isOpen FALSE
url "javascript:
function touchedDoor (val,et) {

isOpen = !isOpen;

if (isOpen) startTime_Open = et;
else startTime_Close = et;

}
"
}

ROUTE ThS.touchTime TO Sc.touchedDoor
ROUTE Sc.startTime_Open TO Open-TiS.startTime
ROUTE Sc.startTime_Close TO Close-TiS.startTime