List of usage examples for javax.media.j3d Appearance setTexture
public void setTexture(Texture texture)
From source file:TextureByReference.java
public BranchGroup createSceneGraph() { // create the root of the branch group BranchGroup objRoot = new BranchGroup(); // create the transform group node and initialize it // enable the TRANSFORM_WRITE capability so that it can be modified // at runtime. Add it to the root of the subgraph Transform3D rotate = new Transform3D(); TransformGroup objTrans = new TransformGroup(rotate); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);/*from w ww .j a v a2 s . c om*/ // bounds BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // set up some light Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -0.5f, -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); Appearance appearance = new Appearance(); // enable the TEXTURE_WRITE so we can modify it at runtime appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE); // load the first texture TextureLoader loader = new TextureLoader(urls[0], TextureLoader.BY_REFERENCE | TextureLoader.Y_UP, this); // get the texture from the loader Texture2D tex = (Texture2D) loader.getTexture(); // get the BufferedImage to convert to TYPE_4BYTE_ABGR and flip // get the ImageComponent because we need it anyway ImageComponent2D imageComp = (ImageComponent2D) tex.getImage(0); BufferedImage bImage = imageComp.getImage(); // convert the image bImage = ImageOps.convertImage(bImage, BufferedImage.TYPE_4BYTE_ABGR); // flip the image ImageOps.flipImage(bImage); imageComp.set(bImage); tex.setCapability(Texture.ALLOW_IMAGE_WRITE); tex.setBoundaryModeS(Texture.CLAMP); tex.setBoundaryModeT(Texture.CLAMP); tex.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f); // set the image of the texture tex.setImage(0, imageComp); // set the texture on the appearance appearance.setTexture(tex); // set texture attributes TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); appearance.setTextureAttributes(texAttr); // set material properties Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); appearance.setMaterial(new Material(white, black, white, black, 1.0f)); // create a scale transform Transform3D scale = new Transform3D(); scale.set(.6); TransformGroup objScale = new TransformGroup(scale); objTrans.addChild(objScale); tetra = new Tetrahedron(true); tetra.setAppearance(appearance); objScale.addChild(tetra); // create the behavior animate = new AnimateTexturesBehavior(tex, urls, appearance, this); animate.setSchedulingBounds(bounds); objTrans.addChild(animate); // add a rotation behavior so we can see all sides of the tetrahedron Transform3D yAxis = new Transform3D(); Alpha rotorAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotorAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // have java3d perform optimizations on this scene graph objRoot.compile(); return objRoot; }
From source file:AppearanceTest.java
private Appearance createAppearance(int idx) { Appearance app = new Appearance(); // Globally used colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); switch (idx) { // Unlit solid case 0: {// w w w . ja va 2 s . c o m // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.2f, 0.4f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); break; } // Unlit wire frame case 1: { // Set up the coloring properties Color3f objColor = new Color3f(0.5f, 0.0f, 0.2f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_LINE); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); break; } // Unlit points case 2: { // Set up the coloring properties Color3f objColor = new Color3f(0.2f, 0.2f, 1.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_POINT); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up point attributes PointAttributes pta = new PointAttributes(); pta.setPointSize(5.0f); app.setPointAttributes(pta); break; } // Lit solid case 3: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 4: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); break; } // Transparent, lit solid case 5: { // Set up the transparency properties TransparencyAttributes ta = new TransparencyAttributes(); ta.setTransparencyMode(ta.BLENDED); ta.setTransparency(0.6f); app.setTransparencyAttributes(ta); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up the material properties Color3f objColor = new Color3f(0.7f, 0.8f, 1.0f); app.setMaterial(new Material(objColor, black, objColor, black, 1.0f)); break; } // Lit solid, no specular case 6: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); break; } // Lit solid, specular only case 7: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(black, black, black, white, 80.0f)); break; } // Another lit solid with a different color case 8: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } default: { ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f(0.0f, 1.0f, 0.0f)); app.setColoringAttributes(ca); } } return app; }
From source file:TickTockPicking.java
private Appearance createAppearance(int idx) { Appearance app = new Appearance(); // Globally used colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); switch (idx) { // Unlit solid case 0: {//from w w w .ja v a 2s . c om // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.2f, 0.4f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); break; } // Unlit wire frame case 1: { // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 0.4f, 0.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_LINE); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); break; } // Unlit points case 2: { // Set up the coloring properties Color3f objColor = new Color3f(1.0f, 1.0f, 0.0f); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(objColor); app.setColoringAttributes(ca); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setPolygonMode(pa.POLYGON_POINT); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up point attributes PointAttributes pta = new PointAttributes(); pta.setPointSize(5.0f); app.setPointAttributes(pta); break; } // Lit solid case 3: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 4: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); break; } // Transparent, lit solid case 5: { // Set up the transparency properties TransparencyAttributes ta = new TransparencyAttributes(); ta.setTransparencyMode(ta.BLENDED); ta.setTransparency(0.6f); app.setTransparencyAttributes(ta); // Set up the polygon attributes PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(pa.CULL_NONE); app.setPolygonAttributes(pa); // Set up the material properties Color3f objColor = new Color3f(0.7f, 0.8f, 1.0f); app.setMaterial(new Material(objColor, black, objColor, black, 1.0f)); break; } // Lit solid, no specular case 6: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); break; } // Lit solid, specular only case 7: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); app.setMaterial(new Material(black, black, black, white, 80.0f)); break; } // Another lit solid with a different color case 8: { // Set up the material properties Color3f objColor = new Color3f(0.8f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } default: { ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f(0.0f, 1.0f, 0.0f)); app.setColoringAttributes(ca); } } return app; }
From source file:Demo3D.java
/** * Construction of the desired borders of the virtual universe (cube). * // w w w .j a v a 2 s .c o m * @return javax.media.j3d.Shape3D myUniverse - the constructed borders of * the virtual universe */ public Shape3D myInternalUniverse() { cube = new QuadArray(cubeFaces.length, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); ////////////////////// Geometric part /////////////////////////// // Scaling of the faces. for (int i = 0; i < cubeFaces.length; i++) cubeFaces[i].scale(scale_XYZ); cube.setCoordinates(0, cubeFaces); for (int i = 0; i < cubeFaces.length; i++) { // With i mod 4 ==> 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 for // the 4 vertices of the 6 faces, thus each vertex has // a point in the texture space. In this case, each cube's // face has the same texture coordinates. cube.setTextureCoordinate(0, i, textCoord[i % 4]); } // The geometry is passed to the instance this of the cube. this.setGeometry(cube); ////////////////////// Appearance part /////////////////////////// Appearance appearance = new Appearance(); // This code block is only necessary to insure, in all cases, the // correct // rendering of the 6 faces of the cube (bug in Java3D version 1.2.0 !). // Set up the polygon's rendering-mode PolygonAttributes polygonAttributes = new PolygonAttributes(); polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL); appearance.setPolygonAttributes(polygonAttributes); // Loading the texture for the 6 cube's faces. newTextureLoader = new NewTextureLoader("Images/Galaxies.gif"); newTextureLoader.setImageObserver(newTextureLoader.getImageObserver()); texture = newTextureLoader.getTexture(); appearance.setTexture(texture); // Application modes of the texture textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.MODULATE); // there still are: // BLEND, COMBINE, // DECAL, and REPLACE appearance.setTextureAttributes(textAttr); // The appearance is passed to the instance this of the cube. this.setAppearance(appearance); return this; }
From source file:Demo3D.java
/** * Construction of the desired borders of the virtual universe (cube). * /* ww w . j a va 2 s. c o m*/ * @return javax.media.j3d.Shape3D myUniverse - the constructed borders of * the virtual universe */ public Shape3D myExternalUniverse() { cube = new QuadArray(cubeFaces.length, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2); ////////////////////// Geometric part /////////////////////////// // Scaling of the faces. for (int i = 0; i < cubeFaces.length; i++) cubeFaces[i].scale(scale_XYZ); cube.setCoordinates(0, cubeFaces); for (int i = 0; i < cubeFaces.length; i++) { // With i mod 4 ==> 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 for // the 4 vertices of the 6 faces, thus each vertex has // a point in the texture space. In this case, each cube's // face has the same texture coordinates. cube.setTextureCoordinate(0, i, textCoord[i % 4]); } // The geometry is passed to the instance this of the cube. this.setGeometry(cube); ////////////////////// Appearance part /////////////////////////// Appearance appearance = new Appearance(); // This code block is only necessary to insure, in all cases, the // correct // rendering of the 6 faces of the cube (bug in Java3D version 1.2.0 !). // Set up the polygon's rendering-mode PolygonAttributes polygonAttributes = new PolygonAttributes(); polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL); appearance.setPolygonAttributes(polygonAttributes); // Loading the texture for the 6 cube's faces. newTextureLoader = new NewTextureLoader("Images/Ciel_Outside.jpg"); newTextureLoader.setImageObserver(newTextureLoader.getImageObserver()); texture = newTextureLoader.getTexture(); appearance.setTexture(texture); // Application modes of the texture textAttr = new TextureAttributes(); textAttr.setTextureMode(TextureAttributes.MODULATE); // there still are: // BLEND, COMBINE, // DECAL, and REPLACE appearance.setTextureAttributes(textAttr); // The appearance is passed to the instance this of the cube. this.setAppearance(appearance); return this; }
From source file:AppearanceExplorer.java
BackgroundTool(String codeBaseString) { bgSwitch = new Switch(Switch.CHILD_NONE); bgSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // set up the dark grey BG color node Background bgDarkGrey = new Background(darkGrey); bgDarkGrey.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgDarkGrey);/*from ww w. ja va 2s. c o m*/ // set up the grey BG color node Background bgGrey = new Background(grey); bgGrey.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgGrey); // set up the light grey BG color node Background bgLightGrey = new Background(lightGrey); bgLightGrey.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgLightGrey); // set up the white BG color node Background bgWhite = new Background(white); bgWhite.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgWhite); // set up the blue BG color node Background bgBlue = new Background(skyBlue); bgBlue.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgBlue); // set up the image java.net.URL bgImageURL = null; try { bgImageURL = new java.net.URL(codeBaseString + "bg.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } if (bgImageURL == null) { // application, try file URL try { bgImageURL = new java.net.URL("file:./bg.jpg"); } catch (java.net.MalformedURLException ex) { System.out.println(ex.getMessage()); System.exit(1); } } TextureLoader bgTexture = new TextureLoader(bgImageURL, null); // Create a background with the static image Background bgImage = new Background(bgTexture.getImage()); bgImage.setApplicationBounds(infiniteBounds); bgSwitch.addChild(bgImage); // create a background with the image mapped onto a sphere which // will enclose the world Background bgGeo = new Background(); bgGeo.setApplicationBounds(infiniteBounds); BranchGroup bgGeoBG = new BranchGroup(); Appearance bgGeoApp = new Appearance(); bgGeoApp.setTexture(bgTexture.getTexture()); Sphere sphereObj = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45, bgGeoApp); bgGeoBG.addChild(sphereObj); bgGeo.setGeometry(bgGeoBG); bgSwitch.addChild(bgGeo); // Create the chooser GUI String[] bgNames = { "No Background (Black)", "Dark Grey", "Grey", "Light Grey", "White", "Blue", "Sky Image", "Sky Geometry", }; int[] bgValues = { Switch.CHILD_NONE, 0, 1, 2, 3, 4, 5, 6 }; bgChooser = new IntChooser("Background:", bgNames, bgValues, 0); bgChooser.addIntListener(new IntListener() { public void intChanged(IntEvent event) { int value = event.getValue(); bgSwitch.setWhichChild(value); } }); bgChooser.setValue(Switch.CHILD_NONE); }
From source file:SplineInterpolatorTest.java
protected Background createBackground() { // add the sky backdrop Background back = new Background(); back.setApplicationBounds(getApplicationBounds()); BranchGroup bgGeometry = new BranchGroup(); // create an appearance and assign the texture image Appearance app = new Appearance(); Texture tex = new TextureLoader("sky.gif", this).getTexture(); app.setTexture(tex); Sphere sphere = new Sphere(1.0f, Primitive.GENERATE_TEXTURE_COORDS | Primitive.GENERATE_NORMALS_INWARD, app);/*w w w.ja v a 2s. c om*/ bgGeometry.addChild(sphere); back.setGeometry(bgGeometry); return back; }
From source file:ExBackgroundImage.java
public TowerScene(Component observer) { BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add a few lights AmbientLight ambient = new AmbientLight(); ambient.setEnable(true);/*from w w w . j av a2s .c o m*/ ambient.setColor(new Color3f(0.2f, 0.2f, 0.2f)); ambient.setInfluencingBounds(worldBounds); addChild(ambient); DirectionalLight dir1 = new DirectionalLight(); dir1.setEnable(true); dir1.setColor(new Color3f(1.0f, 0.15f, 0.15f)); dir1.setDirection(new Vector3f(0.8f, -0.35f, -0.5f)); dir1.setInfluencingBounds(worldBounds); addChild(dir1); DirectionalLight dir2 = new DirectionalLight(); dir2.setEnable(true); dir2.setColor(new Color3f(0.15f, 0.15f, 1.0f)); dir2.setDirection(new Vector3f(-0.7f, -0.35f, 0.5f)); dir2.setInfluencingBounds(worldBounds); addChild(dir2); // Load textures TextureLoader texLoader = new TextureLoader("moon5.jpg", observer); Texture moon = texLoader.getTexture(); if (moon == null) System.err.println("Cannot load moon5.jpg texture"); else { moon.setBoundaryModeS(Texture.WRAP); moon.setBoundaryModeT(Texture.WRAP); moon.setMinFilter(Texture.NICEST); moon.setMagFilter(Texture.NICEST); moon.setMipMapMode(Texture.BASE_LEVEL); moon.setEnable(true); } texLoader = new TextureLoader("stonebrk2.jpg", observer); Texture stone = texLoader.getTexture(); if (stone == null) System.err.println("Cannot load stonebrk2.jpg texture"); else { stone.setBoundaryModeS(Texture.WRAP); stone.setBoundaryModeT(Texture.WRAP); stone.setMinFilter(Texture.NICEST); stone.setMagFilter(Texture.NICEST); stone.setMipMapMode(Texture.BASE_LEVEL); stone.setEnable(true); } // // Build a rough terrain // Appearance moonApp = new Appearance(); Material moonMat = new Material(); moonMat.setAmbientColor(0.5f, 0.5f, 0.5f); moonMat.setDiffuseColor(1.0f, 1.0f, 1.0f); moonMat.setSpecularColor(0.0f, 0.0f, 0.0f); moonApp.setMaterial(moonMat); TextureAttributes moonTexAtt = new TextureAttributes(); moonTexAtt.setTextureMode(TextureAttributes.MODULATE); moonTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); moonApp.setTextureAttributes(moonTexAtt); if (moon != null) moonApp.setTexture(moon); CraterGrid grid = new CraterGrid(50, 50, // grid dimensions 1.0, 1.0, // grid spacing 4.0, // height exageration factor craters, // grid elevations moonApp); // grid appearance addChild(grid); // // Build several towers on the terrain // SharedGroup tower = new SharedGroup(); Appearance towerApp = new Appearance(); Material towerMat = new Material(); towerMat.setAmbientColor(0.6f, 0.6f, 0.6f); towerMat.setDiffuseColor(1.0f, 1.0f, 1.0f); towerMat.setSpecularColor(0.0f, 0.0f, 0.0f); towerApp.setMaterial(towerMat); Transform3D tr = new Transform3D(); tr.setScale(new Vector3d(4.0, 4.0, 1.0)); TextureAttributes towerTexAtt = new TextureAttributes(); towerTexAtt.setTextureMode(TextureAttributes.MODULATE); towerTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); towerTexAtt.setTextureTransform(tr); towerApp.setTextureAttributes(towerTexAtt); if (stone != null) towerApp.setTexture(stone); Arch towerShape = new Arch(0.0, // start Phi 1.571, // end Phi 2, // nPhi 0.0, // start Theta Math.PI * 2.0, // end Theta 5, // nTheta 3.0, // start radius 8.0, // end radius 0.0, // start phi thickness 0.0, // end phi thickness towerApp); // appearance tower.addChild(towerShape); // Place towers Matrix3f rot = new Matrix3f(); rot.setIdentity(); TransformGroup tg = new TransformGroup(new Transform3D(rot, new Vector3d(2.0, -3.0, -8.0), 1.0)); tg.addChild(new Link(tower)); addChild(tg); tg = new TransformGroup(new Transform3D(rot, new Vector3d(-1.0, -3.0, -6.0), 0.5)); tg.addChild(new Link(tower)); addChild(tg); tg = new TransformGroup(new Transform3D(rot, new Vector3d(5.0, -3.0, -6.0), 0.75)); tg.addChild(new Link(tower)); addChild(tg); tg = new TransformGroup(new Transform3D(rot, new Vector3d(1.0, -3.0, -3.0), 0.35)); tg.addChild(new Link(tower)); addChild(tg); }
From source file:ExSwitch.java
public Group buildScene() { // Turn on the example headlight setHeadlightEnable(true);// www. ja v a 2 s . c o m // Default to walk navigation setNavigationType(Walk); // Build the scene group Group scene = new Group(); if (debug) System.err.println(" switch shapes..."); // BEGIN EXAMPLE TOPIC // Build the switch group and allow its switch // value to be changed via menu items swtch = new Switch(); swtch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Create several shapes to place in a switch group // Child 0: a red sphere Appearance app0 = new Appearance(); Material mat0 = new Material(); mat0.setAmbientColor(0.2f, 0.2f, 0.2f); mat0.setDiffuseColor(1.0f, 0.0f, 0.2f); mat0.setSpecularColor(0.7f, 0.7f, 0.7f); app0.setMaterial(mat0); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3f(-2.0f, 1.5f, 0.0f)); TransformGroup tg0 = new TransformGroup(t3d); Sphere sph0 = new Sphere(0.5f, // radius Primitive.GENERATE_NORMALS, // components 16, // facets app0); // appearance tg0.addChild(sph0); swtch.addChild(tg0); // Child 0 // Child 1: a green sphere Appearance app1 = new Appearance(); Material mat1 = new Material(); mat1.setAmbientColor(0.2f, 0.2f, 0.2f); mat1.setDiffuseColor(0.0f, 1.0f, 0.0f); mat1.setSpecularColor(0.7f, 0.7f, 0.7f); app1.setMaterial(mat1); t3d.setTranslation(new Vector3f(0.0f, 1.5f, 0.0f)); TransformGroup tg1 = new TransformGroup(t3d); Sphere sph1 = new Sphere(0.5f, // radius Primitive.GENERATE_NORMALS, // components 16, // facets app1); // appearance tg1.addChild(sph1); swtch.addChild(tg1); // Child 1 // Child 2: a blue sphere Appearance app2 = new Appearance(); Material mat2 = new Material(); mat2.setAmbientColor(0.2f, 0.2f, 0.2f); mat2.setDiffuseColor(0.0f, 0.6f, 1.0f); mat2.setSpecularColor(0.7f, 0.7f, 0.7f); app2.setMaterial(mat2); t3d.setTranslation(new Vector3f(2.0f, 1.5f, 0.0f)); TransformGroup tg2 = new TransformGroup(t3d); Sphere sph2 = new Sphere(0.5f, // radius Primitive.GENERATE_NORMALS, // components 16, // facets app2); // appearance tg2.addChild(sph2); swtch.addChild(tg2); // Set the initial child choice swtch.setWhichChild(options[currentSwitch].child); scene.addChild(swtch); // END EXAMPLE TOPIC // Build foreground geometry including a floor and // columns on which the switchable shapes stand // Load textures TextureLoader texLoader = new TextureLoader("granite07rev.jpg", this); Texture columnTex = texLoader.getTexture(); if (columnTex == null) System.err.println("Cannot load granite07rev.jpg texture"); else { columnTex.setBoundaryModeS(Texture.WRAP); columnTex.setBoundaryModeT(Texture.WRAP); columnTex.setMinFilter(Texture.NICEST); columnTex.setMagFilter(Texture.NICEST); columnTex.setMipMapMode(Texture.BASE_LEVEL); columnTex.setEnable(true); } texLoader = new TextureLoader("flooring.jpg", this); Texture groundTex = texLoader.getTexture(); if (groundTex == null) System.err.println("Cannot load flooring.jpg texture"); else { groundTex.setBoundaryModeS(Texture.WRAP); groundTex.setBoundaryModeT(Texture.WRAP); groundTex.setMinFilter(Texture.NICEST); groundTex.setMagFilter(Texture.NICEST); groundTex.setMipMapMode(Texture.BASE_LEVEL); groundTex.setEnable(true); } // // Build several columns on the floor // if (debug) System.err.println(" columns..."); SharedGroup column = new SharedGroup(); Appearance columnApp = new Appearance(); Material columnMat = new Material(); columnMat.setAmbientColor(0.6f, 0.6f, 0.6f); columnMat.setDiffuseColor(1.0f, 1.0f, 1.0f); columnMat.setSpecularColor(0.0f, 0.0f, 0.0f); columnApp.setMaterial(columnMat); TextureAttributes columnTexAtt = new TextureAttributes(); columnTexAtt.setTextureMode(TextureAttributes.MODULATE); columnTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); columnApp.setTextureAttributes(columnTexAtt); if (columnTex != null) columnApp.setTexture(columnTex); GothicColumn columnShape = new GothicColumn(1.8f, // height 0.25f, // radius GothicColumn.BUILD_TOP, // flags columnApp); // appearance column.addChild(columnShape); Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg; // Left trans.set(-2.0f, -1.0f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); scene.addChild(tg); // Middle trans.set(0.0f, -1.0f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); scene.addChild(tg); // Right trans.set(2.0f, -1.0f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); scene.addChild(tg); // // Add the ground // if (debug) System.err.println(" ground..."); Appearance groundApp = new Appearance(); Material groundMat = new Material(); groundMat.setAmbientColor(0.6f, 0.6f, 0.6f); groundMat.setDiffuseColor(1.0f, 1.0f, 1.0f); groundMat.setSpecularColor(0.0f, 0.0f, 0.0f); groundApp.setMaterial(groundMat); tr = new Transform3D(); tr.setScale(new Vector3d(4.0, 4.0, 1.0)); TextureAttributes groundTexAtt = new TextureAttributes(); groundTexAtt.setTextureMode(TextureAttributes.MODULATE); groundTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); groundTexAtt.setTextureTransform(tr); groundApp.setTextureAttributes(groundTexAtt); if (groundTex != null) groundApp.setTexture(groundTex); ElevationGrid ground = new ElevationGrid(11, // X dimension 11, // Z dimension 2.0f, // X spacing 2.0f, // Z spacing // Automatically use zero heights groundApp); // Appearance trans.set(0.0f, -1.0f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(ground); scene.addChild(tg); // Add a light BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent DirectionalLight light = new DirectionalLight(); light.setEnable(true); light.setColor(new Color3f(1.0f, 1.0f, 1.0f)); light.setDirection(new Vector3f(0.5f, -1.0f, -0.5f)); light.setInfluencingBounds(worldBounds); scene.addChild(light); return scene; }
From source file:ExLinearFog.java
private SharedGroup buildSharedColumn() { Appearance columnApp = new Appearance(); Material columnMat = new Material(); columnMat.setAmbientColor(0.6f, 0.6f, 0.6f); columnMat.setDiffuseColor(1.0f, 1.0f, 1.0f); columnMat.setSpecularColor(0.0f, 0.0f, 0.0f); columnApp.setMaterial(columnMat);/*from www .jav a2s . c om*/ TextureAttributes columnTexAtt = new TextureAttributes(); columnTexAtt.setTextureMode(TextureAttributes.MODULATE); columnTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); columnApp.setTextureAttributes(columnTexAtt); if (columnTex != null) columnApp.setTexture(columnTex); GothicColumn columnShape = new GothicColumn(ColumnHeight, // height ColumnRadius, // radius GothicColumn.BUILD_TOP, // flags columnApp); // appearance // BEGIN EXAMPLE TOPIC // Build a shared group to hold the column shape SharedGroup column = new SharedGroup(); column.addChild(columnShape); // END EXAMPLE TOPIC return column; }