Monday 26 June 2017

Sony's extensions to the VRML 1.0 standard(V 1.2)

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

Registering Tasks

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 URL
    
This idea came from
Mitra's paper.

object attributes

Node scope

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.
  • Event Handler Example 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.
      }
      
  • Script Sharing Example 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.
      }
      
  • Attaching two event handlers example 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.
  • Multiple scripting language support example 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.
      }
      
  • Built-in C function example 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.
      }
      
  • Multiple events example 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.
      }
      
  • Inline scripting example
      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.
      }