List of usage examples for javax.media.j3d BranchGroup BranchGroup
public BranchGroup()
From source file:PickCallbackApp.java
public BranchGroup createSceneGraph(Canvas3D canvas) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objRotate = null;/*from w ww . ja v a2 s . com*/ PickRotateBehavior pickRotate = null; Transform3D transform = new Transform3D(); BoundingSphere behaveBounds = new BoundingSphere(); // create ColorCube and PickRotateBehavior objects transform.setTranslation(new Vector3f(-0.6f, 0.0f, -0.6f)); objRotate = new TransformGroup(transform); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objRoot.addChild(objRotate); objRotate.addChild(new ColorCube(0.4)); pickRotate = new PickRotateBehavior(objRoot, canvas, behaveBounds); objRoot.addChild(pickRotate); PickingCallback myCallback = new MyCallbackClass(); // Register the class callback to be called pickRotate.setupCallback(myCallback); // add a second ColorCube object to the scene graph transform.setTranslation(new Vector3f(0.6f, 0.0f, -0.6f)); objRotate = new TransformGroup(transform); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objRoot.addChild(objRotate); objRotate.addChild(new ColorCube(0.4)); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Text2DApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objSpin);//from w ww .j a v a2 s . c om // Create a simple Text2D leaf node, add it to the scene graph. Text2D text2d = new Text2D("2D text in Java 3D", new Color3f(0.9f, 1.0f, 1.0f), "Helvetica", 24, Font.ITALIC); objSpin.addChild(text2d); Appearance textAppear = text2d.getAppearance(); // The following 4 lines of code (commented out) make the Text2D object // 2-sided. // This code depends on the line of code above that sets TextAppear. // PolygonAttributes polyAttrib = new PolygonAttributes(); // polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); // polyAttrib.setBackFaceNormalFlip(true); // textAppear.setPolygonAttributes(polyAttrib); // The following 12 lines of code (commented out) use the texture from // the previous Text2D object on another object. // This code depends on the line of code above that sets TextAppear. // QuadArray qa = new QuadArray(4, QuadArray.COORDINATES | // QuadArray.TEXTURE_COORDINATE_2); // qa.setCoordinate(0, new Point3f(-10.0f, 1.0f, -5.0f)); // qa.setCoordinate(1, new Point3f(-10.0f, -1.0f, -5.0f)); // qa.setCoordinate(2, new Point3f(10.0f, -1.0f, -5.0f)); // qa.setCoordinate(3, new Point3f(10.0f, 1.0f, -5.0f)); // qa.setTextureCoordinate(0, new Point2f(0.0f, 1.0f)); // qa.setTextureCoordinate(1, new Point2f(0.0f, 0.0f)); // qa.setTextureCoordinate(2, new Point2f(1.0f, 0.0f)); // qa.setTextureCoordinate(3, new Point2f(1.0f, 1.0f)); // // objRoot.addChild(new Shape3D(qa, textAppear)); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Alpha rotationAlpha = new Alpha(-1, 8000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 100 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); Background backg = new Background(); backg.setColor(0.4f, 0.4f, 1.0f); backg.setApplicationBounds(new BoundingSphere()); objRoot.addChild(backg); return objRoot; }
From source file:SimpleCylinder.java
/** * This builds the content branch of our scene graph. It uses the Cylinder * utility class to create the actual shape, adding to to the transform * group so that the shape is slightly tilted to reveal its 3D shape. * /*from w ww .j a v a2s .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 the shape and add it to the branch rotationGroup.addChild(new Cylinder(1.0f, 1.0f, new Appearance())); return contentBranch; }
From source file:SimpleCone.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. * // www . ja v a 2 s .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() { 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(new Cone(1.0f, 2.0f, 0, new Appearance())); return contentBranch; }
From source file:AppearanceTest.java
private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // 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 TextureLoader bgTexture = new TextureLoader(bgImage, this); Background bg = new Background(bgTexture.getImage()); bg.setApplicationBounds(bounds);//from w w w . j av a 2 s . co m objRoot.addChild(bg); // Set up the global lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; Appearance[][] app = new Appearance[3][3]; for (row = 0; row < 3; row++) for (col = 0; col < 3; col++) app[row][col] = createAppearance(row * 3 + col); for (int i = 0; i < 3; i++) { double ypos = (double) (i - 1) * 0.6; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 0.6; objRoot.addChild(createObject(app[i][j], 0.12, xpos, ypos)); } } // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Position.java
public Position() { SimpleUniverse universe = new SimpleUniverse(); BranchGroup group = new BranchGroup(); // X axis made of spheres for (float x = -1.0f; x <= 1.0f; x = x + 0.1f) { Sphere sphere = new Sphere(0.05f); TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Vector3f vector = new Vector3f(x, .0f, .0f); transform.setTranslation(vector); tg.setTransform(transform);/*from w w w.j a va 2 s . c om*/ tg.addChild(sphere); group.addChild(tg); } // Y axis made of cones for (float y = -1.0f; y <= 1.0f; y = y + 0.1f) { TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Cone cone = new Cone(0.05f, 0.1f); Vector3f vector = new Vector3f(.0f, y, .0f); transform.setTranslation(vector); tg.setTransform(transform); tg.addChild(cone); group.addChild(tg); } // Z axis made of cylinders for (float z = -1.0f; z <= 1.0f; z = z + 0.1f) { TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Cylinder cylinder = new Cylinder(0.05f, 0.1f); Vector3f vector = new Vector3f(.0f, .0f, z); transform.setTranslation(vector); tg.setTransform(transform); tg.addChild(cylinder); group.addChild(tg); } Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); group.addChild(light1); universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:TextureImage.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph 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 objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);//from w w w. j ava 2 s .c om // Create appearance object for textured cube Appearance app = new Appearance(); Texture tex = new TextureLoader(texImage, this).getTexture(); app.setTexture(tex); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Create textured cube and add it to the scene graph. Box textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS, app); objTrans.addChild(textureCube); // 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, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); 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); objTrans.addChild(rotator); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:LOD.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); createLights(objRoot);/* ww w .j av a2s.co m*/ // 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); objRoot.addChild(objTrans); // Create a switch to hold the different levels of detail Switch sw = new Switch(0); sw.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_READ); sw.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_WRITE); // Create several levels for the switch, with less detailed // spheres for the ones which will be used when the sphere is // further away sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 40)); sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 20)); sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 10)); sw.addChild(new Sphere(0.4f, Sphere.GENERATE_NORMALS, 3)); // Add the switch to the main group objTrans.addChild(sw); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // set up the DistanceLOD behavior float[] distances = new float[3]; distances[0] = 5.0f; distances[1] = 10.0f; distances[2] = 25.0f; DistanceLOD lod = new DistanceLOD(distances); lod.addSwitch(sw); lod.setSchedulingBounds(bounds); objTrans.addChild(lod); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:MouseNavigatorApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup vpTrans = null;//from w ww .j a va2 s. c om BoundingSphere mouseBounds = null; vpTrans = su.getViewingPlatform().getViewPlatformTransform(); objRoot.addChild(new ColorCube(0.4)); objRoot.addChild(new Axis()); mouseBounds = new BoundingSphere(new Point3d(), 1000.0); MouseRotate myMouseRotate = new MouseRotate(MouseBehavior.INVERT_INPUT); myMouseRotate.setTransformGroup(vpTrans); myMouseRotate.setSchedulingBounds(mouseBounds); objRoot.addChild(myMouseRotate); MouseTranslate myMouseTranslate = new MouseTranslate(MouseBehavior.INVERT_INPUT); myMouseTranslate.setTransformGroup(vpTrans); myMouseTranslate.setSchedulingBounds(mouseBounds); objRoot.addChild(myMouseTranslate); MouseZoom myMouseZoom = new MouseZoom(MouseBehavior.INVERT_INPUT); myMouseZoom.setTransformGroup(vpTrans); myMouseZoom.setSchedulingBounds(mouseBounds); objRoot.addChild(myMouseZoom); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:AxisClassDemoApp.java
public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); objRoot.addChild(new Axis()); // 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); // 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); Transform3D trans = new Transform3D(); trans.set(new Vector3f(0.5f, 0.0f, 0.0f)); TransformGroup objTrans = new TransformGroup(trans); objRoot.addChild(objSpin);/*from w w w.j a va 2s . co m*/ objSpin.addChild(objTrans); objSpin.addChild(rotator); objTrans.addChild(new ColorCube(0.1)); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }