Kouichi Matsuda, Yasuaki Honda matsuda@csl.sony.co.jp Sony Computer Science Laboratory Inc. also with Central Research Center, Sony Corporation
History
Thu Jun 15 15:51:16 JST 1995: The first version(V 1.0).Tue Sep 14 20:43:14 JST 1995: This document was added to WWW.csl.sony.co.jp
Tue Sep 26 12:24:59 JST 1995: Bug fix (MOUSE_DOWN -> BUTTON_DOWN) and WORLD_IN, WORLD_OUT was added.
Mon Oct 2 18:19:25 JST 1995: Add a few examples to demonstrate script sharing and multi-scripting language supporting.
Tue Oct 3 10:06:56 JST 1995: Add description on the arguments of event handler, and KEY_UP/KEY_DOWN event.
Tue Oct 3 20:13:51 JST 1995: Version 1.1. the callback interface was changed.
Wed Oct 4 11:04:07 JST 1995: A new example about attaching two event handlers to one object is added.
Wed Oct 4 14:55:28 JST 1995: "method" and INLINE script type is added.
Thu Oct 5 16:25:57 JST 1995: Version 1.2. BUTTON_DOWN -> GRAB, BUTTON_UP -> RELEASE. Move "filename" of Script node to Event Handler node.
Introduction
Following is a list of nodes that constitute our Sony's extensions to the current VRML 1.0 standard. We extended VRML 1.0 about scripting, object attributes and sound features. 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.Scripting
There are seven extension nodes for it: Script node, EventHandler node, SporadicTask node, PeriodicTask node, and CalendarTask node.Requirement
- Syntactic extensions to VRML: syntactic extensions are necessary for defining functions and registering tasks.
- Basic task support: VRML's scripting nodes should support the following basic tasks: event handler, periodic task, sporadic task and calendar task.
- Naming 3D objects and accessing methods to them from scripts
- Libraries for manipulating 3D objects
- Multiple scripting language support: there are many script languages in the world: e.g. tcl, python and java. VRML's scripting nodes should be language independent.
- Inline scripting is necessary.
Syntactic Extension
Five node types are necessary for the scripting extension to VRML: Script node, EventHandler node, SporadicTask node, PeriodicTask node and CalendarTask node. The first one is for defining functions; others are for registering them to objects.Defining Functions
- Script node
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...
Registering Tasks
- EventHandler node
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
nodes.
- SporadicTask node
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);
- PeriodicTask node
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);
- CalendarTask node
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);
Method
A tiny language can be embedded in the "function" field of EventHandler node, SporadicTask node, PeriodicTask node, and CalendarTask node directly to describe some simple methods. The methods also are invoked by events or messages according to the node type. 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.
object attributes
- Attributes node
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".
Node scope
When Separator of VRML 1.1 proposal is accepted, we will use VRML 1.1 scoping rule.AmbientSound Node
This property node defines an ambient sound source. If user enters the bounding cube of it, it plays sound automatically and adjust its volume according to a distance between the node and user.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 }
Scripting example
In the following examples, we suppose that content of "change.tcl" likes this: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.
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. }
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. }
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.
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. }
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. }
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. }