import com.blaxxun.x3d.*; import com.blaxxun.bx3d.blaxxun3d; /** * example1 * * implements a simple example, showing how to acces blaxxun3d nodes * * @author marc kaufmann (mk), blaxxun interactive * @version 0.1 * **/ public class example1 extends java.applet.Applet { protected Browser browser=null; protected Node sphereMaterial=null; protected Field diffuseCol=null; public example1() { } public void start(){ // connect to blaxxun3d while (browser==null) { browser=blaxxun3d.getBrowser("browser"); hesitate(); } System.out.println("Got browser."); // wait till everything is loaded while (browser.getWorld()==null) { hesitate(); } System.out.println("World loaded."); // connect to nodes try { sphereMaterial=browser.getNode("sphereMaterial"); diffuseCol=sphereMaterial.getField("diffuseColor"); } catch (X3DException notfound) { System.out.println("Can't find nodes. Aborting."); stop(); } catch (IllegalArgumentException sceneerror) { // this should not happen at all System.out.println("No scene present. Aborting."); stop(); } System.out.println("Got nodes."); // main loop float[] col=new float[3]; while (true) { // get current color values col=diffuseCol.getValueFloatArray(0,-1); // calculate new values for (int i=0;i<3;i++) col[i]=(float)Math.random(); // sync renderer browser.beginUpdate(); // send them to the sphere diffuseCol.setValueFloatArray(0,-1,col); // continue rendering browser.endUpdate(); hesitate(); } } /** * waits 300 millis */ private void hesitate() { try { Thread.sleep(300); } catch(InterruptedException ignored) {} } }