0

我想显示一个可以通过开关在面和线之间更改的对象。我应该怎么办?这是我的代码:

4

1 回答 1

0

您可以使用Switch包含两个版本的对象(一个使用 IndexedFaceSet 和一个使用 )的节点,并使用属性IndexedLineSet在它们之间切换。Switch.whichChoice

这是一个例子

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
于 2013-08-16T16:01:17.957 回答