"Extending VRML 2 with Java," Vol. 1, Issue 1, p. 42 

6 of 6  

1. Pre-package as text strings any new VRML nodes you may want to place into the world in response to user actions. 

For Kaleidoscope world, you create eight different shapes you want to add to the kaleidoscope in different combinations. Each of these eight shapes is associated with a shape attribute which converts from a simple string using the createVrmlFromString method of the browser class. You remove unwanted nodes, for example shape[8], using lines of code like removeChildren[8].setValue(shape[8]); and add new nodes using lines of code like addChildren[8].setValue(shape[8]); 

You must make sure you remove the exact same node as exists in the VMRL 2 scene graph at any time. Otherwise, you cannot add a new node in its place. 

2. Create methods (or additional classes with methods) which use the attributes of your class from step 4 to dynamically change each attribute based on the state of the virtual machine. 

In Kaleidoscope world, much of the processing works on manipulating strings which create VRML 2 Transform and Shape nodes. All translations take place within the VRML 2 file which makes sense since the kaleidoscope’s movement is very repetitive in nature. 

Much of the power of the EAI takes advantage of moving VRML 2 objects according to complex logic embedded in Java classes. I would use Java to create kaleidoscope behaviors that were based on real world physics. In that case, my virtual machine would have to perform collision detection and move the shapes according to the logic that responds to collisions. 

Note: Kaleidoscope world was created specifically for the EAI included with Silicon Graphics’ CosmoPlayer 1.0 release of their VRML viewer. I compiled my Java code using JDK 1.0.9. In the 1.0 implementation, I perform multiple EAI changes to a node in response to a single touch event. In version 2.0 of CosmoPlayer, multiple changes to a single node within a single event handling routine are not guaranteed to be handled by the viewer in the order they appear in the Java code. So, a removeChildren.setValue() method is not guaranteed to take place before the related addChildren.setValue(). To avoid any console warnings, you could add another white control button whose event handling routine would contain the necessary remove node functionality. Then, the add node routine could exist separate from the remove node routine. 

Conclusion 
The EAI fills in the gaps between the built-in functionality of a VRML 2 viewer, model specification of VRML 2 file syntax and programmability of Java through the use of an embedded Applet on an HTML Web page. Once a VRML 2 file has been read into a Java class structure, the world model can interact with a Java Virtual Machine capable of all kinds of new, creative processing including processing on multiple machines across a network. Creating interactive worlds with the EAI is thus open-ended, yet every Java class you involve in the processing must be delivered to each user. If your user’s VRML viewer already contains the processing logic to perform an action to your virtual world, you should attempt to use the appropriate VRML 2 mechanism for enabling that action. Java through the EAI is appropriate for extending a VRML viewers capabilities perhaps only until the next VRML viewer version that contains the necessary enhancement. 

Complete project code for Kaleidoscope may be found at www.sys-con.com/vrml

About the Author 
Bruce Campbell is a virtual reality and human interface research scientist working at the Human Interface Technology Laboratory at the University of Washington in Seattle. He enjoys teaching groupware and Web-related technologies through writing books and lecturing in front of a live audience. Bruce can be reached at bdc@hitl.washington.edu 

6 of 6  

Copyright 1998 by SYS-CON Publications, Inc. 
VRMLJournal.com