topical media & game development
Web3D/VR

contents
- VRML (dynamic) concepts
- nodes for assignments
- small examples

nodes for assignment
Sensors
(TouchSensor, PlaneSensor, CylinderSensor, SphereSensor),
DEF/USE,
PROTO

timers, interpolators, sensors and scripts

dissection

dissection analog case
Shape { ## # The shape
geometry Sphere { radius 2 }
## # we will modify the Material (DEF)
appearance Appearance {
material DEF MATERIAL Material {
diffuseColor 1 0 0
}
}
} #
DEF TIME TimeSensor { loop TRUE cycleInterval 5 } #
## # We use a simple ColorInterpolator (analog)
DEF COLORS ColorInterpolator {
key [ 0 0.5 1 ]
keyValue [ 1 0 0, 0 0 1, 1 0 0 ]
} #
ROUTE TIME.fraction_changed TO COLORS.set_fraction
ROUTE COLORS.value_changed TO MATERIAL.diffuseColor

dissection discrete case
Shape {
geometry Sphere { radius 2 }
appearance Appearance {
material DEF MATERIAL Material {
diffuseColor 1 0 0
}
}
}
DEF TIME TimeSensor { loop TRUE cycleInterval 5 } #
DEF COLORS Script {
eventIn SFFloat set_fraction
eventOut SFColor value_changed
url "javascript:
function set_fraction(value) {
if (value < 0.5) value_changed = '0 1 1';
else value_changed = '1 0 0';
}
"
}#
ROUTE TIME.fraction_changed TO COLORS.set_fraction
ROUTE COLORS.value_changed TO MATERIAL.diffuseColor

TimeSensor
TimeSensor {
exposedField SFTime cycleInterval 1 # (0,)
exposedField SFBool enabled TRUE
exposedField SFBool loop FALSE
exposedField SFTime startTime 0 # (-,)
exposedField SFTime stopTime 0 # (-,)
eventOut SFTime cycleTime
eventOut SFFloat fraction_changed
eventOut SFBool isActive
eventOut SFTime time
}

prototype

dissection prototype
PROTO Bulb [
exposedField SFVec3f translation 0 0 0
exposedField SFVec3f scale 1 1 1
]{
Transform {
translation IS translation
scale IS scale
children [
Shape {
geometry Sphere { radius 2 }
appearance Appearance {
material DEF MATERIAL Material { #
diffuseColor 1 0 0
}
}
} #
DEF TOUCH TouchSensor { }
DEF TIME TimeSensor { enabled FALSE loop TRUE } #
DEF SCRIPT Script {
eventIn SFFloat set_fraction
eventOut SFColor value_changed
eventIn SFTime touched
eventOut SFBool enabled
field SFBool on FALSE
url "javascript:
function touched(time) {
if (!on) {
on = 'TRUE';
enabled = 'TRUE';
} else {
on = 'FALSE';
enabled = 'FALSE';
}
}
function set_fraction(value) {
if (value < 0.5) value_changed = '1 0 0';
else value_changed = '0 1 1';
}
"
}#
ROUTE TOUCH.touchTime TO SCRIPT.touched
ROUTE SCRIPT.enabled TO TIME.enabled
ROUTE TIME.fraction_changed TO SCRIPT.set_fraction
ROUTE SCRIPT.value_changed TO MATERIAL.diffuseColor
] }
}
Bulb { translation -8 0 0 scale 0.5 0.5 0.5 }
Bulb { translation -5 0 0 }
Bulb { scale 1.5 1.5 1.5 }
Bulb { translation 5 0 0 }
Bulb { translation 8 0 0 scale 0.5 0.5 0.5 }

script
DEF SCRIPT Script {
eventIn SFFloat set_fraction
eventOut SFColor value_changed
eventIn SFTime touched
eventOut SFBool enabled
field SFBool on FALSE
url "javascript:
function touched(time) {
if (!on) {
on = 'TRUE';
enabled = 'TRUE';
} else {
on = 'FALSE';
enabled = 'FALSE';
}
}
function set_fraction(value) {
if (value < 0.5) value_changed = '1 0 0';
else value_changed = '0 1 1';
}
"
}
ROUTE SCRIPT.enabled TO TIME.enabled
ROUTE TIME.fraction_changed TO SCRIPT.set_fraction
ROUTE SCRIPT.value_changed TO MATERIAL.diffuseColor

routing
DEF TOUCH TouchSensor { }
DEF TIME TimeSensor { enabled FALSE loop TRUE }
DEF SCRIPT Script {
...
}
ROUTE TOUCH.touchTime TO SCRIPT.touched
ROUTE SCRIPT.enabled TO TIME.enabled
ROUTE TIME.fraction_changed TO SCRIPT.set_fraction
ROUTE SCRIPT.value_changed TO MATERIAL.diffuseColor
instances
Bulb { translation -8 0 0 scale 0.5 0.5 0.5 }
Bulb { translation -5 0 0 }
Bulb { scale 1.5 1.5 1.5 }
Bulb { translation 5 0 0 }
Bulb { translation 8 0 0 scale 0.5 0.5 0.5 }

TouchSensor
TouchSensor {
exposedField SFBool enabled TRUE
eventOut SFVec3f hitNormal_changed
eventOut SFVec3f hitPoint_changed
eventOut SFVec2f hitTexCoord_changed
eventOut SFBool isActive
eventOut SFBool isOver
eventOut SFTime touchTime
}

Script
Script {
exposedField MFString url []
field SFBool directOutput FALSE
field SFBool mustEvaluate FALSE
# And any number of:
eventIn eventType eventName
field fieldType fieldName initialValue
eventOut eventType eventName
}

examples
homework: annotated reference manual

Web3D/VR

(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.