我想显示一个可以通过开关在面和线之间切换的对象。我该怎么办? 这是我的代码:
答案 0 :(得分:0)
您可以使用包含两个版本对象的Switch
节点(一个使用IndexedFaceSet,一个使用IndexedLineSet
),并使用Switch.whichChoice
属性在它们之间切换。
这是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