RealVR Traveler Scripting

Making Use of Built-in Scripts

September 15, 1996
ゥ Copyright 1996, RealSpace, Inc. All rights reserved.

Table of Contents

1. Introduction
2. Link Script
3. Slide Script
4. Set Value Script
5. Set Cursor Script
6. Set Camera Script
7. Get Time Script
8. An Example File (Setting the view direction)

1. Introduction

To create interesting, interactive VRML worlds, live objects are useful for immersing the user into the environment. The RealVR Traveler provides several built-in scripts that can be used by anyone creating VRML worlds. By combining these basic scripts, some complex behaviors can be described.

Each of the script types described here is shown in the form that it would appear in a VRML file. You can just copy a script, paste it into your file, and modify the values that describe its behavior. In addition, be sure to "ROUTE" events to the eventIn's of the scripts you use, in order to activate their behavior.

2. Link Script

The Link script is most commonly used for creating connections that allow the user to move from one Vista to another, or to create URL hot spots inside a Vista. However, feel free to experiment with other uses of the Link script.

The Link script type is fully described in the Image Worlds file specification.

3. Slide Script

The Slide script is a specialized script that can be used to move an object in space. The Slide script must refer to some Transform node in the scene (using the transform field) - in the example below, it refers to a Transform named "SomeTransform". When the script is activated, it will alter that transform node, moving it in the direction indicated by the translation field (note that this is a 3D direction). The motion will last as many seconds as specified in the duration field. The state field indicates which end of the motion path the object will start on - "FALSE" indicates the beginning, while "TRUE" indicates the end.

To activate this script, one of three events may be used, depending on the desired effect. The toggle event will move the object back and forth along the motion path each time it is received. The on event will move the object to the end of the motion path (the "TRUE" state). Finally, the off event will move the object to the beginning of the path (the "FALSE" state).

The Slide script appears as below in a VRML file:

Script {
    exposedField MFString url        "rst:slide"

    # events specific to the "slide" type Script:
    eventIn       SFBool   toggle
    eventIn       SFBool   on
    eventIn       SFBool   off

    # fields specific to the "slide" type Script:
    field         SFBool  state        "FALSE"
    field         SFNode  transform    USE SomeTransform
    exposedField  SFVec3f translation  0.25 0.5 7
    exposedField  SFTime  duration     3
}

4. Set Value Script

The Set Value script is very simple - it has a single eventIn (on) and a single field (val). It's main purpose is to convert SFBool events into other types of events. When the on event is received, a val_changed event is generated that may be routed to anywhere else in the scene. The type of the val field can be anything - that way, an SFBool event can be converted into any other type of event.

The Set Value script appears as below in a VRML file:

Script {
    exposedField MFString url        "rst:setVal"

    # events specific to the "setVal" type Script:
    eventIn       SFBool   on

    # fields specific to the "setVal" type Script:
    exposedField  SFInt32  val  1234
}

5. Set Cursor Script

The Set Cursor script is used to set the cursor to one of the predefined types in the RealVR Traveler. When this script receives a "TRUE" value in the on eventIn, it changes the mouse cursor to the type specified in the cursor field. The currently supported cursors are "ARROW", "LINK", and "PAN".

The Set Cursor script appears as below in a VRML file:

Script {
    exposedField MFString url        "rst:setCursor"

    # events specific to the "setCursor" type Script:
    eventIn       SFBool   on

    # fields specific to the "setCursor" type Script:
    exposedField  SFString cursor  "ARROW"
}

6. Set Camera Script

The Set Camera script is used to set the camera parameters for viewing the world. It should be used carefully, because it can take away a certain amount of control from the user. Any of three eventIn's can be used with this script. The orientation eventIn sets the viewing angles (pitch, yaw, and roll). The position eventIn sets the viewer's location in 3D. Finally, the zoom eventIn sets the zoom angle. The relative field is used to control absolute vs. relative camera control. If its value is "TRUE", then camera modifications are relative to the user's current view direction. If its value is "FALSE", then this script will set the camera to exactly the values received in the eventIn.
Note that all angles are in radians.

The Set Camera script appears as below in a VRML file:

Script {
    exposedField MFString url        "rst:setCamera"

    # events specific to the "setCamera" type Script:
    eventIn       SFVec3f  orientation
    eventIn       SFVec3f  position
    eventIn       SFFloat  zoom

    # fields specific to the "setCamera" type Script:
    exposedField  SFBool   relative  "TRUE"
}

7. Get Time Script

The Get Time script allows a VRML file to access the current time (how long the player has been running). When this script receives a requestTime eventIn, it generates a currentTime eventOut that contains the current time. This script is useful for resetting movies or TimeSensors to start playing "now".

The Get Time script appears as below in a VRML file:

Script {
    exposedField MFString url        "rst:getTime"

    # events specific to the "getTime" type Script:
    eventIn       SFBool   requestTime
    eventOut      SFTime   currentTime
}

8. An Example File (Setting the view direction)

The built-in scripts described above all implement pretty simple and useful behaviors. Combined, however, they can be used to create more complex results. An example file is described here to show the use of a couple of these scripts.

The RealVR Traveler defaults to pointing the user at the center of the first Vista node. Many authors, however, want to control the initial viewing direction to be something different. This can be accomplished with a couple of built-in scripts.

First, the file is shown below:


#VRML V2.0 utf8

DEF StartupTrigger TimeSensor {
    startTime 0
    stopTime 100
    loop TRUE
    ROUTE StartupTrigger.isActive TO StartView.on
}

Vista {
    type "CYLINDER"
    filename "greatwal.jpg"
    vFov -0.7418 0.7418
    pitchRange -0.7418 0.7418
}

DEF StartView Script {
    url "rst:setVal"

    eventIn SFBool on
    exposedField SFVec3f val 0 1.57 0
    ROUTE StartView.val_changed TO View.orientation
}

DEF View Script {
    url "rst:setCamera"

    eventIn SFVec3f orientation
    field SFBool relative FALSE
}

Notice that there are 4 nodes in this scene. The Vista node, of course, is used to draw a panoramic background image. The TimeSensor node named StartupTrigger is placed before the Vista, and given a start time of 0. This guarantees that it will start running before the Vista gets drawn for the first time.

The isActive event from the StartupTrigger is generated as soon as the timer starts running. We want this event to set the camera to point in some pre-defined direction. However, the isActive event is a SFBool type. So, it is routed to a Script named StartView. This script is a Set Value script, which lets us convert an SFBool into some other value. In this case, it is converted into an SFVec3f value that, in turn, is routed to the script named View. That script is a Set Camera script, which interprets the x, y, and z values of the SFVec3f as pitch, yaw, and roll, and sets the camera appropriately.

All of this happens before the Vista is ever drawn, and the end result is that the default view is no longer the midpoint of the panorama, but the viewing direction defined in the val field of the StartView Script node.

To try out this file, click here.