List of usage examples for javax.media.j3d BranchGroup BranchGroup
public BranchGroup()
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);//from w w w.j av a 2 s .co 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: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. * /* w ww. jav a 2s. c om*/ * @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:ImageComponentByReferenceTest.java
public BranchGroup createSceneGraph() { objRoot = new BranchGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE); objRoot.addChild(objTrans);//w w w . j a v a2s .c o m BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); app.setCapability(Appearance.ALLOW_TEXTURE_WRITE); textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app); boxShape = textureCube.getShape(Box.FRONT); boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); objTrans.addChild(textureCube); checkBoard = new TiledImage(); TextureLoader texLoader = new TextureLoader(texImage, this); ImageComponent2D oneImage = texLoader.getImage(); bImage1 = oneImage.getImage(); int index = 0; image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, true); image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, true); image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, false); image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, false); createRaster(objRoot); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, true); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, true); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, false); image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, false); texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[2].getWidth(), image[2].getHeight()); texOne.setCapability(Texture.ALLOW_IMAGE_WRITE); texOne.setImage(0, image[2]); app.setTexture(texOne); texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[4].getWidth(), image[4].getHeight()); texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE); objRoot.compile(); return objRoot; }
From source file:SimpleSpotLights.java
/** * This build the content branch of our scene graph. It creates a transform * group so that the shape is slightly tilted to reveal its 3D shape. * /* w ww . j a v a 2 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() { 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); //Create a new appearance Appearance app = new Appearance(); //Create the colours for the material Color3f ambientColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); //Define the shininess float shininess = 20.0f; //Set the material of the appearance app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Create and add a new sphere using the appearance rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); //Use the addLights function to add the lights to the branch addLights(contentBranch); //Return the root of the content branch return contentBranch; }
From source file:cgview.java
public BranchGroup createSceneGraph(CompressedGeometry cg) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.7);/*w ww .j a v a 2 s . com*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // 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 objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); // Add compressed geometry to the scene graph. CompressedGeometryHeader hdr = new CompressedGeometryHeader(); cg.getCompressedGeometryHeader(hdr); // There isn't really enough information in the compressed geometry // header to unamiguously determine the proper rendering attributes. // The bufferDataPresent field specifies whether or not normals are // bundled with vertices, but the compressed buffer can still contain // normals that should be lit. Assume that any surface geometry // should be lit and that lines and points should not unless the // header contains the NORMAL_IN_BUFFER bit. Material m = new Material(); if ((hdr.bufferType == hdr.TRIANGLE_BUFFER) || ((hdr.bufferDataPresent & hdr.NORMAL_IN_BUFFER) == 1)) m.setLightingEnable(true); else m.setLightingEnable(false); Appearance a = new Appearance(); a.setMaterial(m); objTrans.addChild(new Shape3D(cg, a)); // Create mouse behavior scheduling bounds. BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objRoot.addChild(bgNode); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -0.9f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objRoot.addChild(light2); return objRoot; }
From source file:KeyNavigatorApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph TransformGroup vpTrans = null;//w ww.j a v a 2s. c o m BranchGroup objRoot = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); TransformGroup TG = null; objRoot.addChild(createLand()); SharedGroup share = new SharedGroup(); share.addChild(createPyramid()); float[][] position = { { 0.0f, 0.0f, -3.0f }, { 6.0f, 0.0f, 0.0f }, { 6.0f, 0.0f, 6.0f }, { 3.0f, 0.0f, -10.0f }, { 13.0f, 0.0f, -30.0f }, { -13.0f, 0.0f, 30.0f }, { -13.0f, 0.0f, 23.0f }, { 13.0f, 0.0f, 3.0f } }; for (int i = 0; i < position.length; i++) { translate.set(position[i]); T3D.setTranslation(translate); TG = new TransformGroup(T3D); TG.addChild(new Link(share)); objRoot.addChild(TG); } vpTrans = su.getViewingPlatform().getViewPlatformTransform(); translate.set(0.0f, 0.3f, 0.0f); T3D.setTranslation(translate); vpTrans.setTransform(T3D); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objRoot.addChild(keyNavBeh); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:GearTest.java
public BranchGroup createSceneGraph(int toothCount) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);/*w w w. j a v a 2 s . co m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objScale.addChild(bgNode); // Set up the global lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f); Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f); Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objScale.addChild(ambientLightNode); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objScale.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objScale.addChild(light2); // 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 objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(objTrans); // Create an Appearance. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); // Create a gear, add it to the scene graph. // SpurGear gear = new SpurGear(toothCount, 1.0f, 0.2f, SpurGear gear = new SpurGearThinBody(toothCount, 1.0f, 0.2f, 0.05f, 0.05f, 0.3f, 0.28f, look); objTrans.addChild(gear); // Create a new Behavior object that will rotate the object and // add it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 8000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:BooksDemo.java
public void createScene() { BufferedImage image = new BufferedImage(xpanel.getWidth(), xpanel.getHeight(), BufferedImage.TYPE_INT_RGB); getContentPane().paint(image.getGraphics()); BufferedImage subImage = new BufferedImage(CANVAS3D_WIDTH, CANVAS3D_HEIGHT, BufferedImage.TYPE_INT_RGB); ((Graphics2D) subImage.getGraphics()).drawImage(image, null, -c3d.getX(), -c3d.getY()); Background bg = new Background(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, subImage)); BoundingSphere bounds = new BoundingSphere(); bounds.setRadius(100.0);/*from w w w.ja v a2s . c o m*/ bg.setApplicationBounds(bounds); BranchGroup objRoot = new BranchGroup(); objRoot.addChild(bg); TransformGroup objTg = new TransformGroup(); objTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); rotor1Alpha = new Alpha(1, 400); rotator1 = new RotationInterpolator(rotor1Alpha, objTg, yAxis, (float) Math.PI * 1.0f, (float) Math.PI * 2.0f); rotator1.setSchedulingBounds(bounds); textures.put("pages_top", createTexture("pages_top.jpg")); textures.put("pages", createTexture("amazon.jpg")); textures.put("amazon", createTexture("amazon.jpg")); textures.put("cover1", createTexture("cover1.jpg")); textures.put("cover2", createTexture("cover2.jpg")); textures.put("cover3", createTexture("cover3.jpg")); book = new com.sun.j3d.utils.geometry.Box(0.5f, 0.7f, 0.15f, com.sun.j3d.utils.geometry.Box.GENERATE_TEXTURE_COORDS, new Appearance()); book.getShape(book.TOP).setAppearance((Appearance) textures.get("pages_top")); book.getShape(book.RIGHT).setAppearance((Appearance) textures.get("pages")); book.getShape(book.LEFT).setAppearance((Appearance) textures.get("amazon")); book.getShape(book.FRONT).setAppearance((Appearance) textures.get("cover1")); book.getShape(book.BACK).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); book.getShape(book.FRONT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); // book.getShape(book.LEFT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); // book.getShape(book.RIGHT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); objTg.addChild(book); objTg.addChild(rotator1); Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 8.0d); tempspin.rotY(Math.PI / 7.0d); spin.mul(tempspin); TransformGroup objTrans = new TransformGroup(spin); objTrans.addChild(objTg); objRoot.addChild(objTrans); SimpleUniverse u = new SimpleUniverse(c3d); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(objRoot); View view = u.getViewer().getView(); view.setSceneAntialiasingEnable(true); }
From source file:Gouraud.java
/** * Erstellt den Szenegraphen/*from w ww.j a v a 2 s .c o 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); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { // Laden der Obj Datei mittels jar scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }
From source file:AvatarTest.java
public void createBackground(Group bg) { // add the sky backdrop Background back = new Background(); back.setApplicationBounds(getBoundingSphere()); bg.addChild(back);/* w w w. jav a 2 s. c o m*/ BranchGroup bgGeometry = new BranchGroup(); // create an appearance and assign the texture image Appearance app = new Appearance(); Texture tex = new TextureLoader("back.jpg", this).getTexture(); app.setTexture(tex); Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD, app); bgGeometry.addChild(sphere); back.setGeometry(bgGeometry); }