www.pudn.com > vrmlExample.rar > 8-5-2.wrl
#VRML V2.0 utf8
Viewpoint
{
position 0 0 15
orientation 0 0 1 0
fieldOfView 0.8
}
Background
{
skyColor [ 0 0 0.2,
0.1 0.1 0.8,
0.7 0.8 0.9
]
skyAngle [1 1.57]
groundColor [ 0.0 0.0 0.0,
0.5 0.4 0.3,
0.3 0.3 0.3
]
groundAngle [1 1.57]
}
Transform
{
translation -10 0 0
children
[
DEF Switch1 TouchSensor {}
Shape
{
geometry Sphere{}
appearance Appearance
{
material DEF SphereColor1 Material
{
diffuseColor 1 0 0
}
}
}
]
}
Transform
{
translation -6 0 0
children
[
DEF Switch2 TouchSensor {}
Shape
{
geometry Sphere{}
appearance Appearance
{
material DEF SphereColor2 Material
{
diffuseColor 1 1 0
}
}
}
]
}
Transform
{
translation -2 0 0
children
[
DEF Switch3 TouchSensor {}
Shape
{
geometry Sphere{}
appearance Appearance
{
material DEF SphereColor3 Material
{
diffuseColor 0 1 0
}
}
}
]
}
Transform
{
translation 2 0 0
children
[
DEF Switch4 TouchSensor {}
Shape
{
geometry Sphere{}
appearance Appearance
{
material DEF SphereColor4 Material
{
diffuseColor 0 1 1
}
}
}
]
}
Transform
{
translation 6 0 0
children
[
DEF Switch5 TouchSensor {}
Shape
{
geometry Sphere{}
appearance Appearance
{
material DEF SphereColor5 Material
{
diffuseColor 0 0 1
}
}
}
]
}
Transform
{
translation 10 0 0
children
[
DEF Switch6 TouchSensor {}
Shape
{
geometry Sphere{}
appearance Appearance
{
material DEF SphereColor6 Material
{
diffuseColor 1 0 1
}
}
}
]
}
Transform
{
translation 0 4 0
children
[
DEF Switch7 TouchSensor {}
Shape
{
geometry Box{}
appearance Appearance
{
material DEF BoxColor Material
{
diffuseColor 1 1 1
}
}
}
]
}
DEF SetColor Script
{
eventIn SFBool onclick1
eventIn SFBool onclick2
eventIn SFBool onclick3
eventIn SFBool onclick4
eventIn SFBool onclick5
eventIn SFBool onclick6
eventIn SFBool onclick7
eventOut SFColor newColor
field SFBool on FALSE
url "vrmlscript:
function onclick1(value)
{
newColor.r=1;
newColor.g=0;
newColor.b=0;
}
function onclick2(value)
{
newColor.r=1;
newColor.g=1;
newColor.b=0;
}
function onclick3(value)
{
newColor.r=0;
newColor.g=1;
newColor.b=0;
}
function onclick4(value)
{
newColor.r=0;
newColor.g=1;
newColor.b=1;
}
function onclick5(value)
{
newColor.r=0;
newColor.g=0;
newColor.b=1;
}
function onclick6(value)
{
newColor.r=1;
newColor.g=0;
newColor.b=1;
}
function onclick7(value)
{
newColor.r=1;
newColor.g=1;
newColor.b=1;
}"
}
# Routing
ROUTE Switch1.isActive TO SetColor.onclick1
ROUTE Switch2.isActive TO SetColor.onclick2
ROUTE Switch3.isActive TO SetColor.onclick3
ROUTE Switch4.isActive TO SetColor.onclick4
ROUTE Switch5.isActive TO SetColor.onclick5
ROUTE Switch6.isActive TO SetColor.onclick6
ROUTE Switch7.isActive TO SetColor.onclick7
ROUTE SetColor.newColor TO BoxColor.set_diffuseColor