#VRML V2.0 utf8
WorldInfo {
title "Lightbulb - toggle on and off"
info [ "Copyright 1999 by Bob Crispen " ]
}
NavigationInfo {
type [ "EXAMINE" "ANY" ]
headlight FALSE
}
Group {
children [
DEF Entry Viewpoint {
description "Entry"
position 0 0 1
}
DEF The_Box Transform {
translation -0.2 -0.2 0
rotation 0 1 0 0.78
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 0
ambientIntensity 0
}
}
geometry Box { size 0.1 0.1 0.1 }
}
]
}
DEF Lightbulb Transform {
scale 0.35 0.35 0.35
children [
# Just enough light so you can see the lightbulb
# Because this light is grouped with the lightbulb, you shouldn't
# be able to see the box.
DEF Dim_Bulb DirectionalLight {
intensity 0.3
}
Transform {
scale 0.193 0.193 0.193
children [
DEF Light1 PointLight {
intensity 1
on FALSE
}
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 1
specularColor 1 1 1
}
}
geometry Sphere {
radius 1.4
}
}
]
}
Transform {
translation 0 -0.35 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
specularColor 1 1 0
}
}
geometry Cylinder {
height 0.3
radius 0.135
}
}
]
}
DEF Sensor1 TouchSensor { }
]
}
DEF Illuminator Script {
eventIn SFBool touched
field SFBool lit FALSE
eventOut SFBool light_changed
url [ "javascript:
function touched(value) {
if (value) {
if (lit) {
lit = false;
light_changed = false;
} else {
lit = true;
light_changed = true;
}
}
}
" ]
}
]
ROUTE Sensor1.isActive TO Illuminator.touched
ROUTE Illuminator.light_changed TO Light1.set_on
}