| 1 |
#X3D V3.2 utf8 |
| 2 |
PROFILE Interactive |
| 3 |
|
| 4 |
# Demo of ProximitySensor used to open/close doors automatically. |
| 5 |
|
| 6 |
Transform { |
| 7 |
translation 5.9366340637207031 6.2475004196166992 1.5750000476837158 |
| 8 |
rotation 1 0 -0 1.5707963705062866 |
| 9 |
children [ |
| 10 |
Viewpoint { |
| 11 |
position 0 0 0 # camera position is expressed by translation |
| 12 |
orientation -1.0220850299447193E-006 0.9999999403953552 0 3.0978422164916992 |
| 13 |
} |
| 14 |
|
| 15 |
Transform { |
| 16 |
translation 0.4 0.3 1 |
| 17 |
rotation -1.0220850299447193E-006 0.9999999403953552 0 3.0978422164916992 |
| 18 |
scale 0.06 0.06 0.06 |
| 19 |
children Collision { |
| 20 |
enabled FALSE |
| 21 |
children Shape { |
| 22 |
appearance Appearance { material Material { diffuseColor 0.5 0.5 0.5 } } |
| 23 |
geometry Text { string [ |
| 24 |
"Simple ProximitySensor demo." |
| 25 |
"Pressing 'b' toggles displaying" |
| 26 |
"of the yellow (non-collidable) boxes" |
| 27 |
"that visualize ProximitySensors." |
| 28 |
] |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
] |
| 34 |
} |
| 35 |
|
| 36 |
NavigationInfo { |
| 37 |
headlight TRUE |
| 38 |
type ["FLY", "ANY"] |
| 39 |
# "WALK" would be better, but for Castle Game Engine you may be forced |
| 40 |
# to temporarily turn collision detection off, which means that you |
| 41 |
# fall on the ground with gravity=on... |
| 42 |
avatarSize [0.25, 1.75, 0.75] |
| 43 |
speed 10 |
| 44 |
} |
| 45 |
|
| 46 |
Inline { url "deranged_house.wrl" } |
| 47 |
|
| 48 |
PROTO Door [ ] { |
| 49 |
Group { |
| 50 |
children [ |
| 51 |
DEF TimerOpen TimeSensor { } |
| 52 |
DEF OrientOpen OrientationInterpolator { |
| 53 |
key [ 0 1 ] |
| 54 |
keyValue [ 0 0 1 0, 0 0 1 1.57 ] |
| 55 |
} |
| 56 |
|
| 57 |
DEF TimerClose TimeSensor { } |
| 58 |
DEF OrientClose OrientationInterpolator { |
| 59 |
key [ 0 1 ] |
| 60 |
keyValue [ 0 0 1 1.57, 0 0 1 0 ] |
| 61 |
} |
| 62 |
|
| 63 |
DEF DoorTransform Transform { |
| 64 |
center 0 -1 0 |
| 65 |
children Inline { url "deranged_house_door.wrl" } |
| 66 |
} |
| 67 |
|
| 68 |
Transform { |
| 69 |
translation -1 0 1.3 |
| 70 |
children [ |
| 71 |
DEF ProxSens ProximitySensor { |
| 72 |
center 0 0 0 |
| 73 |
size 5 2 2.5 |
| 74 |
} |
| 75 |
DEF ProxSensVisualize Switch { |
| 76 |
whichChoice -1 |
| 77 |
children Collision { |
| 78 |
enabled FALSE |
| 79 |
children Shape { |
| 80 |
appearance Appearance { material Material { |
| 81 |
transparency 0.5 |
| 82 |
diffuseColor 2 2 0 |
| 83 |
} } |
| 84 |
geometry Box { size 5 2 2.5 } # same size of ProxSens |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
] |
| 89 |
} |
| 90 |
|
| 91 |
DEF K KeySensor { } |
| 92 |
|
| 93 |
# Script in CastleScript to open/close doors. |
| 94 |
# |
| 95 |
# While it's possible to express in simple VRML routes |
| 96 |
# to open/close doors automatically, |
| 97 |
# this causes bad artifact when doors is in the middle of opening/closing, |
| 98 |
# and yet it's again caused to close/open. Then naive mechanism |
| 99 |
# done without scripting with produce ugly jump to the beginning |
| 100 |
# of open/close animation. With script, I can check and eventually |
| 101 |
# adjust startTime to start close/open exactly when the door currently is. |
| 102 |
DEF Scr Script { |
| 103 |
inputOutput SFBool open_plays FALSE |
| 104 |
inputOutput SFBool close_plays FALSE |
| 105 |
inputOutput SFTime open_elapsedTime 0 |
| 106 |
inputOutput SFTime close_elapsedTime 0 |
| 107 |
|
| 108 |
inputOnly SFTime start_open |
| 109 |
inputOnly SFTime start_close |
| 110 |
|
| 111 |
outputOnly SFTime open_start_time |
| 112 |
outputOnly SFTime close_start_time |
| 113 |
|
| 114 |
inputOnly SFString key_press |
| 115 |
inputOutput SFInt32 prox_sensor_visualize -1 |
| 116 |
|
| 117 |
url "castlescript: |
| 118 |
function start_open(value, timestamp) |
| 119 |
if(open_plays, 1 { do nothing, return anything }, |
| 120 |
if(close_plays, |
| 121 |
close_start_time := -1000; |
| 122 |
open_start_time := timestamp - (1-close_elapsedTime), |
| 123 |
open_start_time := timestamp)) |
| 124 |
|
| 125 |
function start_close(value, timestamp) |
| 126 |
if(close_plays, 1 { do nothing, return anything }, |
| 127 |
if(open_plays, |
| 128 |
{ The crucial point: you want to start closing |
| 129 |
ih the middle of opening. |
| 130 |
|
| 131 |
The door is already partially opened, by open_elapsedTime, |
| 132 |
so cycleInterval-open_elapsedTime time already passed |
| 133 |
from closing. cycleInterval = always 1 in this case. |
| 134 |
|
| 135 |
Also, you want to actually stop opening, this can be done |
| 136 |
by just setting open_start_time to some negative value. } |
| 137 |
open_start_time := -1000; |
| 138 |
close_start_time := timestamp - (1-open_elapsedTime), |
| 139 |
close_start_time := timestamp)) |
| 140 |
|
| 141 |
function key_press(value, timestamp) |
| 142 |
when (value = 'b', |
| 143 |
{ On each 'b' press, toggle prox_sensor_visualize between -1 and 0 } |
| 144 |
prox_sensor_visualize := - prox_sensor_visualize - 1) |
| 145 |
" |
| 146 |
} |
| 147 |
] |
| 148 |
|
| 149 |
# Routes for opening/closing animation with script |
| 150 |
|
| 151 |
# pass TimerOpen/Close properties to script |
| 152 |
ROUTE TimerOpen.isActive TO Scr.open_plays |
| 153 |
ROUTE TimerOpen.elapsedTime TO Scr.open_elapsedTime |
| 154 |
ROUTE TimerClose.isActive TO Scr.close_plays |
| 155 |
ROUTE TimerClose.elapsedTime TO Scr.close_elapsedTime |
| 156 |
|
| 157 |
# link ProxSens -> script -> Timer -> interpolator -> DoorTransform.rotation |
| 158 |
ROUTE ProxSens.enterTime TO Scr.start_open |
| 159 |
ROUTE Scr.open_start_time TO TimerOpen.set_startTime |
| 160 |
ROUTE TimerOpen.fraction_changed TO OrientOpen.set_fraction |
| 161 |
ROUTE OrientOpen.value_changed TO DoorTransform.rotation |
| 162 |
|
| 163 |
ROUTE ProxSens.exitTime TO Scr.start_close |
| 164 |
ROUTE Scr.close_start_time TO TimerClose.set_startTime |
| 165 |
ROUTE TimerClose.fraction_changed TO OrientClose.set_fraction |
| 166 |
ROUTE OrientClose.value_changed TO DoorTransform.rotation |
| 167 |
|
| 168 |
# Routes to control visualization by 'b' key |
| 169 |
ROUTE K.keyPress TO Scr.key_press |
| 170 |
ROUTE Scr.prox_sensor_visualize TO ProxSensVisualize.whichChoice |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
Transform { |
| 175 |
translation 3.1 4 0 |
| 176 |
children Door { } |
| 177 |
} |
| 178 |
|
| 179 |
Transform { |
| 180 |
translation 3.1 -4 0 |
| 181 |
children Door { } |
| 182 |
} |
| 183 |
|
| 184 |
Transform { |
| 185 |
translation -11.8 -4 0 |
| 186 |
children Door { } |
| 187 |
} |
| 188 |
|
| 189 |
Transform { |
| 190 |
translation 5.1 -8 0 |
| 191 |
rotation 0 0 1 1.5707963268 # Pi/2 = 90 degrees |
| 192 |
children Door { } |
| 193 |
} |
| 194 |
|
| 195 |
Transform { |
| 196 |
translation 9.1 -8 0 |
| 197 |
rotation 0 0 1 1.5707963268 # Pi/2 = 90 degrees |
| 198 |
children Door { } |
| 199 |
} |
| 200 |
|
| 201 |
Transform { |
| 202 |
translation 11.3 -6.2 0 |
| 203 |
rotation 0 0 1 3.1415926536 # Pi |
| 204 |
children Door { } |
| 205 |
} |
| 206 |
|
| 207 |
Transform { |
| 208 |
translation 10.55 -3.1 0 |
| 209 |
rotation 0 0 1 3.1415926536 # Pi |
| 210 |
children Door { } |
| 211 |
} |
| 212 |
|
| 213 |
DirectionalLight { |
| 214 |
intensity 0 |
| 215 |
# just a hack to add pure ambient light in the scene |
| 216 |
# (using global light ambient would be better for OpenGL, but not standard VRML...) |
| 217 |
ambientIntensity 1 |
| 218 |
} |