1

I have a PROTO of some object with TouchSensor and I'd like to link different ROUTEs to it when creating objects

e.g. I have

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

I want to call

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

with different ROUTEs, but having one PROTO

How to implement this?

Thanks

Ilya Blokh
  • 11,923
  • 11
  • 52
  • 84

1 Answers1

1

You would use IS to expose the event from the TouchSensor in the prototype.

For example:

#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
wildpeaks
  • 7,273
  • 2
  • 30
  • 35
  • This uses Script, and Script is not available in view3dscene that I know of. Do you have another suggestion? Thanks! – John Carlson Aug 07 '23 at 02:04
  • What I want to do is pass several animation groups that contain a TimeSensor, a list of interpolators and a list of routes, and then chain all the animation groups into a list using some kind of event utilities. – John Carlson Aug 07 '23 at 02:16