|
![]() "Extending VRML 2 with Java," Vol. 1, Issue 1, p. 42 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
Complete project code for Kaleidoscope may be found at www.sys-con.com/vrml. About the Author
Copyright 1998 by SYS-CON Publications, Inc.
|