List of usage examples for javax.media.j3d TransformGroup addChild
public void addChild(Node child)
From source file:PickCollisionTest.java
protected void addSphere(BranchGroup bg, double x, double y, double z, Vector3d incVector, String name) { Appearance app = new Appearance(); TransformGroup sphereTg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); sphereTg.setTransform(t3d);/*from w w w. j a v a 2s. c o m*/ sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); sphereTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); sphereTg.addChild(new Sphere(1, app)); bg.addChild(sphereTg); recursiveSetUserData(sphereTg, name); // create the collision behaviour CollisionBehavior collisionBehavior = new CollisionBehavior(bg, sphereTg, app, new Vector3d(x, y, z), incVector); collisionBehavior.setSchedulingBounds(getApplicationBounds()); bg.addChild(collisionBehavior); }
From source file:BillboardTest.java
private TransformGroup createBillboard(String szText, Point3f locationPoint, int nMode, Point3f billboardPoint, BoundingSphere bounds) {//from ww w . j a v a 2 s . com TransformGroup subTg = new TransformGroup(); subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Font3D f3d = new Font3D(new Font("SansSerif", Font.PLAIN, 10), new FontExtrusion()); Text3D label3D = new Text3D(f3d, szText, locationPoint); Appearance app = new Appearance(); Color3f black = new Color3f(0.1f, 0.1f, 0.1f); Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); Shape3D sh = new Shape3D(label3D, app); subTg.addChild(sh); Billboard billboard = new Billboard(subTg, nMode, billboardPoint); billboard.setSchedulingBounds(bounds); subTg.addChild(billboard); return subTg; }
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 www.j a va 2s .c o 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; }
From source file:BoundsTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // do NOT auto compute bounds for this node objRoot.setBoundsAutoCompute(false); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 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); rotator.setSchedulingBounds(createApplicationBounds()); objTrans.addChild(rotator); objTrans.addChild(createColorCubes()); objTrans.addChild(createPoints());/*ww w .j a v a 2 s . c o m*/ objRoot.addChild(objTrans); return objRoot; }
From source file:Text3DLoad.java
public BranchGroup createSceneGraph() { float sl = textString.length(); // 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(); // Assuming uniform size chars, set scale to fit string in view t3d.setScale(1.2 / sl);//from w w w . jav a 2 s . c o m 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); Font3D f3d; if (tessellation > 0.0) { f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), tessellation, new FontExtrusion()); } else { f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); } Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, -1.f, -1.f)); Shape3D sh = new Shape3D(); Appearance app = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); app.setMaterial(mm); sh.setGeometry(txt); sh.setAppearance(app); objTrans.addChild(sh); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); if (false) { 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); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); } // 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.3f, 0.3f, 0.3f); 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, -1.0f); 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:TriangulatorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 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); // triangulate the polygon GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(m_VertexArray);/* ww w.j ava 2 s . c om*/ int[] stripCountArray = { 10, 5 }; int[] countourCountArray = { stripCountArray.length }; gi.setContourCounts(countourCountArray); gi.setStripCounts(stripCountArray); Triangulator triangulator = new Triangulator(); triangulator.triangulate(gi); NormalGenerator normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(gi); // create an appearance Appearance ap = new Appearance(); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); ap.setPolygonAttributes(polyAttrbutes); // add both a wireframe and a solid version // of the triangulated surface Shape3D shape1 = new Shape3D(gi.getGeometryArray(), ap); Shape3D shape2 = new Shape3D(gi.getGeometryArray()); objTrans.addChild(shape1); objTrans.addChild(shape2); objRoot.addChild(objTrans); return objRoot; }
From source file:PointTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 14000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(rotator); Switch switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); switchGroup.addChild(createPoints(1, 5, false)); switchGroup.addChild(createPoints(1, 5, true)); switchGroup.addChild(createPoints(8, 10, false)); switchGroup.addChild(createPoints(8, 10, true)); switchGroup.addChild(createPoints(2, 5, false)); switchGroup.addChild(createPoints(2, 5, true)); switchGroup.addChild(createPoints(2, 20, false)); switchGroup.addChild(createPoints(2, 20, true)); // create a SwitchValueInterpolator to // cycle through the child nodes in the Switch Node Alpha switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 15000, 0, 0, 0, 0, 0); SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(switchAlpha, switchGroup); switchInterpolator.setSchedulingBounds(getApplicationBounds()); switchInterpolator.setEnable(true);// ww w.j a va 2 s . c om // WARNING: do not add the SwitchValueInterpolator to the Switch Node! objRoot.addChild(switchInterpolator); objTrans.addChild(switchGroup); objRoot.addChild(objTrans); return objRoot; }
From source file:DoorApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup doorTG = new TransformGroup(); doorTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); doorTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); OpenBehavior openObject = new OpenBehavior(doorTG); CloseBehavior closeObject = new CloseBehavior(doorTG); //prepare the behavior objects openObject.setBehaviorObjectPartner(closeObject); closeObject.setBehaviorObjectPartner(openObject); // set scheduling bounds for behavior objects BoundingSphere bounds = new BoundingSphere(); openObject.setSchedulingBounds(bounds); closeObject.setSchedulingBounds(bounds); // assemble scene graph objRoot.addChild(openObject);//from ww w. ja v a 2 s. com objRoot.addChild(closeObject); objRoot.addChild(doorTG); doorTG.addChild(new ColorCube(0.4)); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:MultiView.java
public BranchGroup createSceneBranchGroup() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); //Make the scene graph try {/*from w w w. j ava 2 s . co m*/ TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans); // Create appearance object for textured cube Appearance app = new Appearance(); Texture tex = new TextureLoader("Dog.jpg", this).getTexture(); app.setTexture(tex); // Create a simple shape leaf node, add it to the scene graph. Box textureCube = new Box(2, 3, 4, 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); } catch (RuntimeException e) { System.out.println("MultiView.createSceneBranchGroup:" + e.getMessage()); System.exit(-1); } return objRoot; }
From source file:ScenegraphTest.java
TransformGroup createLimb(double radius, double length) { // because the cylinder is centered at 0,0,0 // we need to shift the cylinder so that the bottom of // the cylinder is at 0,0,0 and the top is at 0, length, 0 TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(0, length / 2, 0)); tg.setTransform(t3d);/* w w w .j av a 2 s .c o m*/ Appearance app = new Appearance(); Color3f black = new Color3f(0.4f, 0.2f, 0.1f); Color3f objColor = new Color3f(1, 0.8f, 0.6f); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); Cylinder cylinder = new Cylinder((float) radius, (float) length, Primitive.GENERATE_NORMALS, app); tg.addChild(cylinder); return tg; }