TouchSensor を持つオブジェクトの PROTO があり、オブジェクトを作成するときに別の ROUTE をそれにリンクしたい
たとえば、私は持っています
PROTO plate[]
{
Shape {..something..}
DEF TS TouchSensor {}
}
電話したい
plate{ROUTE ...}
plate{ROUTE ...}
ROUTE は異なるが、PROTO は 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