List of usage examples for javax.media.j3d TextureAttributes MODULATE
int MODULATE
To view the source code for javax.media.j3d TextureAttributes MODULATE.
Click Source Link
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: {//w w w. ja v a2s. 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(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:ExSound.java
private Group buildForeground() { ///* www. j a v a 2s . c o m*/ // Create a group for the foreground, and move // everything up a bit. // TransformGroup group = new TransformGroup(); Transform3D tr = new Transform3D(); tr.setTranslation(new Vector3f(0.0f, -1.6f, 0.0f)); group.setTransform(tr); // // Load textures // if (debug) System.err.println(" textures..."); Texture groundTex = null; Texture spurTex = null; Texture domeTex = null; TextureLoader texLoader = null; ImageComponent image = null; texLoader = new TextureLoader("flooring.jpg", this); image = texLoader.getImage(); if (image == null) System.err.println("Cannot load flooring.jpg texture"); else { groundTex = texLoader.getTexture(); groundTex.setBoundaryModeS(Texture.WRAP); groundTex.setBoundaryModeT(Texture.WRAP); groundTex.setMinFilter(Texture.NICEST); groundTex.setMagFilter(Texture.NICEST); groundTex.setMipMapMode(Texture.BASE_LEVEL); groundTex.setEnable(true); } 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("brtsky.jpg", this); Texture boxTex = texLoader.getTexture(); if (boxTex == null) System.err.println("Cannot load brtsky.jpg texture"); else { boxTex.setBoundaryModeS(Texture.WRAP); boxTex.setBoundaryModeT(Texture.WRAP); boxTex.setMinFilter(Texture.NICEST); boxTex.setMagFilter(Texture.NICEST); boxTex.setMipMapMode(Texture.BASE_LEVEL); boxTex.setEnable(true); } // // Build the ground // if (debug) System.err.println(" ground..."); Appearance groundApp = new Appearance(); Material groundMat = new Material(); groundMat.setAmbientColor(0.3f, 0.3f, 0.3f); groundMat.setDiffuseColor(0.7f, 0.7f, 0.7f); groundMat.setSpecularColor(0.0f, 0.0f, 0.0f); groundApp.setMaterial(groundMat); tr = new Transform3D(); tr.setScale(new Vector3d(16.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 group.addChild(ground); // // Create a column appearance used for both columns. // 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); // // To give the point sound an apparent location, // build a column and a set of three co-located // tumbling boxes hovering above the column. // TransformGroup pointGroup = new TransformGroup(); tr.setIdentity(); tr.setTranslation(new Vector3f(pointX, 0.0f, 0.0f)); pointGroup.setTransform(tr); GothicColumn column = new GothicColumn(1.0f, // height 0.2f, // radius GothicColumn.BUILD_TOP, // flags columnApp); // appearance pointGroup.addChild(column); TransformGroup rotThing = new TransformGroup(); tr.setIdentity(); tr.setTranslation(new Vector3f(0.0f, soundHeight, 0.0f)); rotThing.setTransform(tr); Appearance boxApp = new Appearance(); // No material -- make it emissive TextureAttributes boxTexAtt = new TextureAttributes(); boxTexAtt.setTextureMode(TextureAttributes.REPLACE); boxTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); boxApp.setTextureAttributes(boxTexAtt); if (boxTex != null) boxApp.setTexture(boxTex); rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height, // depth boxApp, // Appearance 40000, 32000, 26000));// XYZ tumble durations rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height, // depth boxApp, // Appearance 38000, 30000, 28000));// XYZ tumble durations rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height, // depth boxApp, // Appearance 30000, 26000, 34000));// XYZ tumble durations pointGroup.addChild(rotThing); group.addChild(pointGroup); return group; }
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 ava 2 s .co 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: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 w w w .j a v a2 s .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; }
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 w w .j av a 2s .co m // 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:ExLinearFog.java
public ColumnScene(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);/* w w w .ja va 2s .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, 1.0f, 1.0f)); 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.75f, 0.75f, 1.0f)); dir2.setDirection(new Vector3f(-0.7f, -0.35f, -0.5f)); dir2.setInfluencingBounds(worldBounds); addChild(dir2); // Load textures TextureLoader texLoader = new TextureLoader("grass06.jpg", observer); Texture grassTex = texLoader.getTexture(); if (grassTex == null) System.err.println("Cannot load grass06.jpg texture"); else { grassTex.setBoundaryModeS(Texture.WRAP); grassTex.setBoundaryModeT(Texture.WRAP); grassTex.setMinFilter(Texture.NICEST); grassTex.setMagFilter(Texture.NICEST); grassTex.setMipMapMode(Texture.BASE_LEVEL); grassTex.setEnable(true); } texLoader = new TextureLoader("marble10.jpg", observer); Texture walkTex = texLoader.getTexture(); if (walkTex == null) System.err.println("Cannot load marble10.jpg texture"); else { walkTex.setBoundaryModeS(Texture.WRAP); walkTex.setBoundaryModeT(Texture.WRAP); walkTex.setMinFilter(Texture.NICEST); walkTex.setMagFilter(Texture.NICEST); walkTex.setMipMapMode(Texture.BASE_LEVEL); walkTex.setEnable(true); } texLoader = new TextureLoader("granite07rev.jpg", observer); 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); } // // Build the ground // +-----+---+-----+ // | | | | // | G | W | G | // | | | | // +-----+---+-----+ // // where "G" is grass, and "W" is a walkway between columns // Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg; // Walkway appearance Appearance walkApp = new Appearance(); Material walkMat = new Material(); walkMat.setAmbientColor(0.5f, 0.5f, 0.5f); walkMat.setDiffuseColor(1.0f, 1.0f, 1.0f); walkMat.setSpecularColor(0.0f, 0.0f, 0.0f); walkApp.setMaterial(walkMat); TextureAttributes walkTexAtt = new TextureAttributes(); walkTexAtt.setTextureMode(TextureAttributes.MODULATE); walkTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(1.0, 6.0, 1.0)); walkTexAtt.setTextureTransform(tr); walkApp.setTextureAttributes(walkTexAtt); if (walkTex != null) walkApp.setTexture(walkTex); // Grass appearance Appearance grassApp = new Appearance(); Material grassMat = new Material(); grassMat.setAmbientColor(0.5f, 0.5f, 0.5f); grassMat.setDiffuseColor(1.0f, 1.0f, 1.0f); grassMat.setSpecularColor(0.0f, 0.0f, 0.0f); grassApp.setMaterial(grassMat); TextureAttributes grassTexAtt = new TextureAttributes(); grassTexAtt.setTextureMode(TextureAttributes.MODULATE); grassTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(2.0, 8.0, 1.0)); grassTexAtt.setTextureTransform(tr); grassApp.setTextureAttributes(grassTexAtt); if (grassTex != null) grassApp.setTexture(grassTex); // Left grass trans.set(-LawnWidth / 2.0f - WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass1 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass1); addChild(tg); // Right grass trans.set(LawnWidth / 2.0f + WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass2 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass2); addChild(tg); // Walkway trans.set(0.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid walk = new ElevationGrid(2, // X dimension 2, // Z dimension WalkwayWidth, // X spacing WalkwayDepth, // Z spacing walkApp); // appearance tg.addChild(walk); addChild(tg); // // Build several columns on the floor // SharedGroup column = buildSharedColumn(); Group columns = buildColumns(column); addChild(columns); }
From source file:AppearanceTest.java
public void onMODULATE() { getTextureAttributes().setTextureMode(TextureAttributes.MODULATE); }
From source file:Demo3D.java
/** * Construction of the desired borders of the virtual universe (cube). * /*from ww w . ja va2 s . co 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). * // w ww .ja v a 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:Demo3D.java
/** * Construction of the desired tetrahedron. * /* w ww . ja v a 2 s .c om*/ * @return javax.media.j3d.Shape3D myTetrahedron - the constructed * tetrahedron */ public Shape3D myTetrahedron() { ////////////////////// Geometric part /////////////////////////// // The 4 vertices p0, p1, p2 and p3 of the tetrahedron. vertices = new Point3f[lengthVertices]; // 4 vertices[0] = new Point3f(0.0f, 0.0f, 0.0f); vertices[1] = new Point3f(1.0f, 0.0f, 0.0f); vertices[2] = new Point3f(0.0f, 1.0f, 0.0f); vertices[3] = new Point3f(0.0f, 0.0f, 1.0f); // Scaling of vertices for (int i = 0; i < lengthVertices; i++) // lengthVertices = 4 vertices[i].scale(scale_XYZ); // Set the face's indices for the tetrahedron (referenced to the array // of vertices // by setCoordinates(vertices) and // setCoordinateIndices(tetraFaceIndices)). tetraFaceIndices = new int[lengthTetraFaceIndices]; // 12 // From the camera in the view coordinate system // bottom tetraFaceIndices[0] = 0; tetraFaceIndices[1] = 1; tetraFaceIndices[2] = 3; // back-left face tetraFaceIndices[3] = 0; tetraFaceIndices[4] = 3; tetraFaceIndices[5] = 2; // back face tetraFaceIndices[6] = 0; tetraFaceIndices[7] = 2; tetraFaceIndices[8] = 1; // front face tetraFaceIndices[9] = 1; tetraFaceIndices[10] = 2; tetraFaceIndices[11] = 3; // Create the GeometryInfo instance and set the vertices tetra_GeometryInfo = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY); tetra_GeometryInfo.setCoordinates(vertices); tetra_GeometryInfo.setCoordinateIndices(tetraFaceIndices); // triangulator = new Triangulator(); // only for polygons: // POLYGON_ARRAY // triangulator.triangulate(tetra_GeometryInfo); // and with: int // stripCounts[] // gi.setStripCounts(...) // int contourCounts[] // Set the parameters (1 texture with dimension 2) for the texture's // coordinates tetra_GeometryInfo.setTextureCoordinateParams(1, 2); // case #1: each face of the tetrahedron has the same texture portion. // The coordinates of the 3 points in the 2D texture space. textCoord2f = new TexCoord2f[3]; textCoord2f[0] = new TexCoord2f(0.0f, 0.2f); textCoord2f[1] = new TexCoord2f(0.5f, 1.0f); textCoord2f[2] = new TexCoord2f(1.0f, 0.5f); // Set the texture coordinate's indices (referenced to the array of 2D // points // in the texture space by setTextureCoordinates(0, textCoord2f) and // setTextureCoordinateIndices(0, textCoordIndices)). textCoordIndices = new int[lengthTetraFaceIndices]; // 12 // From the camera in the view coordinate system (inverse of // tetraFaceIndices !!!) // front face textCoordIndices[0] = 0; textCoordIndices[1] = 1; textCoordIndices[2] = 2; // back face textCoordIndices[3] = 0; textCoordIndices[4] = 1; textCoordIndices[5] = 2; // back-left face textCoordIndices[6] = 2; textCoordIndices[7] = 0; textCoordIndices[8] = 1; // bottom textCoordIndices[9] = 0; textCoordIndices[10] = 1; textCoordIndices[11] = 2; /* * // case #2: each face of the tetrahedron has a different part of the * texture. * // The coordinates of the 4 points in the 2D texture space. * textCoord2f = new TexCoord2f[4]; textCoord2f[0] = new * TexCoord2f(0.0f, 0.5f); textCoord2f[1] = new TexCoord2f(1.0f, 0.5f); * textCoord2f[2] = new TexCoord2f(0.6f, 0.7f); textCoord2f[3] = new * TexCoord2f(0.6f, 0.3f); * * // Set the texture coordinate's indices (referenced to the array of * 2D points // in the texture space by setTextureCoordinates(0, * textCoord2f) and // setTextureCoordinateIndices(0, * textCoordIndices)). textCoordIndices = new * int[lengthTetraFaceIndices]; // 12 * // From the camera in the view coordinate system (inverse of * tetraFaceIndices !!!) // front face textCoordIndices[0] = 3; * textCoordIndices[1] = 2; textCoordIndices[2] = 0; // back face * textCoordIndices[3] = 1; textCoordIndices[4] = 2; textCoordIndices[5] = * 3; // back-left face textCoordIndices[6] = 1; textCoordIndices[7] = * 0; textCoordIndices[8] = 2; // bottom textCoordIndices[9] = 1; * textCoordIndices[10]= 3; textCoordIndices[11]= 0; */ // just one set tetra_GeometryInfo.setTextureCoordinates(0, textCoord2f); // just one set tetra_GeometryInfo.setTextureCoordinateIndices(0, textCoordIndices); normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(tetra_GeometryInfo); if (crAngle) normalGenerator.setCreaseAngle(0.0f); // with 0 radian ===> creased stripifier = new Stripifier(); stripifier.stripify(tetra_GeometryInfo); tetra_GeometryArray = tetra_GeometryInfo.getGeometryArray(); // The geonometry is passed to the instance this of the tetrahedron. this.setGeometry(tetra_GeometryArray); ////////////////////// Appearance part /////////////////////////// appearance = new Appearance(); // Optical properties of the tetrahedron. // Ambient-diffuse-reflection coefficient diffAmb = new Color3f(1.0f, 0.5f, 1.0f); // Diffuse-reflection coefficient reflDiff = new Color3f(1.0f, 0.5f, 1.0f); // Specular-reflection coefficient (reflectance function) reflSpec = new Color3f(1.0f, 0.5f, 1.0f); // c = shininess: cos^c in the specular reflection float c = 15; // Emitted light emittedLight = new Color3f(0.0f, 0.0f, 0.0f); material = new Material(diffAmb, emittedLight, reflDiff, reflSpec, c); appearance.setMaterial(material); // This instance acts only on the tetrahedron and not on its texture. trAttr = new TransparencyAttributes(TransparencyAttributes.NICEST, 0.0f); // 0.0 = fully opaque // 1.0 = fully transparent appearance.setTransparencyAttributes(trAttr); // Loading the texture newTextureLoader = new NewTextureLoader("Images/Claude.jpg"); newTextureLoader.setImageObserver(newTextureLoader.getImageObserver()); texture = newTextureLoader.getTexture(); appearance.setTexture(texture); // Application mode 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 tetrahedron. this.setAppearance(appearance); return this; }