List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
From source file:SimpleSpotLights.java
/** * This build the content branch of our scene graph. It creates a transform * group so that the shape is slightly tilted to reveal its 3D shape. * //from w ww. ja v a2 s . co m * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); //Create a new appearance Appearance app = new Appearance(); //Create the colours for the material Color3f ambientColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f diffuseColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f); Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f); //Define the shininess float shininess = 20.0f; //Set the material of the appearance app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); //Create and add a new sphere using the appearance rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app)); //Use the addLights function to add the lights to the branch addLights(contentBranch); //Return the root of the content branch return contentBranch; }
From source file:BillboardTest.java
private TransformGroup createBillboard(String szText, Point3f locationPoint, int nMode, Point3f billboardPoint, BoundingSphere bounds) {// w ww .jav a2s .c om 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:ExTransform.java
public Group buildScene() { // Turn on the headlight setHeadlightEnable(true);// w ww .j a v a 2s . co m // Build the scene root switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); // Create application bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent Transform3D t3d; Appearance app = new Appearance(); Material mat = new Material(); mat.setAmbientColor(0.2f, 0.8f, 0.4f); mat.setDiffuseColor(0.2f, 0.8f, 0.4f); mat.setSpecularColor(0.0f, 0.0f, 0.f); app.setMaterial(mat); // Build the 3D object: Box box = new Box(3.0f, 2.0f, 1.0f, app); // Build the shared object: sharedObject = new SharedGroup(); sharedObject.addChild(box); // Build 4 separate transforms: Transform3D id = new Transform3D(); TransformGroup idGroup = new TransformGroup(id); idGroup.addChild(new Link(sharedObject)); switchGroup.addChild(idGroup); Transform3D rot = new Transform3D(); rot.set(new AxisAngle4d(0., 1., 0., Math.PI / 4.)); TransformGroup rotGroup = new TransformGroup(rot); rotGroup.addChild(new Link(sharedObject)); switchGroup.addChild(rotGroup); Transform3D trans = new Transform3D(); trans.set(new Vector3d(2., 0., 0.)); TransformGroup transGroup = new TransformGroup(trans); transGroup.addChild(new Link(sharedObject)); switchGroup.addChild(transGroup); Transform3D scale = new Transform3D(); scale.set(2.0); TransformGroup scaleGroup = new TransformGroup(scale); scaleGroup.addChild(new Link(sharedObject)); switchGroup.addChild(scaleGroup); switchGroup.setWhichChild(options[currentSwitch].child); return switchGroup; }
From source file:FarbWurfelAsQuads.java
/** * Wurfeldarstellung//from w w w . j a v a 2s . c om * * @return Appearance */ private Appearance makeAppearance() { Appearance a = new Appearance(); PolygonAttributes p = new PolygonAttributes(); p.setCullFace(PolygonAttributes.CULL_NONE); a.setPolygonAttributes(p); return a; }
From source file:AvatarTest.java
public void createBackground(Group bg) { // add the sky backdrop Background back = new Background(); back.setApplicationBounds(getBoundingSphere()); bg.addChild(back);// ww w . j ava 2 s .c o m BranchGroup bgGeometry = new BranchGroup(); // create an appearance and assign the texture image Appearance app = new Appearance(); Texture tex = new TextureLoader("back.jpg", this).getTexture(); app.setTexture(tex); Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD, app); bgGeometry.addChild(sphere); back.setGeometry(bgGeometry); }
From source file:OrientedTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objScale = new TransformGroup(); Transform3D textMat = new Transform3D(); // Assuming uniform size chars, set scale to fit string in view textMat.setScale(1.2 / sl);// w ww. j a v a 2 s . c o m objScale.setTransform(textMat); // 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); objRoot.addChild(objTrans); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Appearance apText = new Appearance(); Material m = new Material(); m.setLightingEnable(true); apText.setMaterial(m); Appearance apEarth = new Appearance(); Material mm = new Material(); mm.setLightingEnable(true); apEarth.setMaterial(mm); Appearance apStone = new Appearance(); apStone.setMaterial(mm); // create 3D text Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion()); Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f)); OrientedShape3D textShape = new OrientedShape3D(); textShape.setGeometry(txt); textShape.setAppearance(apText); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); objScale.addChild(textShape); // Create a simple shape leaf node, add it to the scene graph. Transform3D cubeMat = new Transform3D(); TransformGroup cubeTrans = new TransformGroup(cubeMat); cubeMat.set(new Vector3d(0.9, 0.0, -1.0)); cubeTrans.setTransform(cubeMat); cubeTrans.addChild(new ColorCube(0.3)); objTrans.addChild(cubeTrans); TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this); if (stoneTex != null) apStone.setTexture(stoneTex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); apStone.setTextureAttributes(texAttr); Transform3D coneMat = new Transform3D(); TransformGroup coneTrans = new TransformGroup(coneMat); coneMat.set(new Vector3d(0.0, 0.0, 0.0)); coneTrans.setTransform(coneMat); coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone)); objTrans.addChild(coneTrans); TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this); if (earthTex != null) apEarth.setTexture(earthTex.getTexture()); apEarth.setTextureAttributes(texAttr); Transform3D cylinderMat = new Transform3D(); TransformGroup cylinderTrans = new TransformGroup(cylinderMat); cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0)); cylinderTrans.setTransform(cylinderMat); cylinderTrans.addChild( new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth)); objTrans.addChild(cylinderTrans); objTrans.addChild(objScale); // 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.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, 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); apText.setMaterial(mm); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleMorph2.java
/** * Build the content branch for the scene graph * /* w w w . j a va2 s. co m*/ * @return BranchGroup that is the root of the content */ protected BranchGroup buildContentBranch() { 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)); //Make the cube key shape 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); //Make the pyramid key shape. Although this needs //only five vertices to create the desired shape, we //need to use six vertices so that it has the same //number as the cube. IndexedQuadArray indexedPyramid = new IndexedQuadArray(8, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24); Point3f[] pyramidCoordinates = { new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) }; Vector3f[] pyramidNormals = { 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 pyramidCoordIndices[] = { 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 pyramidNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; indexedPyramid.setCoordinates(0, pyramidCoordinates); indexedPyramid.setNormals(0, pyramidNormals); indexedPyramid.setCoordinateIndices(0, pyramidCoordIndices); indexedPyramid.setNormalIndices(0, pyramidNormalIndices); //Set the contents of the array to the two shapes GeometryArray[] theShapes = new GeometryArray[2]; theShapes[0] = indexedCube; theShapes[1] = indexedPyramid; BranchGroup contentBranch = new BranchGroup(); //Create a transform to rotate the shape slightly Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); addLights(contentBranch); //Call the function to build the morph rotationGroup.addChild(createMorph(theShapes, app)); //Add the behaviour to the scene graph to activate it rotationGroup.addChild(myBehave); return contentBranch; }
From source file:BoundsTest.java
protected Group createPoints() { Group group = new Group(); final int kNumPoints = 200; final double kRadius = 10.0; Point3d points[] = new Point3d[kNumPoints]; for (int n = 0; n < kNumPoints; n++) { double randX = (java.lang.Math.random() * kRadius) - kRadius / 2; double randY = (java.lang.Math.random() * kRadius) - kRadius / 2; double randZ = (java.lang.Math.random() * kRadius) - kRadius / 2; points[n] = new Point3d(randX, randY, randZ); }//from ww w .j a va2s . c o m PointArray pointArray = new PointArray(points.length, GeometryArray.COLOR_4 | GeometryArray.COORDINATES); pointArray.setCoordinates(0, points); Shape3D shapePoints = new Shape3D(pointArray, new Appearance()); group.addChild(shapePoints); return group; }
From source file:BackgroundGeometry.java
public 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 av a 2 s. com*/ 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. TransformGroup objTrans = new TransformGroup(); objScale.addChild(objTrans); Background bg = new Background(); bg.setApplicationBounds(bounds); BranchGroup backGeoBranch = new BranchGroup(); Sphere sphereObj = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45); Appearance backgroundApp = sphereObj.getAppearance(); backGeoBranch.addChild(sphereObj); bg.setGeometry(backGeoBranch); objTrans.addChild(bg); TextureLoader tex = new TextureLoader(bgImage, new String("RGB"), this); if (tex != null) backgroundApp.setTexture(tex.getTexture()); Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f); Transform3D modelTransform = new Transform3D(); Transform3D tmpTransform = new Transform3D(); double angleInc = Math.PI / 8.0; double angle = 0.0; int numBoxes = 16; float scaleX[] = { 0.1f, 0.2f, 0.2f, 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f }; float scaleY[] = { 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.4f }; float scaleZ[] = { 0.3f, 0.2f, 0.1f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.2f }; Appearance a1 = new Appearance(); Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f); Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f); Material m = new Material(oColor, eColor, oColor, sColor, 100.0f); m.setLightingEnable(true); a1.setMaterial(m); for (int i = 0; i < numBoxes; i++, angle += angleInc) { modelTransform.rotY(angle); tmpTransform.set(tranlation); modelTransform.mul(tmpTransform); TransformGroup tgroup = new TransformGroup(modelTransform); objTrans.addChild(tgroup); tgroup.addChild(new Box(scaleX[i], scaleY[i], scaleZ[i], Box.GENERATE_NORMALS, a1)); } // Shine it with two lights. Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt1); objScale.addChild(lgt2); return objRoot; }
From source file:SimpleSwitch.java
/** * This creates the shapes used in the program. A switch node is created * that has its write capability set so that we can swap the rendered shape. * Then a box and a cone are created and added to the switch. * //from w w w . j a va 2s. co m * @return Node that is the switch node */ 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)); //Set the capability so that we can change the switch value firstSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); //Add the two shapes to the switch firstSwitch.addChild(new Box(2.0f, 2.0f, 2.0f, Box.GENERATE_NORMALS, app)); firstSwitch.addChild(new Cone(2.0f, 4.0f, Cone.GENERATE_NORMALS, app)); return firstSwitch; }