Fields and Events
The main difference between VRML 1.0 and VRML 2.0 is that every node can
send and receive events. Yes, in VRML 2.0 you can have animated objects
that react to users actions.
In VRML 2.0 when some fields of a Node are changed after the world has
been loaded an event is generated. You may have noticed that some fields
in the syntax boxes, present in the tutorial for each node, where written
in bold, well those fields are exposed fields, i.e. they can be set when
the user is viewing the world.
An exposed field can be decomposed into the following three lines:
-
eventIn set_fieldName
-
field fieldName
-
eventOut fieldName_changed
where fieldName is what appears in the Syntax boxes present in the tutorial
for each node.
An exposed field declaration implies that the node is able to receive events,
eventIn, and generate events, eventOut. eventIn in an exposed field is
used to set the field's value. When the field's value is changed, the node
in which the field is defined will generate an event.
Besides exposed fields, nodes can have other eventIn or eventOut fields,
however these fields are not present in the node's definition in a VRML
file. For a complete list of eventIn and eventOut fields in each node see
the event list.
How do I send an event to a node and how do I catch an event generated
by a node? There are two ways of doing this, using ROUTES
and scripts.
The next question is: when are events generated, other than those which
result in a field's value being changed? There are several possibilities:
Timers which generate events
at regular intervals
Touch Sensors which generate
events when the cursor is over objects within the same group
as the sensor.
Visibility Sensors which generate
events when shapes within the same group
as the sensor are visible to the user.
Dragging Sensors which generate
events when the user clicks the mouse and drags objects within the same
group as the sensor.
Proximity Sensors which generate
events when the user is within a predefined box.