Code for the button prototype used in Button test... comments
#VRML V2.0 utf8
PROTO Button [
field SFVec3f bPosition 0 0 0
field SFRotation bOrientation 0 1 0 0
eventOut SFBool buttonOn
]
{
Transform {
translation IS bPosition
rotation IS bOrientation
children [
DirectionalLight {
color .6 .6 .6
direction -.1 -.5 -.5
intensity .5
}
DEF buttonTouch TouchSensor {}
Shape {
appearance Appearance {
material DEF buttonColor Material {
diffuseColor 0 .5 0
specularColor .5 .5 .5
}
}
geometry IndexedFaceSet {
coord Coordinate {
point [
-.1 0 0, -.08 -.02 .02, .14 -.02 .02, .16 0 0,
-.1 0 0, -.1 -.14 0, -.08 -.12 .02, -.08 -.02 .02
-.08 -.12 .02, -.1 -.14 0, .16 -.14 0, .14 -.12 .02,
.14 -.02 .02, .14 -.12 .02, .16 -.14 0, .16 0 0,
-.08 -.02 .02, -.08 -.12 .02, .14 -.12 .02, .14 -.02 .02,
]
}
coordIndex [
0 1 2 3 0 -1
4 5 6 7 4 -1
8 9 10 11 8 -1
12 13 14 15 12 -1
16 17 18 19 16 -1
]
}
}
]
}
DEF ButtonScript Script {
eventIn SFBool isOver
eventIn SFBool isActive
field SFBool itisOver FALSE
field SFBool alredyPresed FALSE
field SFColor oldColor 0 .5 0
eventOut SFBool buttonActive IS buttonOn
eventOut SFColor changeColor
url [ "javascript:
function isActive (value) {
if (value == FALSE && itisOver == TRUE){
if (alredyPresed == FALSE) {
alredyPresed = TRUE ;
oldColor [0] = .5 ;
oldColor [1] = 0 ;
changeColor = oldColor ;
buttonActive = TRUE ;
}
else {
alredyPresed = FALSE ;
oldColor [0] = 0 ;
oldColor [1] = .5 ;
changeColor = oldColor ;
buttonActive = FALSE ;
}
}
}
function isOver (value) {
if (value == TRUE)
itisOver = TRUE ;
else
itisOver = FALSE ;
}
"]
}
ROUTE buttonTouch.isOver TO ButtonScript.isOver
ROUTE buttonTouch.isActive TO ButtonScript.isActive
ROUTE ButtonScript.changeColor TO buttonColor.diffuseColor
}