|
|
VRML Prototypes
PrototypesPrototypes can be used to create templates for 'new' nodes built up of combinations of other nodes. They enable developers to encapsulate and parameterise combinations of geometry, attributes, and behaviour. Prototypes are used like the built-in nodes. For example, the prototype below is used by creating a node ShowPosition {}. It prints the user's position and orientation to the VRML console when the user's position or orientation changes. It also gives a taste of how JavaScript can be used in a Script node.
PROTO ShowPosition [
]
{
Group {
children [
DEF FINDME ProximitySensor {
center 0 0 0
size 1000 1000 1000
}
DEF PRINTER Script {
eventIn SFVec3f set_position
eventIn SFRotation set_orientation
url "javascript:
function set_position(value, time) {
print('Position :' + value);
}
function set_orientation(value, time) {
print('Orientation :' + value);
}"
}
]
}
ROUTE FINDME.position_changed TO PRINTER.set_position
ROUTE FINDME.orientation_changed TO PRINTER.set_orientation
}
The structure of a Proto definition is as follows:
PROTO prototypename [
eventIn eventtypename name
eventOut eventtypename name
exposedField fieldtypename name defaultvalue
field fieldtypename name defaultvalue
...
]
{
Zero or more routes and prototypes
First node (defines the node type of the prototype)
Zero or more nodes (any type), routes, and prototypes
}
|
|
|
Michael Louka, October 10, 2001 |