List of usage examples for javax.media.j3d Transform3D Transform3D
public Transform3D()
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. * /*from w ww. j av a 2s . 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:MultiView.java
public TransformGroup[] getViewTransformGroupArray() { // increment the view count m_nNumViews++;//www.j ava 2 s .co m TransformGroup[] tgArray = new TransformGroup[1]; tgArray[0] = new TransformGroup(); Vector3d vTrans = new Vector3d(0.0, 0.0, -20); // move the camera BACK so we can view the scene // also set the scale so that the more views we have // the smaller the scene will be scaled Transform3D t3d = new Transform3D(); t3d.setTranslation(vTrans); t3d.setScale(1.0 / m_nNumViews); t3d.invert(); tgArray[0].setTransform(t3d); return tgArray; }
From source file:ScenegraphTest.java
private TransformGroup createArm(double rotX, double rotY, double rotZ) { TransformGroup tgShoulder = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setEuler(new Vector3d(rotX, rotY, rotZ)); tgShoulder.setTransform(t3d);/*from w w w . j a va 2 s. c o m*/ TransformGroup tgParent = null; tgParent = addLimb(tgShoulder, "Upper Arm", 0.05, 0.5, 0.0, 0.0); tgParent = addLimb(tgParent, "Lower Arm", 0.03, 0.4, Math.PI * -0.5, Math.PI * 0.8); TransformGroup tgWrist = addLimb(tgParent, "Wrist", 0.03, 0.07, 0.0, Math.PI * 0.5); addLimb(tgWrist, "Thumb", 0.01, 0.05, 0.0, Math.PI * 0.5); addLimb(tgWrist, "Finger 1", 0.01, 0.08, 0.0, Math.PI * 0.3); addLimb(tgWrist, "Finger 2", 0.01, 0.10, 0.0, Math.PI * 0.3); addLimb(tgWrist, "Finger 3", 0.01, 0.08, 0.0, Math.PI * 0.3); addLimb(tgWrist, "Finger 4", 0.01, 0.05, 0.0, Math.PI * 0.3); return tgShoulder; }
From source file:ExLightBounds.java
public Group buildScene() { // Get the current bounding leaf position Point3f pos = (Point3f) positions[currentPosition].value; // Turn off the example headlight setHeadlightEnable(false);//from ww w . j a v a 2s .c om // Build the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create a bounding leaf we'll use or not use depending // upon menu selections. Put it within a transform group // so that we can move the leaf about. leafTransformGroup = new TransformGroup(); leafTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D tr = new Transform3D(); tr.setTranslation(new Vector3f(pos)); leafTransformGroup.setTransform(tr); leafBounds = new BoundingLeaf(worldBounds); leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE); leafTransformGroup.addChild(leafBounds); scene.addChild(leafTransformGroup); // Add a directional light whose bounds we'll modify // Set its color and aim direction light = new DirectionalLight(); light.setEnable(true); light.setColor(White); light.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE); // Set the bounds to be either from the leaf or from // explicit bounds, depending upon the menu initial state if (boundingLeafOnOff) // Use bounding leaf light.setInfluencingBoundingLeaf(leafBounds); else // Use bounds on the light light.setInfluencingBounds(worldBounds); // Set the scope list to include nothing initially. // This defaults to "universal scope" which covers // everything. scene.addChild(light); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional light is being bounded... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(White); ambient.setInfluencingBounds(worldBounds); scene.addChild(ambient); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); return scene; }
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);// www . jav a2s .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: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);/* w w w .ja va 2 s . c o m*/ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); mouseT.setSchedulingBounds(bounds); 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:NodesTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); double labelScale = 20; // create the top level Switch Node // we will use the Switch Node to switch the // other Nodes on and off. // 1: Switch//from w w w . ja v a 2 s . co m Switch switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); switchGroup.addChild(createLabel("1. Switch Label", labelScale)); // 2: BranchGroup BranchGroup branchGroup = new BranchGroup(); branchGroup.addChild(createLabel("2. BranchGroup", labelScale)); switchGroup.addChild(branchGroup); // 3: OrderedGroup, OrderedGroup orderedGroup = new OrderedGroup(); orderedGroup.addChild(createLabel("3. OrderedGroup", labelScale)); orderedGroup.addChild(createLabel("Child 1", labelScale)); orderedGroup.addChild(createLabel("Child 2", labelScale)); switchGroup.addChild(orderedGroup); // 4: SharedGroup, SharedGroup sharedGroup1 = new SharedGroup(); sharedGroup1.addChild(createLabel("4. Shared Group 1", labelScale)); switchGroup.addChild(new Link(sharedGroup1)); // 5: Primitive, BranchGroup primitiveGroup = new BranchGroup(); primitiveGroup.addChild(createLabel("5. Primitive", labelScale)); primitiveGroup.addChild(new Sphere(2)); switchGroup.addChild(primitiveGroup); // 6: TransformGroup TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); transformGroup.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, transformGroup, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(createApplicationBounds()); transformGroup.addChild(rotator); transformGroup.addChild(new ColorCube(2)); transformGroup.addChild(createLabel("6. TransformGroup", labelScale)); switchGroup.addChild(transformGroup); // 7: add another copy of the shared group switchGroup.addChild(new Link(sharedGroup1)); // create a SwitchValueInterpolator to // cycle through the child nodes in the Switch Node Alpha switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(switchAlpha, switchGroup); switchInterpolator.setSchedulingBounds(createApplicationBounds()); switchInterpolator.setEnable(true); // WARNING: do not add the SwitchValueInterpolator to the Switch Node! objRoot.addChild(switchInterpolator); // finally add the Switch Node objRoot.addChild(switchGroup); return objRoot; }
From source file:YoyoPointApp.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 www .java2s. c o m objSpin.addChild(new Yoyo()); // 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:Morphing.java
private 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 w w w . j a va 2 s . c om 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 bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.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); objScale.addChild(aLgt); objScale.addChild(lgt1); // // Create the transform group nodes for the 3 original objects // and the morphed object. Add them to the root of the // branch graph. // TransformGroup objTrans[] = new TransformGroup[4]; for (int i = 0; i < 4; i++) { objTrans[i] = new TransformGroup(); objScale.addChild(objTrans[i]); } Transform3D tr = new Transform3D(); Transform3D rotX90 = new Transform3D(); rotX90.rotX(90.0 * Math.PI / 180.0); objTrans[0].getTransform(tr); tr.setTranslation(new Vector3d(-2.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[0].setTransform(tr); objTrans[1].getTransform(tr); tr.setTranslation(new Vector3d(0.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[1].setTransform(tr); objTrans[2].getTransform(tr); tr.setTranslation(new Vector3d(2.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[2].setTransform(tr); objTrans[3].getTransform(tr); tr.setTranslation(new Vector3d(0.0, -2.0, -2.0)); tr.mul(rotX90); objTrans[3].setTransform(tr); // Now load the object files Scene s[] = new Scene[3]; GeometryArray g[] = new GeometryArray[3]; Shape3D shape[] = new Shape3D[3]; ObjectFile loader = new ObjectFile(ObjectFile.RESIZE); for (int i = 0; i < 3; i++) { s[i] = null; g[i] = null; shape[i] = null; } for (int i = 0; i < 3; i++) { try { s[i] = loader.load(objFiles[i]); } catch (FileNotFoundException e) { System.err.println(e); System.exit(1); } catch (ParsingErrorException e) { System.err.println(e); System.exit(1); } catch (IncorrectFormatException e) { System.err.println(e); System.exit(1); } BranchGroup b = s[i].getSceneGroup(); shape[i] = (Shape3D) b.getChild(0); g[i] = (GeometryArray) shape[i].getGeometry(); shape[i].setGeometry(g[i]); objTrans[i].addChild(b); } // // Create a Morph node, and set the appearance and input geometry // arrays. Set the Morph node's capability bits to allow the weights // to be modified at runtime. // Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); Morph morph = new Morph(g, app); morph.setCapability(Morph.ALLOW_WEIGHTS_READ); morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE); objTrans[3].addChild(morph); // Now create the Alpha object that controls the speed of the // morphing operation. Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 2000, 1000, 200, 2000, 1000, 200); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objScale.addChild(mBeh); return objRoot; }
From source file:RasterTest.java
protected BranchGroup createSceneBranchGroup() { // create some simple geometry (a rotating ColorCube) // and a Shape3D object for the Raster containing the Image BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); yAxis.rotX(0.6);//from w ww . ja v a2s . co m 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); // wrap the Raster in a Shape3D Shape3D shape = new Shape3D(m_RenderRaster); objRoot.addChild(shape); objTrans.addChild(new ColorCube(1.0)); objRoot.addChild(objTrans); return objRoot; }