List of usage examples for javax.media.j3d TransformGroup addChild
public void addChild(Node child)
From source file:FarbWurfelAsQuads.java
/** * Erstellt den Szenegraphen/*from w w w. jav a2 s . co m*/ * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); drehung.setScale(0.5d); TransformGroup objDreh = new TransformGroup(drehung); Shape3D shape = new Shape3D(makeCube(), makeAppearance()); objDreh.addChild(shape); objWurzel.addChild(objDreh); return objWurzel; }
From source file:Viewer3D.java
public void init() { if (filename == null) { // the path to the file for an applet try {/*from w ww .jav a2s . c o m*/ java.net.URL path = getCodeBase(); filename = new java.net.URL(path.toString() + "./ballcone.lws"); } catch (java.net.MalformedURLException ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); System.exit(1); } } // Construct the Lw3d loader and load the file Loader lw3dLoader = new Lw3dLoader(Loader.LOAD_ALL); Scene loaderScene = null; try { loaderScene = lw3dLoader.load(filename); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Construct the applet canvas setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a basic universe setup and the root of our scene u = new SimpleUniverse(c); BranchGroup sceneRoot = new BranchGroup(); // Change the back clip distance; the default is small for // some lw3d worlds View theView = u.getViewer().getView(); theView.setBackClipDistance(50000f); // Now add the scene graph defined in the lw3d file if (loaderScene.getSceneGroup() != null) { // Instead of using the default view location (which may be // completely bogus for the particular file you're loading), // let's use the initial view from the file. We can get // this by getting the view groups from the scene (there's // only one for Lightwave 3D), then using the inverse of the // transform on that view as the transform for the entire scene. // First, get the view groups (shouldn't be null unless there // was something wrong in the load TransformGroup viewGroups[] = loaderScene.getViewGroups(); // Get the Transform3D from the view and invert it Transform3D t = new Transform3D(); viewGroups[0].getTransform(t); Matrix4d m = new Matrix4d(); t.get(m); m.invert(); t.set(m); // Now we've got the transform we want. Create an // appropriate TransformGroup and parent the scene to it. // Then insert the new group into the main BranchGroup. TransformGroup sceneTransform = new TransformGroup(t); sceneTransform.addChild(loaderScene.getSceneGroup()); sceneRoot.addChild(sceneTransform); } // Make the scene graph live by inserting the root into the universe u.addBranchGraph(sceneRoot); }
From source file:SimpleBehaviorApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objRotate = new TransformGroup(); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objRotate);//from www .j a v a 2s . co m objRotate.addChild(new ColorCube(0.4)); SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate); myRotationBehavior.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myRotationBehavior); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleIndexedQuadSmooth.java
/** * This builds the content branch of our scene graph. It uses the buildShape * function to create the actual shape, adding to to the transform group so * that the shape is slightly tilted to reveal its 3D shape. It also uses * the addLights function to add some lights to the scene. * //from w w w.j a va2 s.c o m * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch(Node shape) { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); rotationGroup.addChild(shape); addLights(contentBranch); return contentBranch; }
From source file:MaterialApp.java
public MaterialApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); TransformGroup trans11 = createTG(-0.7f, 0.7f, -0.5f); scene.addChild(trans11);/*from w w w. j a v a 2 s . c o m*/ trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 0.0f))); TransformGroup trans12 = createTG(0.0f, 0.7f, -0.5f); scene.addChild(trans12); trans12.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1.0f))); TransformGroup trans13 = createTG(0.7f, 0.7f, -0.5f); scene.addChild(trans13); trans13.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 2.0f))); TransformGroup trans21 = createTG(-0.7f, 0.0f, -0.5f); scene.addChild(trans21); trans21.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 5.0f))); TransformGroup trans22 = createTG(0.0f, 0.0f, -0.5f); scene.addChild(trans22); trans22.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 10.0f))); TransformGroup trans23 = createTG(0.7f, 0.0f, -0.5f); scene.addChild(trans23); trans23.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 20.0f))); TransformGroup trans31 = createTG(-0.7f, -0.7f, -0.5f); scene.addChild(trans31); trans31.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 50.0f))); TransformGroup trans32 = createTG(0.0f, -0.7f, -0.5f); scene.addChild(trans32); trans32.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 100.0f))); TransformGroup trans33 = createTG(0.7f, -0.7f, -0.5f); scene.addChild(trans33); trans33.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); scene.addChild(lightD1); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); scene.addChild(background); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); // setLocalEyeViewing u.getViewer().getView().setLocalEyeLightingEnable(true); u.addBranchGraph(scene); }
From source file:SimpleWorld.java
/** * This builds the content branch of our scene graph. It uses the buildCube * function to create the actual shape, adding to to the transform group so * that the shape is slightly tilted to reveal its 3D shape. * //from ww w . j a v a2s . com * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch(Node shape) { //Create the branch group that will be the root of the content branch BranchGroup contentBranch = new BranchGroup(); //Create the transform that will cause the shape to appear tilted Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); //Put the branch together contentBranch.addChild(rotationGroup); rotationGroup.addChild(shape); return contentBranch; }
From source file:ConeYoyoApp.java
public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objSpin);// w w w .ja va 2s . c o m objSpin.addChild(new ConeYoyo().getBG()); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, 4000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:LocalEyeApp.java
public LocalEyeApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); TransformGroup trans11 = createTG(-0.7f, 0.7f, -0.5f); scene.addChild(trans11);//ww w .jav a 2 s.c o m trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans12 = createTG(0.0f, 0.7f, -0.5f); scene.addChild(trans12); trans12.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans13 = createTG(0.7f, 0.7f, -0.5f); scene.addChild(trans13); trans13.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans21 = createTG(-0.7f, 0.0f, -0.5f); scene.addChild(trans21); trans21.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans22 = createTG(0.0f, 0.0f, -0.5f); scene.addChild(trans22); trans22.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans23 = createTG(0.7f, 0.0f, -0.5f); scene.addChild(trans23); trans23.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans31 = createTG(-0.7f, -0.7f, -0.5f); scene.addChild(trans31); trans31.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans32 = createTG(0.0f, -0.7f, -0.5f); scene.addChild(trans32); trans32.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); TransformGroup trans33 = createTG(0.7f, -0.7f, -0.5f); scene.addChild(trans33); trans33.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f))); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); lightD1.setColor(red); scene.addChild(lightD1); PointLight lightP1 = new PointLight(); lightP1.setInfluencingBounds(new BoundingSphere()); Point3f position = new Point3f(0.0f, 0.0f, 1.0f); lightP1.setPosition(position); scene.addChild(lightP1); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(white); scene.addChild(background); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); //Enable Local Eye Lighting u.getViewer().getView().setLocalEyeLightingEnable(true); u.addBranchGraph(scene); }
From source file:HelloUniverse1.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the TransformGroup node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at run time. Add it to // the root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);// w ww .j av a2 s .c o m // Create a simple Shape3D node; add it to the scene graph. objTrans.addChild(new ColorCube(0.4)); // Create a new Behavior object that will perform the // desired operation on the specified transform and add // it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, 4000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objRoot.addChild(rotator); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:YoyoPointApp.java
public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objSpin);/*from w w w. ja v a 2 s . co m*/ objSpin.addChild(new Yoyo()); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, 4000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }