//testtraverse.java import vrml.external.Browser; import vrml.external.Node; import vrml.external.exception.*; import vrml.external.field.*; import java.applet.*; import java.awt.*; import java.util.*; import netscape.javascript.JSObject; public class TestExternal4 extends Applet{ TextArea output = null; Browser browser; Node protogroupnode; Node [] childprotos; public void init(){ } public void start(){ output = new TextArea(10, 40); add(output); // // make connection to Cosmo Player // JSObject win = JSObject.getWindow(this); JSObject doc = (JSObject) win.getMember("document"); JSObject embeds = (JSObject) doc.getMember("embeds"); browser = (Browser) embeds.getSlot(0); // // Get handle to root of the scene graph // try { protogroupnode = browser.getNode("PROTOGROUPNODE"); } catch (InvalidNodeException e) { output.appendText("error: get protogroupnode\n"); } output.appendText("Root node type: " + protogroupnode.getType()+"\n"); // get all child objects of protogroupnode try{ childprotos=((EventOutMFNode) (protogroupnode.getEventOut("children_changed"))).getValue(); } catch (InvalidEventOutException e) { output.appendText("protogroupnode eventout get failed, invalid eventout\n"); } output.appendText("got child nodes \n"); // cycle through proto child nodes int i; Node tempnode=null; for (i=0; i< childprotos.length;i++) { tempnode=childprotos[i]; output.appendText("childproto at index " + i + " get ok \n"); float[] tempvals=new float[3]; float[] tempvals2=new float[3]; { try{ tempvals=((EventOutSFVec3f) (tempnode.getEventOut("translation_changed"))).getValue(); } catch (InvalidEventOutException e){output.appendText("childproto at index " + i + " eventout get failed, invalid eventout\n");} output.appendText("childproto at index "+i+" at initpos: "+tempvals[0]+", "+tempvals[1]+", "+tempvals[2]+"\n" ); tempvals2[0]=tempvals[0]+1.0f; tempvals2[1]=tempvals[1]+1.0f; tempvals2[2]=tempvals[2]+1.0f; // get EventIn of current proto EventInSFVec3f eventtoproto=(EventInSFVec3f) childprotos[i].getEventIn("set_translation"); // send value to EventIn of current proto eventtoproto.setValue(tempvals2); output.appendText("childproto at index " + i + " updated at pos "+tempvals2[0]+", "+tempvals2[1]+", "+tempvals2[2]+"\n" ); } // end this section } } //start } //class