0

スイッチで面と線を切り替えられるオブジェクトを表示したい。私は何をすべきか?ここに私のコードがあります:

4

1 に答える 1

0

Switchオブジェクトの 2 つのバージョン (1 つは IndexedFaceSet を使用し、もう 1 つは を使用) を含むノードを使用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 に答える