List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:Text2DTest.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); u = new SimpleUniverse(c); MoverBehavior navigator = new MoverBehavior(u.getViewingPlatform().getViewPlatformTransform()); scene.addChild(navigator); // Have Java 3D perform optimizations on this scene graph. scene.compile();//from w w w .ja v a 2 s. c om // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:MouseBehaviorApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objTransform = new TransformGroup(); objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(objTransform); objTransform.addChild(new ColorCube(0.4)); objRoot.addChild(new Axis()); MouseRotate myMouseRotate = new MouseRotate(); myMouseRotate.setTransformGroup(objTransform); myMouseRotate.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myMouseRotate);//from ww w . ja v a 2 s. c om MouseTranslate myMouseTranslate = new MouseTranslate(); myMouseTranslate.setTransformGroup(objTransform); myMouseTranslate.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myMouseTranslate); MouseZoom myMouseZoom = new MouseZoom(); myMouseZoom.setTransformGroup(objTransform); myMouseZoom.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myMouseZoom); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleSphere.java
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)); // rotateCube.set(new AxisAngle4d(1.0,0.0,0.0,Math.PI/2.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); addLights(contentBranch);//from w ww . j av a2s . c o m return contentBranch; }
From source file:HelloJava3Db.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // rotate object has composited transformation matrix Transform3D rotate = new Transform3D(); Transform3D tempRotate = new Transform3D(); rotate.rotX(Math.PI / 4.0d);//from www . ja v a 2 s . c om tempRotate.rotY(Math.PI / 5.0d); rotate.mul(tempRotate); TransformGroup objRotate = new TransformGroup(rotate); 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:HelloJava3Dbalt.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // rotate object has composited transformation matrix Transform3D rotate = new Transform3D(); Transform3D tempRotate = new Transform3D(); rotate.rotX(Math.PI / 4.0d);/* ww w.j a va 2 s .c o m*/ tempRotate.rotY(Math.PI / 5.0d); tempRotate.mul(rotate); TransformGroup objRotate = new TransformGroup(tempRotate); 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); // 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);//from ww w .j a v a2 s . co m 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:Erscheinungsbild.java
/** * Erstellt den Szenegraphen//from w w w. j av a2 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); objDreh.addChild(new Box(0.5f, 0.5f, 0.5f, makeAppearance())); objWurzel.addChild(objDreh); return objWurzel; }
From source file:SimpleGeometry.java
public BranchGroup createSceneGraph() { // 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);//from www . j a v a2s . c om 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); objScale.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. objTrans.addChild(new ColorCube()); // 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:Text2DTest1.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); Color3f color = new Color3f(0.0f, 0.0f, 0.0f); objRoot.addChild(createText2D("400 point 1x", color, 400, 1.0f, 6.0f)); objRoot.addChild(createText2D("150 point 3x", color, 150, 3.0f, 3.0f)); objRoot.addChild(createText2D("50 point 10x", color, 50, 10.0f, 0.0f)); objRoot.addChild(createText2D("10 point 50x", color, 10, 50.0f, -3.0f)); objRoot.addChild(createText2D("5 point 100x", color, 5, 100.0f, -6.0f)); return objRoot; }
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 w ww .j a va 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(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; }