List of usage examples for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ
int ALLOW_TRANSFORM_READ
To view the source code for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ.
Click Source Link
From source file:AppearanceTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup zoomTg = new TransformGroup(); zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // attach a navigation behavior to the position of the viewer KeyNavigatorBehavior key = new KeyNavigatorBehavior(zoomTg); key.setSchedulingBounds(createApplicationBounds()); key.setEnable(true);// ww w . ja v a2s .c o m objRoot.addChild(key); // create a TransformGroup to flip the hand onto its end and enlarge it. TransformGroup objTrans1 = new TransformGroup(); Transform3D tr = new Transform3D(); objTrans1.getTransform(tr); tr.setEuler(new Vector3d(0.5 * Math.PI, 0.6, 0)); objTrans1.setTransform(tr); // 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(getApplicationBounds()); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(getApplicationBounds()); objRoot.addChild(aLgt); objRoot.addChild(lgt1); int nScale = 50; Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, m_Appearance); Shape3D frontFace = box.getShape(Box.LEFT); // create a new left face so we can // assign per-vertex colors GeometryArray geometry = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR_4 | GeometryArray.TEXTURE_COORDINATE_2); nScale = 40; final float[] verts = { // left face -1.0f * nScale, -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, 1.0f * nScale, 1.0f * nScale, -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale }; final float[] colors = { // left face 1, 0, 0, 0, 0, 1, 0, 0.2f, 0, 0, 1, 0.8f, 0, 0, 0, 1, }; float[] tcoords = { // left 1, 0, 1, 1, 0, 1, 0, 0 }; Vector3f normalVector = new Vector3f(-1.0f, 0.0f, 0.0f); geometry.setColors(0, colors, 0, 4); for (int n = 0; n < 4; n++) geometry.setNormal(n, normalVector); geometry.setTextureCoordinates(0, tcoords, 0, 4); geometry.setCoordinates(0, verts); frontFace.setGeometry(geometry); // connect the scenegraph objTrans1.addChild(box); zoomTg.addChild(objTrans1); objRoot.addChild(zoomTg); return objRoot; }
From source file:PlatformTest.java
ViewingPlatform createViewer(Canvas3D c, String szName, Color3f objColor, double x, double z) { // create a Viewer and attach to its canvas // a Canvas3D can only be attached to a single Viewer Viewer viewer2 = new Viewer(c); // create a ViewingPlatform with 1 TransformGroups above the // ViewPlatform ViewingPlatform vp2 = new ViewingPlatform(1); // create and assign the PlatformGeometry to the Viewer vp2.setPlatformGeometry(createPlatformGeometry(szName)); // create and assign the ViewerAvatar to the Viewer viewer2.setAvatar(createViewerAvatar(szName, objColor)); // set the initial position for the Viewer Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, 0, z)); vp2.getViewPlatformTransform().setTransform(t3d); // set capabilities on the TransformGroup so that the // KeyNavigatorBehavior // can modify the Viewer's position vp2.getViewPlatformTransform().setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); vp2.getViewPlatformTransform().setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // attach a navigation behavior to the position of the viewer KeyNavigatorBehavior key = new KeyNavigatorBehavior(vp2.getViewPlatformTransform()); key.setSchedulingBounds(m_Bounds); key.setEnable(false);/*w w w. ja v a 2 s . c om*/ // add the KeyNavigatorBehavior to the ViewingPlatform vp2.addChild(key); // set the ViewingPlatform for the Viewer viewer2.setViewingPlatform(vp2); // associate the name of the Viewer with its KeyNavigatorBehavior m_KeyHashtable.put(szName, key); // create a button to switch the Viewer ON. Button button = new Button(szName); button.addActionListener(this); add(button); return vp2; }
From source file:SimpleGame.java
/** * Creates the duck. This loads the two duck geometries from the files * 'duck.obj' and 'deadduck.obj' and loads these into a switch. The access * rights to the switch are then set so we can write to this switch to swap * between the two duck models. It also creates a transform group and an * interpolator to move the duck./*from w ww . jav a 2 s .c o m*/ * * @return BranchGroup with content attached. */ protected BranchGroup buildDuck() { BranchGroup theDuck = new BranchGroup(); duckSwitch = new Switch(0); duckSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); ObjectFile f1 = new ObjectFile(); ObjectFile f2 = new ObjectFile(); Scene s1 = null; Scene s2 = null; try { s1 = f1.load("duck.obj"); s2 = f2.load("deadduck.obj"); } catch (Exception e) { System.exit(1); } TransformGroup duckRotXfmGrp = new TransformGroup(); Transform3D duckRotXfm = new Transform3D(); Matrix3d duckRotMat = new Matrix3d(); duckRotMat.rotY(Math.PI / 2); duckRotXfm.set(duckRotMat, new Vector3d(0.0, 0.0, -30.0), 1.0); duckRotXfmGrp.setTransform(duckRotXfm); duckRotXfmGrp.addChild(duckSwitch); duckSwitch.addChild(s1.getSceneGroup()); duckSwitch.addChild(s2.getSceneGroup()); TransformGroup duckMovXfmGrp = new TransformGroup(); duckMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); duckMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); duckMovXfmGrp.addChild(duckRotXfmGrp); duckAlpha = new Alpha(-1, 0, 0, 3000, 0, 0); Transform3D axis = new Transform3D(); PositionInterpolator moveDuck = new PositionInterpolator(duckAlpha, duckMovXfmGrp, axis, -30.0f, 30.0f); moveDuck.setSchedulingBounds(bounds); theDuck.addChild(moveDuck); theDuck.addChild(duckMovXfmGrp); return theDuck; }
From source file:SimpleCollision.java
/** * Creates the content branch of the scene graph. * //from w ww . j av a 2 s.c om * @return BranchGroup with content attached. */ protected BranchGroup buildContentBranch() { //First create a different appearance for each cube Appearance app1 = new Appearance(); Appearance app2 = new Appearance(); Appearance app3 = new Appearance(); Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f ambientColour3 = new Color3f(1.0f, 1.0f, 1.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); Color3f diffuseColour3 = new Color3f(1.0f, 1.0f, 1.0f); float shininess = 20.0f; app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess)); app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess)); app3.setMaterial(new Material(ambientColour3, emissiveColour, diffuseColour3, specularColour, shininess)); //Create the vertex data for the cube. Since each shape is //a cube we can use the same vertex data for each cube IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, cubeNormals); indexedCube.setCoordinateIndices(0, cubeCoordIndices); indexedCube.setNormalIndices(0, cubeNormalIndices); //Create the three cubes leftCube = new Shape3D(indexedCube, app1); rightCube = new Shape3D(indexedCube, app2); moveCube = new Shape3D(indexedCube, app3); //Define the user data so that we can print out the //name of the colliding cube. leftCube.setUserData(new String("left cube")); rightCube.setUserData(new String("right cube")); //Create the content branch and add the lights BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Create and set up the movable cube's TransformGroup. //This scales and translates the cube and then sets the // read, write and pick reporting capabilities. Transform3D moveXfm = new Transform3D(); moveXfm.set(0.7, new Vector3d(0.0, 2.0, 1.0)); moveGroup = new TransformGroup(moveXfm); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); //Create the left cube's TransformGroup Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); leftGroup = new TransformGroup(leftGroupXfm); //Create the right cube's TransformGroup Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); rightGroup = new TransformGroup(rightGroupXfm); //Add the behaviour to allow us to move the cube PickTranslateBehavior pickTranslate = new PickTranslateBehavior(contentBranch, myCanvas3D, bounds); contentBranch.addChild(pickTranslate); //Add our CollisionDetector class to detect collisions with //the movable cube. CollisionDetector myColDet = new CollisionDetector(moveCube, bounds); contentBranch.addChild(myColDet); //Create the content branch hierarchy. contentBranch.addChild(moveGroup); contentBranch.addChild(leftGroup); contentBranch.addChild(rightGroup); moveGroup.addChild(moveCube); leftGroup.addChild(leftCube); rightGroup.addChild(rightCube); return contentBranch; }
From source file:PickWorld.java
private Group createObject(int i, int j, Appearance app, double scale, double xpos, double ypos) { // Create a transform group node to scale and position the object. Transform3D t = new Transform3D(); t.set(scale, new Vector3d(xpos, ypos, 0.0)); TransformGroup objTrans = new TransformGroup(t); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING); // Create a second transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg = new TransformGroup(); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING); Primitive obj = null;//from www. ja v a2s .co m if (i % 3 == 2) { obj = (Primitive) new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, j * 8 + 4, app); } else if (i % 3 == 1) { obj = (Primitive) new Cylinder(1.0f, 2.0f, Cylinder.GENERATE_TEXTURE_COORDS | Cylinder.GENERATE_NORMALS, j * 8 + 4, j * 8 + 4, app); } else if (i % 3 == 0) { obj = (Primitive) new Cone(1.0f, 2.0f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, j * 8 + 4, j * 8 + 4, app); } // add it to the scene graph. spinTg.addChild(obj); objTrans.addChild(spinTg); return objTrans; }
From source file:ConicWorld.java
private Group createObject(int i, int j, Appearance app, double scale, double xpos, double ypos) { // Create a transform group node to scale and position the object. Transform3D t = new Transform3D(); t.set(scale, new Vector3d(xpos, ypos, 0.0)); TransformGroup objTrans = new TransformGroup(t); // Create a second transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg = new TransformGroup(); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Primitive obj = null;/* w ww . j av a2 s . c o m*/ if (i % 3 == 2) { obj = (Primitive) new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, j * 8 + 4, app); } else if (i % 3 == 1) { obj = (Primitive) new Cylinder(1.0f, 2.0f, Cylinder.GENERATE_TEXTURE_COORDS | Cylinder.GENERATE_NORMALS, j * 8 + 4, j * 8 + 4, app); } else if (i % 3 == 0) { obj = (Primitive) new Cone(1.0f, 2.0f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, j * 8 + 4, j * 8 + 4, app); } // add it to the scene graph. spinTg.addChild(obj); // 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, 5000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, spinTg, 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); // Add the behavior and the transform group to the object objTrans.addChild(rotator); objTrans.addChild(spinTg); return objTrans; }
From source file:TransformExplorer.java
TransformGroup createConeTransformGroup() { // create a TransformGroup for the cone, allow tranform changes, coneTG = new TransformGroup(); coneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); coneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // Set up an appearance to make the Cone with red ambient, // black emmissive, red diffuse and white specular coloring Material material = new Material(red, black, red, white, 64); // These are the colors used for the book figures: //Material material = new Material(white, black, white, black, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material);/*from www .j a v a 2s . co m*/ // create the cone and add it to the coneTG Cone cone = new Cone(coneRadius, coneHeight, appearance); coneTG.addChild(cone); return coneTG; }
From source file:SimpleCollision2.java
/** * Creates the content branch of the scene graph. * /*from www. j a va 2 s . co m*/ * @return BranchGroup with content attached. */ protected BranchGroup buildContentBranch() { //First create a different appearance for each cube Appearance app1 = new Appearance(); Appearance app2 = new Appearance(); Appearance app3 = new Appearance(); Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f); Color3f ambientColour3 = new Color3f(1.0f, 1.0f, 1.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); Color3f diffuseColour3 = new Color3f(1.0f, 1.0f, 1.0f); float shininess = 20.0f; app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess)); app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess)); app3.setMaterial(new Material(ambientColour3, emissiveColour, diffuseColour3, specularColour, shininess)); //Build the vertex array for the cubes. We can use the same //data for each cube so we just define one set of data IndexedQuadArray indexedCube = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f), new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f), new Vector3f(0.0f, -1.0f, 0.0f) }; int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 }; int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedCube.setCoordinates(0, cubeCoordinates); indexedCube.setNormals(0, cubeNormals); indexedCube.setCoordinateIndices(0, cubeCoordIndices); indexedCube.setNormalIndices(0, cubeNormalIndices); //Create the three cubes leftCube = new Shape3D(indexedCube, app1); rightCube = new Shape3D(indexedCube, app2); moveCube = new Shape3D(indexedCube, app3); //Define some user data so that we can print meaningful messages leftCube.setUserData(new String("left cube")); rightCube.setUserData(new String("right cube")); //Create the content branch and add the lights BranchGroup contentBranch = new BranchGroup(); addLights(contentBranch); //Set up the transform to position the left cube Transform3D leftGroupXfm = new Transform3D(); leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0)); leftGroup = new TransformGroup(leftGroupXfm); //Set up the transform to position the right cube Transform3D rightGroupXfm = new Transform3D(); rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0)); rightGroup = new TransformGroup(rightGroupXfm); //Create the movable cube's transform with a scale and //a translation. Set up the //capabilities so it can be moved by the behaviour Transform3D moveXfm = new Transform3D(); moveXfm.set(0.7, new Vector3d(0.0, 2.0, 1.0)); moveGroup = new TransformGroup(moveXfm); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); moveGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING); //Create the behaviour to move the movable cube PickTranslateBehavior pickTranslate = new PickTranslateBehavior(contentBranch, myCanvas3D, bounds); contentBranch.addChild(pickTranslate); //Create and add the two colision detectors CollisionDetector2 myColDetLeft = new CollisionDetector2(leftCube, bounds); contentBranch.addChild(myColDetLeft); CollisionDetector2 myColDetRight = new CollisionDetector2(rightCube, bounds); contentBranch.addChild(myColDetRight); //Set up the scene graph contentBranch.addChild(moveGroup); contentBranch.addChild(leftGroup); contentBranch.addChild(rightGroup); moveGroup.addChild(moveCube); leftGroup.addChild(leftCube); rightGroup.addChild(rightCube); return contentBranch; }
From source file:LineTypes.java
BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a TransformGroup to scale the scene down by 3.5x // TODO: move view platform instead of scene using orbit behavior TransformGroup objScale = new TransformGroup(); Transform3D scaleTrans = new Transform3D(); //scaleTrans.set(1 / 3.5f); // scale down by 3.5x objScale.setTransform(scaleTrans);/* w w w . j av a 2 s .c o m*/ objRoot.addChild(objScale); // Create a TransformGroup and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // the mouse behaviors 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); // Add the primitives to the scene objTrans.addChild(createLineTypes()); BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bg.setApplicationBounds(bounds); objTrans.addChild(bg); // set up the mouse rotation behavior MouseRotate mr = new MouseRotate(); mr.setTransformGroup(objTrans); mr.setSchedulingBounds(bounds); mr.setFactor(0.007); objTrans.addChild(mr); // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 1.0f); Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); return objRoot; }
From source file:GeometryByReferenceTest.java
BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); // Set up attributes to render lines app = new Appearance(); transp = new TransparencyAttributes(); transp.setTransparency(0.5f);//from w w w. j a v a 2s. co m transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transp.setTransparencyMode(TransparencyAttributes.NONE); app.setTransparencyAttributes(transp); tetraRegular = createGeometry(1); tetraStrip = createGeometry(2); tetraIndexed = createGeometry(3); tetraIndexedStrip = createGeometry(4); geoArrays[0] = tetraRegular; geoArrays[1] = tetraStrip; geoArrays[2] = tetraIndexed; geoArrays[3] = tetraIndexedStrip; shape = new Shape3D(tetraRegular, app); shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE); shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ); Transform3D t = new Transform3D(); // move the object upwards t.set(new Vector3f(0.0f, 0.3f, 0.0f)); // rotate the shape Transform3D temp = new Transform3D(); temp.rotX(Math.PI / 4.0d); t.mul(temp); temp.rotY(Math.PI / 4.0d); t.mul(temp); // Shrink the object t.setScale(0.6); TransformGroup trans = new TransformGroup(t); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRoot.addChild(trans); trans.addChild(shape); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }