I want to display a obeject that can be changed between face and line by a switch. What should I do? here is my code:
You can use a Switch
node that contains two versions of the object (one using IndexedFaceSet and one using IndexedLineSet
) and toggle between them using the Switch.whichChoice
property.
Here's an example:
Group {
children [
DEF sensor TouchSensor {}
DEF shapes Switch {
whichChoice 0
choice [
# Choice 0: Not wireframe
Shape {
appearance DEF appearance Appearance {
material Material {
emissiveColor 0 0.5 0
}
}
geometry IndexedFaceSet {
coordIndex [0 1 2 0 -1]
coord DEF coords Coordinate {
point [
-2 -2 0, 0 2 0, 2 -2 0
]
}
solid FALSE
}
}
# Choice 1: Wireframe
Shape {
appearance USE appearance
geometry IndexedLineSet {
coordIndex [0 1 2 0 -1]
coord USE coords
}
}
]
}
]
}
DEF script Script {
field SFNode shapes USE shapes
eventIn SFTime clicked
directOutput TRUE
url "javascript:
function clicked(){
if (shapes.whichChoice == 0){
shapes.whichChoice = 1;
} else {
shapes.whichChoice = 0;
}
}
"
}
ROUTE sensor.touchTime TO script.clicked