Kouichi Matsuda, Yasuaki Honda matsuda@csl.sony.co.jp Sony Computer Science Laboratories Inc. also with Central Research Center, Sony Corporation
There are seven extension nodes for it: Script node, EventHandler node, SporadicTask node, PeriodicTask node , CalendarTask node, Attributes node, and ambientSound node. Notice that "fields" field is necessary in extension nodes but it is removed from the following descriptions for simplyfing.
This node defines a procedure for EventHandler nodes, SporadicTask nodes, PeriodicTask nodes and CalendarTask nodes. This node doesn't affect any other nodes.
Script node can specify inline script in the procedure field. More than one script function can be specified in the field.
FILE FORMAT/DEFAULT
Script {
procedure "" # SFString
scriptType NONE # SFEnum
}
EXAMPLE
Script {
procedure "proc change_color { obj event userData } {\n\
vsSetObjDiffuse $obj $userData;\n\
}
proc move { obj event userData } {\n\
vsObjTranslate $obj 10 0 0;\n\
}" # SFString
scriptType TCL # SFEnum
}
SCRIPT TYPE ENUM
TCL, PYTHON, JAVA, VB...
This property node defines an event handler. It is called back from a browser when an event that matches the eventType occurs on the object.
filename: specifies URL of a script file. The script file
can contain more than one script function. If
the URL is empty string, "function" name is searched from
Script node.
eventType: specifies the event type for which to call the handler
userData: specifies additional data to be passed to the event handler
function: specifies the function name that is to be added or simple
method(see below).
scriptType: specify the script type
FILE FORMAT/DEFAULT
EventHandler {
filename "" # SFString
eventType NOEVENT # SFBitMask
userData "" # SFString
function "" # SFString
scriptType INLINE # SFEnum
}
EXAMPLE
EventHandler {
filename "change.tcl" # SFString
eventType GRAB # SFBitMask
userData "red" # SFString
function "change_color" # SFString
scriptType TCL # SFEnum
}
EVENT TYPE MASK
GRAB, RELEASE, COLLISION_IN, COLLISION_OUT, WORLD_IN, WORLD_OUT,
KEY_DOWN, KEY_UP...
SCRIPT TYPE ENUM
INLINE, C, PYTHON, TCL, JAVA, VB...
About scriptType, see "Multiple
scripting language example". The script type INLINE can be used for
describing a simple method
directly. The script type "C" can be used only for specifying the built-in C
libraries (see "Buit-in C
function example").
The EventHandler procedure is called back from a browser in the following form:
void EventHandler(VsObj *obj, VsEvent *event, VsString userData); obj: is specified the object which has the event handler. event: is specified the event which is occurred. It has the following information. - the object on which the event has occurred. This object could be different from the "obj". - event type - key or button - modifier - (x, y, z) - time stamp - event type dependent information In case of COLLISION_IN/COLLISION_OUT event, the object with which "obj" collides is specified. In case of WORLD_IN/WORLD_OUT, information about the world is specified. userData: is specified the data which is specified in the "userData" field in an EventHandler node.In this example, the "change_color " function is defined in the Script
This node defines a sporadic task. It is called back from a browser when the specified time expires, and the task is removed. This node has five fields: filename, millisecond, userData, function, and scriptType. "millisecond" specifies the time when the task is executed.
FILE FORMAT/DEFAULT
SporadicTask {
filename "" # SFString
millisecond 100 # SFLong
userData "" # SFString
function "" # SFString
scriptType INLINE # SFEnum
}
EXAMPLE
SporadicTask {
filename "change.tcl" # SFString
millisecond 100 # SFLong
userData "red" # SFString
function "change_color" # SFString
scriptType TCL # SFEnum
}
The SporadicTask procedure is be called back from a browser in the
following prototype:
void SporadicTaskProc(VsObj *obj, VsEvent *event, VsString userData);
This node defines a periodic task. It is called back from a browser periodically when the specified time expires. This node has the same fields as SporadicTask node has. The task is stopped when the function returns TRUE.
FILE FORMAT/DEFAULT
PeriodicTask {
filename "" # SFString
millisecond 100 # SFLong
userData "" # SFString
function "" # SFString
scriptType INLINE # SFEnum
}
EXAMPLE
PeriodicTask {
filename "change.tcl" # SFString
millisecond 100 # SFLong
userData "red" # SFString
function "change_color" # SFString
scriptType TCL # SFEnum
}
The PeriodicTask procedure is be called back from a browser in the
following prototype:
VsBoolean PeriodicTaskProc(VsObj *obj, VsEvent *event, VsString userData);
This node defines a calendar task. It is called back from a browser when the specified date comes, and the task is removed. This node has five fields: filename, date, userData, function and scriptType. "date" specifies the date when the task is executed(e.g. "Jun 15 15:51:16 2995").
date: specify the date. e.g. "Jun 15 15:51:16 2995"
FILE FORMAT/DEFAULT
CalendarTask {
filename "" # SFString
date "" # SFString
userData "" # SFString
function "" # SFString
scriptType INLINE # SFEnum
}
FILE FORMAT/EXAMPLE
CalendarTask {
filename "change.tcl" # SFString
date "Jun 15 15:51:16 2995" # SFString
userData "red" # SFString
function "change_color" # SFString
scriptType TCL # SFEnum
}
The CalendarTask procedure is be called back from a browser in the
following prototype:
void CalendarTaskProc(VsObj *obj, VsEvent *event, VsString userData);
For example,
EventHandler {
eventType GRAB
function "set diffuseColor 1 0 0"
}
Cube {}
In this example, when user clicks the cube, its diffuse color is
changed to red. It isn't necessary to specify scriptType, becuase INLINE is
default script type.
Only the following syntax can be used for describing method.
- set RESERVED-WORD CONSTANT RESERVED-WORD diffuseColor, transparency, ambientColor... - load URLThis idea came from Mitra's paper.
Attributes node defines the object name and its attributes. The "name" can
be accessed
only in scripts. Although VRML1.0 supports DEF keyword for
naming node,
the names do not have to be unique. It is difficult to use
for accessing objects in scripts.
The name must be unique between top
objects and its sub objects.
name: object name
grasp: possible to grasp object
solid: determines if the object is passable.
collision: determines if a collision check should be performed
when the object moves.
mobile: determines if object is static
backface: backface is rendered
gouraud: gouraud shading
propagateMask: determines if event is propagated to the object's parent
assignId: determines if id is assigned. If id is assigned to an object,
it is shared among all users under multi-user environment.
FILE FORMAT/DEFAULTS
Attributes {
name "" # SFString
visible TRUE # SFBool
grasp TRUE # SFBool
solid TRUE # SFBool
collision TRUE # SFBool
mobile TRUE # SFBool
backface TRUE # SFBool
gouraud TRUE # SFBool
propagateMask all-one # SFBitMask
assignId FALSE # SFBool
}
NOTE
Solid, backface and gouraud fields should be the fields
of ShapeHint. AssignId should be "shared".
Separator {
Separator {
Attributes {
name "foo"
}
EventHandler {
filename "change.tcl"
eventType GRAB
userData "red"
function "change_color"
scriptType TCL
}
Cube {} # This cube is named "foo" and has the
# event handler.
Cube {} # This cube has no name and no event handler.
}
Cube {} # This cube has no name and no event handler.
}
When Separator of VRML 1.1 proposal is accepted, we will use VRML 1.1 scoping
rule.
filename: specify the sound data(URL).
.wav Windows WAVE (PCM)
.mid Windows MIDI
bboxSize, bboxCenter: specify the bounding cube.
autoPlay: specify if the sound plays automatically
when user enters the bounding cube.
loop: auto repeat
FILE FORMAT/DEFAULT
AmbientSound {
filename "" # SFString
bboxSize 0 0 0 # SFVec3f
bboxCenter 0 0 0 # SFVec3f
autoplay TRUE # SFBool
loop TRUE # SFBool
}
proc change_color { obj event userData } {
vsSetObjDiffuse $obj $userData;
}
proc move { obj event userData } {
vsObjTranslate $obj 10 0 0;
}
Notice that "fields" field is necessary in extension nodes but it is
removed from the following descriptions for simplyfing.
In the following example, the first cube has the name "foo" and the event handler.
Separator {
Separator {
Attributes {
name "foo"
}
EventHandler {
filename "change.tcl"
eventType GRAB
userData "red"
function "change_color"
scriptType TCL
}
Cube {} # This cube is named "foo" and has the event handler.
}
Cube {} # This cube has no name and no event handler.
}
In the following example, two event handlers share the same script.
Separator {
Separator {
EventHandler {
filename "change.tcl"
eventType GRAB
userData "red"
function "change_color"
scriptType TCL
}
Cube {} # This cube has the event handler to change its color to red.
}
EventHandler {
filename "change.tcl"
eventType GRAB
userData "blue"
function "change_color"
scriptType TCL
}
Cube {} # This cube has no name
# but has event handler to change its color to blue.
}
In the following example, two event handlers are attached to the same cube.
Separator {
Separator {
EventHandler {
filename "change.tcl"
eventType GRAB
userData "red"
function "change_color"
scriptType TCL
}
EventHandler {
filename "change.tcl"
eventType RELEASE
userData "blue"
function "change_color"
scriptType TCL
}
Cube {} # This cube has the two event handlers to change its color.
}
}
When user presses button, the color of cube is changed to red, then
button is released, that of cube is changed to blue.
In the following example, the first cube has TCL event handler and the second cube has PYTHON event handler to change their color.
Separator {
Separator {
EventHandler {
filename "change.tcl"
eventType GRAB
userData "red"
function "change_color"
scriptType TCL
}
Cube {} # This cube has the TCL event handler
# to change its color to red.
}
EventHandler {
filename "change.py"
eventType GRAB
userData "blue"
function "change_color"
scriptType PYTHON
}
Cube {} # This cube has PYTHON event handler to change its color to blue.
}
If a browser has a built-in function "change_color", an event handler can be specified like the following:
Separator {
EventHandler {
eventType GRAB
userData "red"
function "change_color"
scriptType C
}
Cube {} # This cube has the built-in C event handler
# to change its color to red.
}
In the following example, a cube has the same event handler for GRAB and KEY_DOWN.
Separator {
EventHandler {
filename "change.tcl"
eventType ( GRAB | KEY_DOWN )
userData "red"
function "change_color"
scriptType TCL
}
Cube {} # This cube has the event handler for two events.
}
Separator {
Script { # defines script procedure.
procedure
"proc change_color { obj event userData } {\n\
vsSetObjDiffuse $obj $userData;\n\
}"
scriptType TCL # SFEnum
}
EventHandler {
filename ""
eventType GRAB
userData "red"
function "change_color"
scriptType TCL
}
Cube {} # This cube has the handler for GRAB event.
}