如何在面部和线条之间快速移动?

时间:2013-08-16 01:38:14

标签: x3d

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

1 个答案:

答案 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