List of usage examples for javax.media.j3d TransformGroup addChild
public void addChild(Node child)
From source file:SimpleKeyNav.java
/** * Build the content branch for the scene graph * //from www .j av a2s .c o m * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { //Create the appearance an appearance for the two cubes Appearance app1 = new Appearance(); Appearance app2 = new Appearance(); Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f diffuseColour2 = new Color3f(1.0f, 1.0f, 0.0f); float shininess = 20.0f; app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess)); app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess)); //Make two cubes Box leftCube = new Box(1.0f, 1.0f, 1.0f, app1); Box rightCube = new Box(1.0f, 1.0f, 1.0f, app2); BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Put it all together Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); TransformGroup leftGroup = new TransformGroup(leftGroupXfm); Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); TransformGroup rightGroup = new TransformGroup(rightGroupXfm); leftGroup.addChild(leftCube); rightGroup.addChild(rightCube); contentBranch.addChild(leftGroup); contentBranch.addChild(rightGroup); return contentBranch; }
From source file:TwistStripApp.java
public BranchGroup createSceneGraph() { BranchGroup contentRoot = 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); contentRoot.addChild(objSpin);// w ww .j a va 2 s . com Shape3D twist = new Twist(); objSpin.addChild(twist); // Duplicate the twist strip geometry and set the // appearance of the new Shape3D object to line mode // without culling. // Add the POLYGON_FILLED and POLYGON_LINE strips // in the scene graph at the same point. // This will show the triangles of the original Mobius strip that // are clipped. The PolygonOffset is set to prevent stitching. PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrib.setPolygonOffset(0.001f); Appearance polyAppear = new Appearance(); polyAppear.setPolygonAttributes(polyAttrib); objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear)); Alpha rotationAlpha = new Alpha(-1, 16000); 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 1 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); // make background white Background background = new Background(1.0f, 1.0f, 1.0f); background.setApplicationBounds(bounds); contentRoot.addChild(background); // Let Java 3D perform optimizations on this scene graph. contentRoot.compile(); return contentRoot; }
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);//from ww w .ja v a2 s. c o m objTransform.addChild(new ColorCube(0.4)); objRoot.addChild(new Axis()); MouseRotate myMouseRotate = new MouseRotate(); myMouseRotate.setTransformGroup(objTransform); myMouseRotate.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myMouseRotate); 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:SimpleCombine.java
/** * This defines the shapes used in the scene. The function uses the utility * geometries sphere, box, cone and cylinder to build a simple scene. This * demonstrates the use of transformations to group and position items. * /* w w w .j a v a 2 s . c om*/ * @return Node that is the root of the shape hierarchy. */ protected Node buildShape() { //Create a root for the shapes in the scene BranchGroup theScene = new BranchGroup(); //Create an appearance for the ground Appearance groundApp = new Appearance(); Color3f groundColour = new Color3f(0.0f, 0.5f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(0.5f, 0.5f, 0.5f); float shininess = 10.0f; groundApp.setMaterial(new Material(groundColour, emissiveColour, groundColour, specularColour, shininess)); //Create a box that will be the ground Box ground = new Box(100.0f, 0.1f, 100.0f, groundApp); //Create a transform and a transform group that //will position the ground Transform3D grndXfm = new Transform3D(); grndXfm.set(new Vector3f(0.0f, -1.0f, 0.0f)); TransformGroup grndXfmGrp = new TransformGroup(grndXfm); //Add the ground shape to the group grndXfmGrp.addChild(ground); //Add the ground group to the scene group theScene.addChild(grndXfmGrp); //Create an appearance for the wall of the house Appearance wallApp = new Appearance(); Color3f wallColour = new Color3f(0.5f, 0.5f, 0.5f); wallApp.setMaterial(new Material(wallColour, emissiveColour, wallColour, specularColour, shininess)); //Create a cylinder that is the wall of the house Cylinder walls = new Cylinder(1.0f, 1.0f, Primitive.GENERATE_NORMALS, wallApp); //Create a group that will be the root of the house TransformGroup house = new TransformGroup(); //Add the walls to the house group house.addChild(walls); //Create an appearance for the roof Appearance roofApp = new Appearance(); Color3f roofColour = new Color3f(0.5f, 0.0f, 0.0f); roofApp.setMaterial(new Material(roofColour, emissiveColour, roofColour, specularColour, shininess)); //Create a cone that will be the roof Cone myRoof = new Cone(1.0f, 1.0f, Primitive.GENERATE_NORMALS, roofApp); //Create the transform and transform group that will position the //roof on the house Transform3D roofXfm = new Transform3D(); roofXfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup roofXfmGrp = new TransformGroup(roofXfm); //Add the roof to the roof transform group roofXfmGrp.addChild(myRoof); //Add the roof group to the house house.addChild(roofXfmGrp); //Create an appearance for the tree trunks Appearance trunkApp = new Appearance(); Color3f trunkColour = new Color3f(0.2f, 0.2f, 0.0f); trunkApp.setMaterial(new Material(trunkColour, emissiveColour, trunkColour, specularColour, shininess)); //Create an appearance for the tree leaves Appearance leafApp = new Appearance(); Color3f leafColour = new Color3f(0.0f, 0.2f, 0.0f); leafApp.setMaterial(new Material(leafColour, emissiveColour, leafColour, specularColour, shininess)); //Create a transform and transform group for the tree Transform3D treeXfm = new Transform3D(); treeXfm.set(new Vector3f(-2.0f, 0.0f, 0.5f)); TransformGroup treeXfmGrp = new TransformGroup(treeXfm); //Create a cylinder for the tree trunk Cylinder myTrunk = new Cylinder(0.1f, 1.0f, trunkApp); //Add the trunk to the tree group treeXfmGrp.addChild(myTrunk); //Create a transform and transform group for the tree leaves Transform3D leafXfm = new Transform3D(); leafXfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup leafXfmGrp = new TransformGroup(leafXfm); //Create the leaves Sphere myLeaf = new Sphere(0.5f, leafApp); //Add the leaves to the leaf group leafXfmGrp.addChild(myLeaf); //Add the leaf group to the tree group treeXfmGrp.addChild(leafXfmGrp); //Create another tree Transform3D tree1Xfm = new Transform3D(); tree1Xfm.set(new Vector3f(1.4f, 0.0f, -0.5f)); TransformGroup tree1XfmGrp = new TransformGroup(tree1Xfm); Cylinder myTrunk1 = new Cylinder(0.1f, 1.0f, trunkApp); tree1XfmGrp.addChild(myTrunk1); Transform3D leaf1Xfm = new Transform3D(); leaf1Xfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup leaf1XfmGrp = new TransformGroup(leaf1Xfm); Sphere myLeaf1 = new Sphere(0.5f, leafApp); leaf1XfmGrp.addChild(myLeaf1); tree1XfmGrp.addChild(leaf1XfmGrp); //Create the final tree Transform3D tree2Xfm = new Transform3D(); tree2Xfm.set(new Vector3f(1.2f, 0.0f, 1.0f)); TransformGroup tree2XfmGrp = new TransformGroup(tree2Xfm); Cylinder myTrunk2 = new Cylinder(0.1f, 1.0f, trunkApp); tree2XfmGrp.addChild(myTrunk2); Transform3D leaf2Xfm = new Transform3D(); leaf2Xfm.set(new Vector3f(0.0f, 1.0f, 0.0f)); TransformGroup leaf2XfmGrp = new TransformGroup(leaf2Xfm); Sphere myLeaf2 = new Sphere(0.5f, leafApp); leaf2XfmGrp.addChild(myLeaf2); tree2XfmGrp.addChild(leaf2XfmGrp); //Put the scene together by adding all the groups //to the scene group theScene.addChild(house); theScene.addChild(treeXfmGrp); theScene.addChild(tree1XfmGrp); theScene.addChild(tree2XfmGrp); return theScene; }
From source file:SimpleTest.java
public SimpleTest() { // create the SimpleUniverse class that will // encapsulate the scene that we are building. // SimpleUniverse is a helper class (utility) // from SUN that is included with the core Java 3D // distribution. SimpleUniverse u = new SimpleUniverse(); // create a BranchGroup. A BranchGroup is a node in // a Tree data structure that can have child nodes BranchGroup bgRoot = new BranchGroup(); // create the Background node and add it to the SimpleUniverse u.addBranchGraph(createBackground()); // create the behaviors to move the geometry along the X-axis. // The behavior is added as a child of the bgRoot node. // Anything add as a child of the tg node will be effected by the // behvior (will be moved along the X-axis). TransformGroup tg = createBehaviors(bgRoot); // add the Sphere geometry as a child of the tg // so that it will be moved along the X-axis. tg.addChild(createSceneGraph()); // because the sphere was added at the 0,0,0 coordinate // and by default the viewer is also located at 0,0,0 // we have to move the viewer back a little so that // she can see the scene. u.getViewingPlatform().setNominalViewingTransform(); // add a light to the root BranchGroup to illuminate the scene addLights(bgRoot);/*from w w w . ja va2 s . c om*/ // finally wire everything together by adding the root // BranchGroup to the SimpleUniverse u.addBranchGraph(bgRoot); }
From source file:SimpleGeometry.java
PlatformGeometry createAimer() { PlatformGeometry pg = new PlatformGeometry(); // This TransformGroup will be used by the MouseTranslate // utiltiy to move the cylinder around the canvas. when the // the user holds down mouse button 3. TransformGroup moveTG = new TransformGroup(); moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); MouseTranslate mouseT = new MouseTranslate(moveTG); moveTG.addChild(mouseT); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); mouseT.setSchedulingBounds(bounds);/* ww w .j a va2 s .co m*/ pg.addChild(moveTG); // This TransformGroup is used to place the cylinder in the scene. // The cylinder will be rotated 90 degrees so it will appear as // a circle on the screen (could be made into a nice gun site...). // The cylinder is also displaced a little in Z so it is in front // of the viewer. Transform3D xForm = new Transform3D(); xForm.rotX(Math.PI / 2.0); xForm.setTranslation(new Vector3d(0.0, 0.0, -0.7)); TransformGroup placementTG = new TransformGroup(xForm); moveTG.addChild(placementTG); // Create the cylinder - make it thin and transparent. Appearance cylinderAppearance = new Appearance(); TransparencyAttributes transAttrs = new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.5f); // cylinderAppearance.setTransparencyAttributes(transAttrs); Cylinder aimer = new Cylinder(0.06f, 0.005f, 0, cylinderAppearance); placementTG.addChild(aimer); return pg; }
From source file:PrintFromButton.java
public BranchGroup createSceneGraph(Raster drawRaster) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // spin object has composited transformation matrix Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 4.0d);/*from w ww. j a v a2s .c o m*/ tempspin.rotY(Math.PI / 5.0d); spin.mul(tempspin); spin.setScale(0.7); spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0)); TransformGroup objTrans = new TransformGroup(spin); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. // ColorCube is a Convenience Utility class objTrans.addChild(new ColorCube(0.4)); //Create a raster obj Shape3D shape = new Shape3D(drawRaster); objRoot.addChild(shape); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:StereoCube.java
public BranchGroup createSceneGraph(int i) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D t = new Transform3D(); TransformGroup tg = new TransformGroup(t); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.addChild(tg); tg.addChild(new ColorCube(0.4)); MouseRotate behavior = new MouseRotate(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); behavior.setTransformGroup(tg);/*from w w w. ja v a 2 s.c om*/ objTrans.addChild(behavior); // Create the translate behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(tg); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objTrans.addChild(keyNavBeh); behavior.setSchedulingBounds(bounds); objRoot.addChild(objTrans); return objRoot; }
From source file:Phong.java
/** * Erstellt den Szenegraphen//from www. j a va2 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); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { 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:OffScreenTest.java
public BranchGroup createSceneGraph(Raster drawRaster) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // spin object has composited transformation matrix Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 4.0d);//from w w w . j a v a2 s. co m tempspin.rotY(Math.PI / 5.0d); spin.mul(tempspin); spin.setScale(0.7); spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0)); TransformGroup objTrans = new TransformGroup(spin); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. // ColorCube is a Convenience Utility class objTrans.addChild(new ColorCube(0.4)); //Create a raster Shape3D shape = new Shape3D(drawRaster); objRoot.addChild(shape); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }