List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
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);/*from w w w . j a v a2 s . c o m*/ // triangulate the polygon GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(m_VertexArray); 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:SimpleWorld.java
/** * This constructs a cube as an array of quadrilateral polygons. There are * six faces, each with four vertices (obviously!). The cube extends 1 unit * along each axis in the positive and negavtive directions and is centred * on the origin./*from ww w.ja v a 2 s . co m*/ * * @return Shape3D that is the cube */ protected Shape3D buildCube() { //Create the array of numbers that will form the //vertex information. float[] cubeFaces = { 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f }; //Create the array of quadrilaterals from the vertices QuadArray cubeData = new QuadArray(24, QuadArray.COORDINATES); cubeData.setCoordinates(0, cubeFaces); //Create a default appearance Appearance app = new Appearance(); //Create and return the cube return new Shape3D(cubeData, app); }
From source file:CuboidTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); 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);//from www .ja va2 s . c o m // 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); objTrans.addChild(new Cuboid(50, 30, 20, ap)); objTrans.addChild(new Box(25, 15, 10, ap)); objRoot.addChild(objTrans); return objRoot; }
From source file:ScenegraphTest.java
private void addHead(Group parentGroup) { // add a cylinder for the Neck TransformGroup tgNeck = addLimb(parentGroup, "Neck", 0.05, 0.2, 0.0, 0.0); 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)); // position a Sphere for the head itself Sphere headSphere = new Sphere((float) 0.12, Primitive.GENERATE_NORMALS, app); tgNeck.addChild(headSphere);// w ww.j ava2 s.c om }
From source file:LightBug.java
void setupSpheres() { // create a Switch for the spheres, allow switch changes spheresSwitch = new Switch(Switch.CHILD_ALL); spheresSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Set up an appearance to make the Sphere with red ambient, // black emmissive, red diffuse and white specular coloring Material material = new Material(red, black, red, white, 64); Appearance appearance = new Appearance(); appearance.setMaterial(material);/*from ww w . j a v a 2 s.c om*/ // create a sphere and put it into a shared group Sphere sphere = new Sphere(0.5f, appearance); SharedGroup sphereSG = new SharedGroup(); sphereSG.addChild(sphere); // create a grid of spheres in the z=0 plane // each has a TransformGroup to position the sphere which contains // a link to the shared group for the sphere for (int y = -2; y <= 2; y++) { for (int x = -2; x <= 2; x++) { TransformGroup tg = new TransformGroup(); tmpVector.set(x * 1.2f, y * 1.2f, 0.0f); tmpTrans.set(tmpVector); tg.setTransform(tmpTrans); tg.addChild(new Link(sphereSG)); spheresSwitch.addChild(tg); } } }
From source file:Pyramid2Cube.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);/*ww w . ja v a2s. c om*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behavior 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); // // 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 rotY15 = new Transform3D(); rotY15.rotY(15.0 * Math.PI / 180.0); objTrans[0].getTransform(tr); tr.setTranslation(new Vector3d(-3.0, 1.5, -6.5)); tr.mul(rotY15); objTrans[0].setTransform(tr); objTrans[1].getTransform(tr); tr.setTranslation(new Vector3d(0.0, 1.5, -6.5)); tr.mul(rotY15); objTrans[1].setTransform(tr); objTrans[2].getTransform(tr); tr.setTranslation(new Vector3d(3.0, 1.5, -6.5)); tr.mul(rotY15); objTrans[2].setTransform(tr); objTrans[3].getTransform(tr); tr.setTranslation(new Vector3d(0.0, -2.0, -5.0)); tr.mul(rotY15); objTrans[3].setTransform(tr); // Now create simple geometries. QuadArray g[] = new QuadArray[3]; Shape3D shape[] = new Shape3D[3]; for (int i = 0; i < 3; i++) { g[i] = null; shape[i] = null; } g[0] = new ColorPyramidUp(); g[1] = new ColorCube(); g[2] = new ColorPyramidDown(); Appearance a = new Appearance(); for (int i = 0; i < 3; i++) { shape[i] = new Shape3D(g[i], a); objTrans[i].addChild(shape[i]); } // // 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. // Morph morph = new Morph((GeometryArray[]) g, a); 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, 4000, 1000, 500, 4000, 1000, 500); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objScale.addChild(mBeh); return objRoot; }
From source file:SimpleTransform.java
/** * This defines the shapes used in the scene. It creates a simple cube using * a Box utility class.//from ww w. j a va2 s . c o m * * @return Node that is the root of the shape hierarchy. */ protected Node buildShape() { Appearance app = new Appearance(); Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f); float shininess = 20.0f; app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); return new Box(2.0f, 2.0f, 2.0f, app); }
From source file:Text3DTest.java
TransformGroup createText3D(TornadoRotation rotator, String szText, int nSize, float scale, float trans, int nPath) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(scale);/*from ww w.j ava 2 s. c o m*/ t3d.setTranslation(new Vector3d(0.0, trans, -10.0)); tg.setTransform(t3d); // use a customized FontExtrusion object to control the depth of the // text double X1 = 0; double Y1 = 0; double X2 = 3; double Y2 = 0; Shape extrusionShape = new java.awt.geom.Line2D.Double(X1, Y1, X2, Y2); FontExtrusion fontEx = new FontExtrusion(extrusionShape); Font3D f3d = new Font3D(new Font("TimesRoman", Font.PLAIN, nSize), fontEx); TornadoText3D text3D = new TornadoText3D(f3d, szText, new Point3f(0.0f, 0.0f, 0.0f), Text3D.ALIGN_CENTER, nPath); rotator.addTornadoText3D(text3D); // create an appearance Color3f black = new Color3f(0.1f, 0.1f, 0.1f); Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f); Appearance app = new Appearance(); app.setMaterial(new Material(objColor, black, objColor, black, 90.0f)); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); app.setPolygonAttributes(polyAttrbutes); tg.addChild(new Shape3D(text3D, app)); return tg; }
From source file:SimpleGame.java
/** * This builds the gun geometry. It uses box and cylinder primitives and * sets up a transform group so that we can rotate the gun. *//*www . j a v a 2s . c o m*/ protected BranchGroup buildGun() { BranchGroup theGun = new BranchGroup(); Appearance gunApp = new Appearance(); Color3f ambientColour = new Color3f(0.5f, 0.5f, 0.5f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(0.5f, 0.5f, 0.5f); float shininess = 20.0f; gunApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); TransformGroup init = new TransformGroup(); TransformGroup barrel = new TransformGroup(); Transform3D gunXfm = new Transform3D(); Transform3D barrelXfm = new Transform3D(); barrelXfm.set(new Vector3d(0.0, -2.0, 0.0)); barrel.setTransform(barrelXfm); Matrix3d gunXfmMat = new Matrix3d(); gunXfmMat.rotX(Math.PI / 2); gunXfm.set(gunXfmMat, new Vector3d(0.0, 0.0, 0.0), 1.0); init.setTransform(gunXfm); gunXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); gunXfmGrp.addChild(new Box(1.0f, 1.0f, 0.5f, gunApp)); barrel.addChild(new Cylinder(0.3f, 4.0f, gunApp)); gunXfmGrp.addChild(barrel); theGun.addChild(init); init.addChild(gunXfmGrp); return theGun; }
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 www.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; }