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

4 of 6  

The eight shapes in the kaleidoscope move according to simple OrientationInterpolator nodes and two of the eight nodes move according to PositionInterpolator nodes as well. You should put the movement in the VRML 2 file when it repeats over and over. You should put the kaleidoscope’s behavior in the Java file instead if it lacks a highly repetitive motion. The kaleidoscope contains two separate grouping Transform nodes  (named T1 and T2) which contain eight nodes each. Transform nodes T3, T4, T5 and T6 reuse T1 and T2 to simulate a mirror reflecting the images in the kaleidoscope. ROUTE statements connect the animation start and stop control buttons to the TimeSensor (named Time_T) and interpolators needed for the animation. 

2. Add additional empty Transform nodes wherever you might like to add new objects dynamically in response to your audience’s actions. 

The Transform nodes that make up the kaleidoscope (their names start with a W) do not contain any shapes when the VRML 2 file initially loads in the Web browser, yet do contain TouchSensor nodes. Transform node W9 will contain the shape of the node the user is designing at any time. W9 also contains no shape when the world initially loads. 

3. Uniquely name the nodes you want to change dynamically with Java using the DEF keyword. 

Note that all the nodes I want to change have been given unique names in step 1 above. 

4. Extend Java’s Applet class to create your own class which will be aware of your VRML 2 file. 

After importing all the classes from the Java language and EAI vrml packages you need in order to compile your code, you extend the Applet class with your own class. For Kaleidoscope world, I created a class I name K with the line: 

public class K extends Applet implements EventOutObserver { 

5. Create an HTML document to connect your VRML 2 world from step 3 with your class in step 4. 

The HTML file, K.html (see Listing 1), connects the K.wrl file with the Java code using the HTML tags: 

<center> 
<embed src="k.wrl" border=0 height="500" 
 width="500"></center> 
<applet code="K.class" mayscript></applet> 

6. Follow the architecture of the EAI to connect your class from step 4 to the browser object of the Web browser. 

I connect to Netscape Navigator with these four lines: 

JSObject win = JSObject.getWindow(this); 
JSObject doc = (JSObject) win.getMember("document"); 
JSObject embeds = (JSObject) doc.getMember("embeds"); 
browser = (Browser) embeds.getSlot(0); 

4 of 6  

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