VRML:ROUTE作为PROTO中的参数

时间:2011-10-05 14:01:32

标签: prototype routes vrml

我有一个TouchSensor对象的PROTO,我想在创建对象时将不同的ROUTE链接到它

e.g。我有

PROTO plate[]
{
  Shape {..something..}
  DEF TS TouchSensor {} 
}

我想打电话

plate{ROUTE ...}
plate{ROUTE ...}

有不同的ROUTE,但有一个PROTO

如何实现这个?

由于

1 个答案:

答案 0 :(得分:1)

您可以使用IS从原型中的TouchSensor公开事件。

例如:

#VRML V2.0 utf8

# First, define the prototype "plate".
PROTO plate [
    eventOut SFTime touched
    exposedField SFVec3f translation 0 0 0
]{

    Transform {
        translation IS translation
        children Shape{
            appearance Appearance {material Material {}}
            geometry Sphere{}
        }
    }
    TouchSensor{touchTime IS touched}
}


# Then create one or several instances of the object
DEF plate1 plate{translation -2 0 0}
DEF plate2 plate{translation 2 0 0}



DEF myscript Script{
    eventIn SFTime receive_event
    url "javascript:
    function receive_event(){
        trace('A sphere was clicked');
    }
    "
}

# Each instance had a different DEF name, so you can choose where to send the event independently from each other
# but for the example, I send them both to a script that says in the console when it was clicked
ROUTE plate1.touched TO myscript.receive_event
ROUTE plate2.touched TO myscript.receive_event