VRML Scripting

Gavin Bell, <gavin@sgi.com>, Silicon Graphics
Mitra <mitra@mitra.biz>, WorldMaker
Chee Yu, Silicon Graphics
Chris Marrin, Silicon Graphics
Yasuaki Honda <honda@csl.sony.co.jp>, Sony Computer Science Laboratory
Kouichi Matsuda <matsuda@csl.sony.co.jp>, Sony Computer Science Laboratory

This document can be found at http://reality.sgi.com/employees/gavin/vrml/Scripts.html. It was last updated on Dec. 11, 1995.


Script nodes

Behavior files are referenced through a new Script node:

    Script { 
        behavior  ""  # MFString field
        scriptType "" # SFString field
        optimization  # SFBitMask field:
                        (UNKNOWNOUTPUTS | ALWAYSEVAL
Mitra/Sony:             | CULLEVENTS | LODEVENTS | WORLDINOUT )

        # And any number of:
        eventIn eventTypeName eventName
        field fieldTypeName fieldName initialValue
        eventOut eventTypeName eventName
    }

For example:

    Script { 
        behavior  "http://foo.com/bar.class"  ; MFSTRING
        scriptType "JAVA" ; SFSTRING
        eventIn SFString name   
        eventIn PICK selected
        eventOut SFString lookto
        field SFLong currentState 0
        optimization  ALWAYSEVAL
    }

A Script node instance may consist of:

Gavin: Defines a VisibilitySensor that takes the place of the CULL/LOD events functionality; script init/destroy calls and ProximitySensors that enclose the entire world take the place of WORLD events.

Sony/Mitra: Script nodes can only appear as children of Frames, and have an implicit object which they are attached to. They should be thought of as implementing the behavior of the real-world object.

SGI/Gavin: Script nodes can appear anywhere a node can appear in the VRML file, but Script nodes are conceptually NOT part of the scene parent/child hierarchy. Instead, Script nodes should be thought of as nodes that live "to the side" of the scene graph structure, orchestrating the flow of events from Sensors, which are part of the scene's structure and which DO have a particular place in the virtual world, or from the real world (if the Script node is a source of real-world events), into changes to the virtual world. Scripts may be combined with geometry using the prototyping mechanism to create real-world-like objects that encapsulate behavior.

Script Capabilities

A Script node is "executed" after it has received one or more events. When it executes, it may process the events received, update its internal and/or persistent state, generate output events, and make API calls to find out information about or change the virtual world.

A Script node may also run asynchronously, in which case it may spontaneously generate events.

The Script API document describes in detail the types of operations a Script node may perform.

Culling Rules

To deal with concerns about optimisation, some rules must be laid down about when a browser can, and when it cannot, optimise away, or cull, a behavior (or a node).

  1. If a script has an output that is visible, it must be evaluated when it receives events.
  2. If a script has the UNKNOWNOUPUTS flag set, meaning that it might effect other things in the scene graph, then it must be assumed to be connected to a visible object, so rule 1 applies.
  3. If a script has the ALWAYSEVAL flag set, then it must be evaluated whenever it receives events. (this might be equivalent to UNKNOWNOUTPUTS, but I'm not sure it will be for all systems).
  4. If a script would be evaluated, then any Node that it depends on will need evaluating.