Given by Balaji Natarajan(Geoffrey C. Fox) at CPS616 -- Information Track of CPS on Spring Semester 97. Foils prepared April 15 1997
Outside Index
Summary of Material
See VRML Resources including many interesting examples |
Basic Concepts of Scripting in VRML2 |
Java JavaScript VRMLScript as Scripting Languages |
VRML Database Connectivity |
Outside Index Summary of Material
Scripting in VRML 2.0 |
and Other Recent Developments |
Presented: Geoffrey Fox |
NPAC |
Syracuse University |
111 College Place |
Syracuse NY 13244-4100 |
Script Nodes essentially give logic and state management to a VRML world. |
Key feature of the execution model is that time advances in a VRML 2.0 scene in virtual units |
Each time unit in the scene has an associated time value , called a timestamp. |
Start of an Event Cascade signifies creation of a timestamp and attaching it to an event. |
Scripting languages supported currently by VRML 2.0 are Java, JavaScript and VrmlScript. |
User-defined fields in Script Nodes provide the link between the state in VRML scene and state in the Java/JavaScript/VrmlScript program. |
Events arriving at an eventIn field automatically cause the browser to pass the event to the program referred to in the url field of the Script node. This mechanism is called Event Dispatching. |
Java nodes make use of VRML 2.0 Java API attached to VRML 2.0 specifications. |
Typical fields in a Java script node are : |
eventIn - for getting the actual event in the VRML world |
eventOut - for sending results generated by Java Class |
url - this field specifies the location of the Java class |
field - this defines fixed parameters |
The blending of Java and VRML enables true multimedia ,experiential and dynamic content on the Web. |
Both Java and VRML are cross - platform standards. |
The powerful networking classes of Java can be optimally used with VRML to provide for Collaborative virtual environments. |
VRML with Java is a powerful combination that results in executable content, optimized for today's low bandwidth environments. |
Simple 3-D programming of complex front-ends possible using well-defined nodes in VRML 2.0 specifications. |
Substantial bandwidth savings possible by using a VRML world animated by a Java applet - rather than a 2D GIF/JPEG image animated by Java.
|
In VRML 2.0, Script nodes allows to fashion nodes that are described by Java classes using the VRML 2.0 Java API. |
The whole VRML browser can be written in Java - having a set of Java classes that implement the VRML specifications - as in DimensionX's Liquid Reality browser. |
Using Netscape's LiveConnect architecture,a VRML world can be controlled by a Java applet. |
Sony's Community Place |
SGI's CosmoPlayer |
DimensionX's Liquid Reality |
IICM's VRWave |
OzVirtual Browser |
This class will extend the Script class defined in the vrml package - a part of the VRML 2.0 Java API. |
Contains an initialize method for getting eventOuts and exposedFields from the VRML file. |
Contains a processEvent method for getting details about the event and processing it. |
Contains a shutdown method - this method is automatically called when Script node is deleted. |
Description of the Example world : |
This is a simple VRML world to illustrate the idea of scripting using Java.This world consists of a sphere object with a touchSensor associated with it. On clicking the sphere,through Scripting, the color of the sphere is changed. |
#VRML V2.0 utf8 |
Transform { |
children [ DEF TS TouchSensor {} |
Shape { appearance Appearance { |
material DEF SphereColor material {diffuseColor100} |
} # End Appearance |
geometry Sphere {} |
} ] } |
DEF ColorScript Script { |
url "ChangeColor.class" |
eventIn SFBool clicked |
eventOut SFColor newColor |
field SFBool on FALSE } |
ROUTE TS.isActive TO ColorScript.clicked |
ROUTE ColorScript.newColor TO SphereColor.set_diffuseColor |
Public class Changecolor extends Script { |
private SFColor newColor ; |
float red[] = {1,0,0}; |
public void initialize() { |
newColor = (SFColor) |
getEventOut ("newColor"); |
} |
Public void processEvent(Event e) { |
ConstSFBool v = (ConstSFBool)e.getValue(); |
if(v.getValue()) { |
if(on.getValue()) { |
newColor.setValue(red); |
} else { newColor.setValue(blue); |
} |
on.setValue(!on.getValue()); } } } |
changecolor.wrl(requires Community Place Plug-in on PC) |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/java/changecolor.wrl |
Dynamic Generation of VRML 2.0 nodes at Runtime. |
Dynamic Generation of VRML 2.0 routes at Runtime. |
Behavioral worlds coupled with DirectSound effects to achieve realism. |
Collaborative Virtual Environments like Virtual Theaters,Shopping Malls. |
Description of the world : |
This world initially consists of a sphere object with a touchSensor associated with it. On clicking the Sphere, an entire new node is generated at runtime and is displayed near the existing Sphere.Now the new Sphere can be clicked upon to generate another node. |
#VRML V2.0 utf8 |
DEF GEN_ROOT Transform{ |
children [ DEF GEN_TOUCH TouchSensor {} |
Shape {geometrySphere{} } ] } |
DEF GEN_SCRIPT Script { |
url "DynamicGen.class" |
eventIn SFTime touched |
eventOut MFNode addSphere } |
ROUTE GEN_TOUCH.touchTime TO |
GEN_SCRIPT.touched |
ROUTE GEN_SCRIPT.addSphere TO |
GEN_ROOT.addChildren |
Public class DynamicGenerator extends Script { |
MFNode addSphere ; |
Random randomNumGenerator = new Random(); |
float posX = 0.0f; |
public void initialize() { |
addSphere = (MFNode)getEventOut("addSphere"); } |
public void processEvent(Event e) { |
String sphereDesc1 = "Transform { translation 0.0 0.0 0..0 "; |
String sphereDesc2 = "children[ Shape geometry Sphere{}"; |
String sphereDesc3 = "appearance Appearance { material Material "; |
String sphereDesc4 = "diffuseColor 1.0 0.0 0.0 } } } ] } "; |
Float red = randomNumGenerator.nextFloat(); |
float green = randomNumGenerator.nextFloat(); |
float blue = randomNumGenerator.nextFloat(); |
Browser browser = getBrowser(); |
BaseNode baseNodes[]; |
posX += 3.0f ; // X coordinate of new node. |
try { |
baseNodes[0] = browser.createVrmlFromString(sphereDesc1+ |
sphereDesc2+sphereDesc3+sphereDesc4); |
addSphere.setValue(baseNodes[0]); |
} |
catch(Exception ex) { ex.printStackTrace() ; |
} } } } |
DynamicGen.wrl(requires Community Place Plug-in on PC) |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/java/DynamicGen.wrl |
Description of the world : |
This world consists of a cone object and a sphere object.The Cone functions as an ON/OFF switch for route creation.When the cone is clicked initially,it means the world is ready for a route to be created - then click on the sphere - a route is dynamically created between the touchSensor and the lighting node. |
#VRML V2.0 utf8 |
Transform { children [ |
DEF RouteSwitch TouchSensor {} |
Shape {geometryCone{} } ] } |
Transform { translation 3 0 0 children [ |
DEF LightSwitch TouchSensor {} |
Shape {geometrySphere{} } |
] } |
DEF DL DirectionalLight {onFALSE} |
NavigationInfo {headlightFALSE} |
DEF SC Script { |
url "AddRoute.class" |
field SFNode lightswitch USE LightSwitch |
field SFNode dl USE DL |
eventIn SFTime touched } |
ROUTE RouteSwitch.touchTime TO SC.touched |
Public class AddRoute extends Script { |
private boolean routed = false; |
Browser b; |
Node lightswitch,dl; |
public void initialize() { |
b = getBrowser(); |
dl = (Node)((SFNode)getField("dl")).getValue(); |
lightswitch = (Node)((SFNode)getField("lightswitch")). |
getValue(); } |
Public void processEvent(Event e) { |
if(routed) {b.deleteRoute(lightswitch,"isActive",dl,"on");} |
else {b.addRoute(lightswitch,"isActive",dl,"on");} |
routed = !routed; } } |
addRoute.wrl(requires Community Place Plug-in on PC) |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/java/addRoute.wrl |
Description of the world: |
This world consists of a virtual Honey bee hive. As the Beehive is approached closer, the bees jump out of the hive with buzzing noises. Full use of sound spatialization is made by making the buzzing sound node reside in the same hierarchial level as the node which constructs the bee. |
#VRML2.0 utf8 |
PROTO BEEBEE[ |
eventIn SFVec3f positionChanged |
eventIn SFRotation orientationChanged |
eventIn SFBool isActive |
eventIn SFTime BeeTimeSensorCycleTime |
] |
Transform { |
children [ |
DEF BeeTransform Transform { |
children[ DEF BeeSound Sound { |
source AudioClip {url "sounds/beebee.wav" |
loop TRUE } |
maxFront 17.3205 |
maxBack 17.3205 |
} Inline {url"models/bee.wrl"} ] } |
DEF MainScript Script { |
url "scripts/Beebee.class" |
eventIn SFVec3f PositionChanged IS positionChanged |
eventIn SFRotation OrientationChanged IS orientationChanged |
eventIn SFBool HoneycomTouchSensorIsActive IS isActive |
eventIn SFTime BeeTimeSensorCycleTime IS |
BeeTimeSensorCycleTime |
eventOut SFVec3f BeeTranslation |
eventOut SFRotation BeeRotation } ] |
ROUTE MainScript.BeeTranslation TO BeeTransform.set_translation |
ROUTE MainScript.BeeRotation TO BeeTransform.set_rotation |
} |
} |
DEF BeeTimeSensor TimeSensor { |
loop TRUE |
enabled TRUE |
stopTime -1 |
cycleInterval 0.1 } |
DEF HoneyCom Transform { |
children [ DEF HoneycomProximitySensor |
ProximitySensor size 100 100 100 } |
DEF HoneycomTouchSensor TouchSensor{} |
Transform { translation 0 -1 0 |
children [ Shape { appearance Appearance{ |
texture ImageTexture " honeycom.jpg" |
} } geometry Sphere{radius3} } ] }] } |
DEF Beebee1 BEEBEE {} |
ROUTE HoneycomProximitySensor.position_changed TO |
Beebee1.positionChanged |
ROUTE HoneycomProximitySensor.orientation_changed TO |
Beebee1.orientationChanged |
ROUTE HoneycomTouchSensor.isActive TO Beebee1.isActive |
ROUTE BeeTimeSensor.cycleTime TO |
Beebee1.BeeTimeSensorCycleTime |
beebee.wrl(requires Community Place Plug-in on PC) |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/java/beebee/main.wrl |
Made possible using Java's powerful networking classes |
Users represented as Avatars in shared spaces. |
Concept of Shared Behaviors has to be implemented to achieve realism in these environments. |
The visual element of a shared environment also provides a vehicle for enhancing the tools available in a workplace , such as scientific data visualization and process simulation |
For example , a team of engineers who design an aerospace engine by testing different parts online from different locations can benefit from a display of results that show cause and effect relationships in a multi-user space. |
Theater.wrl(requires Community Place Plug-in on PC) |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/Multi-User/theater/main.wrl |
JavaScript allows for opening a document in a Web page using the plug-in type and to send commands directly to the plug-in/browser. |
JavaScript allows for opening of a VRML 2.0 file in a different frame on the same Web page of which the other frame will contain the control information written in JavaScript |
Similar scripting procedures like Java though collaborative applications are fairly difficult. |
Creation of User-defined VRML 2.0 interpolator nodes. |
Creation of Boolean Event-Filters enabling creation of virtual Radio-Buttons. |
Parameter passing to VRML objects directly from |
Web pages. |
Description of the world: |
Animation of a red sphere - located relatively higher than a white board - is done using javascript. The sphere will continue to move for 4 virtual time units(as set in the world file) and then return to its origin and then start to move again.... |
#VRML V2.0 utf8 |
Group { children [ |
Background [ # Node for background representation |
. . . . . . . . . . . . . ] |
Shape { # Node for floor representation |
. . . . . . . . . . . . . .] |
Transform { # Node for red ball representation |
. . . . . . . . . . . . . .} |
DEF Clock AnimationSensor {....} # Animation Clock |
DEF Mover Script { |
url "move1.js " |
eventIn SFFloat set_fraction |
eventOut SFVec3f value_changed |
} ] } |
ROUTE Clock.fraction_changed TO Mover.set_fraction |
ROUTE Mover.value_changed TO BallTransform. |
set_translation |
// Function to move a shape in a straight path |
function set_fraction(fraction, eventTime ) |
{ |
value_changed[0] = fraction; // X component |
value_changed[1] = 0.0; // Y component |
value_changed[2] = 0.0; // Z component |
} |
moveball.wrl |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/js/moveball.wrl |
Description of the world: |
Custom shapes like cube,sphere,box are converted into radio-buttons by providing them with typical functionalities like background color changing. These functionalities can be extensively extended to create a complete virtual 3-D Graphical User Interface(GUI). |
#VRML V2.0 utf8 |
Group { children [ |
# Bindable Backgrounds (cyan,red,blue) |
DEF Back1 Background {........} |
DEF Back2 Background {........} |
DEF Back3 Background {........} |
# Shapes to act as Radio - Buttons to control Backgrounds |
Transform {children[......geometryBox{} |
DEF BackButton1 TouchSensor{} ] } |
Transform {children[......geometrySphere{} |
DEF BackButton2 TouchSensor {} ] } |
Transform {children[......geometryCone{} |
DEF BackButton3 TouchSensor {} ] } |
# The inline JavaScript source |
DEF Filter1 Script { #code for I filter |
url "javascript: |
function set_boolean(bool,eventTime) { |
if(bool = = true) {true_changed=true;} |
else {false_changed=true;} |
eventIn SFBool set_boolean |
eventIn SFBool true_changed |
eventIn SFBool false_changed } |
DEF Filter2 Script { #code for II filter |
url "javascript: |
function set_boolean(bool,eventTime) { |
if(bool = = true) {true_changed=true;} |
else {false_changed=true;} |
eventIn SFBool set_boolean |
eventIn SFBool true_changed |
eventIn SFBool false_changed } |
DEF Filter3 Script { #code for III filter |
url "javascript: |
function set_boolean(bool,eventTime) { |
if(bool = = true) {true_changed=true;} |
else {false_changed=true;} |
eventIn SFBool set_boolean |
eventIn SFBool true_changed |
eventIn SFBool false_changed } |
Route BackButton1.isActive TO Filter1.set_boolean |
Route BackButton2.isActive TO Filter2.set_boolean |
Route BackButton3.isActive TO Filter3.set_boolean |
Route Filter1.true_changed TO Back1.set_bind |
Route Filter2.true_changed TO Back2.set_bind |
Route Filter3.true_changed TO Back3.set_bind |
radiobuttons.wrl |
http://king.syr.edu:2006/src/public_htmL/InteractiveDemos/js/radiobuttons.wrl |
cylinder.wrl |
http://www.npac.syr.edu/users/zeynep/VRML2.0_EXAMPLES/hasan/Cylinder/main..html |
VrmlScript is a subset of the JavaScript language with VRML data types supported as JavaScript built-in objects. |
Scripts can be included in source form, inline rather than in a separate URL. |
Receiving eventIns is handled with separate functions to ease development and to speed up processing. |
The url field of the Script Node may contain a URL that references the VrmlScript code |
Script {url"http://foo.com/myScript.vs"} |
The script can also be placed inline as |
Script {url"vrmlscript:functionfoo(){...} " } |
The url field may contain multiple URL's and thus reference a remote line or in-line code. |
Description of the world : |
There are two box objects present in the scene. Clicking on the blue box object animates the red box object for a fixed time period. The animation is controlled by an inline vrmlscript source within the world file. |
#VRML V2.0 utf8 |
Transform { children [ |
DEF TIME1 TimeSensor {cycleInterval10} |
DEF INTERP1 PositionInterpolator { |
key [ 0.0 0.5 1.0 ] |
keyValue [ .15 .15 0 .15 -.15 0 .15 .15 0 ] |
} DEF T1 Transform {.....geometryBox{..} } |
// Node definition for box to be animated. |
Transform {children[DEFGOTouchSensor{} |
Shape {...geometryBox{..} ] } |
// Node definition of animating box |
// The inline VrmlScript source |
DEF JUMPY Script { |
eventIn SFFloat smooth_in |
eventOut SFFloat jumpy_out |
url "vrmlscript: |
Function smooth_in(t) |
{ step = (t*10) % 5; |
jumpy_out = step/10.0; } " |
DEF SCRIPT Script { |
eventIn SFTime clicked |
eventOut SFTime start1 |
url "vrmlscript : function clicked(time) |
{start1=time;} " |
ROUTE TIME1.fraction_changed TO |
JUMPY.smooth_in |
ROUTE JUMPY.jumpy_out TO |
INTERP1.set_fraction |
ROUTE INTERP1.value_changed TO |
T1.translation |
ROUTE GO.touchTime TO SCRIPT.clicked |
ROUTE SCRIPT.start1 TO TIME1.startTime |
jumper.wrl |
http://king.syr.edu:2006/src/public_html/InteractiveDemos/vs/jumper.wrl |
VRML worlds are accessible through Java using a plug-in API that employs Netscape's LiveConnect Architecture. |
Java applets loaded on a HTML page can trigger events in a VRML world loaded in a different frame in the same page. |
VRML 2.0 Browser currently employing the LiveConnect architecture is Live3D browser on the PC's. |
EAI is one other way in which Java can interact with VRML. |
From a Java programmer's point of view, EAI is a set of classes with methods that can be called to control the VRML world. |
From a VRML world creator's point of view, the EAI is just another mechanism that can send and receive events. |
Processes happening when a Java applet changes the color of a Sphere node in a VRML world : |
The applet makes a call to find the sphere by asking for it by name. |
Next, the applet will make a call to change the color of that field. |
When the applet finds the color field and changes the color of that field, the VRML world receives and event - processes it and finally changes color. |
Compressed Binary Format for VRML 2.0 file to be introduced. |
Database Connectivity for VRML files to be established in the near future. |
Currently in the development stage |
Results in reduced file size - Clever Compression routines can result in the reduction of a VRML file size by 40 percent. |
Reduced Load Time - A binary file format is better suited for efficient parsing because it contains the minimum data needed by the browser to build scenes. |
Increased degree of security . |
VRML Database API is now currently in the development stage. |
The objective in developing this API is to define a standard for Data Repositories - a generic mechanism for storing and accessing VRML data that supports modifying existing world content , distributing world information and managing world access. |
The VRML Database API would essentially address the following issues : |
Persistence : While VRML 2.0 describes worlds that change over time and respond to user actions, the world always begins at a fixed unchanging state. Any changes a user makes to objects in the world are reset the next time the world is entered. The API would support locks , contention management, retrieval of a scene graph |
Scalability : The API would support optimized, streamed delivery of custom VRML content based on user criteria defined via spatial and logical partitioning. |
Security : The API would support user privileges, authorization and object ownership inside the virtual world. |