List of usage examples for javax.media.j3d Appearance Appearance
public Appearance()
From source file:KeyNavigateTest.java
public Group createCeiling(Group g) { System.out.println("Creating ceiling"); Group ceilingGroup = new Group(); Land ceilingTile = null;//from ww w .ja v a 2 s. co m // because we are technically viewing the ceiling from below // we want to switch the normals using a PolygonAttributes. Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); g.addChild(ceilingGroup); final double kNumTiles = 6; for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x + FLOOR_WIDTH / kNumTiles) { for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z + FLOOR_LENGTH / kNumTiles) { ceilingTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); ceilingTile.createObject(app, new Vector3d(x, m_kCeilingLevel, z), new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)), "ceiling.gif", null, null); } } return ceilingGroup; }
From source file:TexCoordTest.java
void createAppearance(double yMaxHeight) { // create an Appearance and assign a Material m_Appearance = new Appearance(); m_Appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE); Color3f black = new Color3f(0, 0.2f, 0); Color3f objColor = new Color3f(0.1f, 0.7f, 0.2f); m_Appearance.setMaterial(new Material(objColor, black, objColor, black, 0.8f)); // load the texture image TextureLoader texLoader = new TextureLoader("stripes.gif", Texture.RGB, this); // clamp the coordinates in the S dimension, that way they // will not wrap when the calculated texture coordinate falls outside // the range 0 to 1. When the texture coordinate is outside this range // no texture coordinate will be used Texture tex = texLoader.getTexture(); tex.setBoundaryModeS(Texture.CLAMP); // assign the texute image to the appearance m_Appearance.setTexture(tex);// w ww . ja v a 2 s . c o m // create the TexCoordGeneration object. // we are only using 1D texture coordinates (S) - texture coordinates // are calculated from a vertex's distance from the Y = 0 plane // the 4th parameter to the Vector4f is the distance in *texture // coordinates* // that we shift the texture coordinates by (i.e. Y = 0 corresponds to S // = 0.5) TexCoordGeneration texGen = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(0, (float) (1.0 / (2 * yMaxHeight)), 0, 0.5f), new Vector4f(0, 0, 0, 0), new Vector4f(0, 0, 0, 0)); // create our "non-live" TexCoordGeneration object so we // can update the "genMode" parameter after we go live. m_TexGen = (TexCoordGeneration) texGen.cloneNodeComponent(true); // assign the TexCoordGeneration to the Appearance m_Appearance.setTexCoordGeneration(texGen); // we just glue the texture image to the surface, we are not // blending or modulating the texture image based on material // attributes. You can experiment with MODULATE or BLEND. TextureAttributes texAttribs = new TextureAttributes(); texAttribs.setTextureMode(TextureAttributes.DECAL); m_Appearance.setTextureAttributes(texAttribs); }
From source file:ImageComponentByReferenceTest.java
void createRaster(BranchGroup scene) { // Create raster geometries and shapes Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg;//from w ww .ja v a 2 s . c o m // Left raster = new javax.media.j3d.Raster(); raster.setCapability(javax.media.j3d.Raster.ALLOW_IMAGE_WRITE); raster.setCapability(javax.media.j3d.Raster.ALLOW_SIZE_WRITE); raster.setPosition(new Point3f(-0.9f, 0.75f, 0.0f)); raster.setType(javax.media.j3d.Raster.RASTER_COLOR); raster.setOffset(0, 0); raster.setSize(image[2].getWidth(), image[2].getHeight()); raster.setImage(image[2]); Shape3D sh = new Shape3D(raster, new Appearance()); scene.addChild(sh); }
From source file:MouseNavigateTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // note that we are creating a TG *above* the TG // the is being controlled by the mouse behaviors. // The SUN mouse translate behavior would fail in this // instance as all movement would be in the X-Y plane // irrespective of any TG above the object. // The TornadoMouseTranslate behavior always moves an object // parrallel to the image plane TransformGroup objTrans1 = new TransformGroup(); Transform3D t3d = new Transform3D(); objTrans1.getTransform(t3d);//from w w w.j a v a 2s . c o m t3d.setEuler(new Vector3d(0.9, 0.8, 0.3)); objTrans1.setTransform(t3d); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create the mouse scale behavior and set limits TornadoMouseScale mouseScale = new TornadoMouseScale(5, 0.1f); mouseScale.setMinScale(new Point3d(0.5, 0.5, 0.5)); mouseScale.setMaxScale(new Point3d(2, 2, 2)); mouseScale.setObject(objTrans); mouseScale.setChangeListener(this); mouseScale.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseScale); // create the mouse rotate behavior TornadoMouseRotate mouseRotate = new TornadoMouseRotate(0.001, 0.001); mouseRotate.setInvert(true); mouseRotate.setObject(objTrans); mouseRotate.setChangeListener(this); mouseRotate.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseRotate); // create the mouse translate behavior and set limits TornadoMouseTranslate mouseTrans = new TornadoMouseTranslate(0.005f); mouseTrans.setObject(objTrans); mouseTrans.setChangeListener(this); mouseTrans.setMinTranslate(new Point3d(-4, -4, -4)); mouseTrans.setMaxTranslate(new Point3d(4, 4, 4)); mouseTrans.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(mouseTrans); objTrans.addChild(new ColorCube(0.5)); // create some axis for the world to show it has been rotated ColorCube axis = new ColorCube(5.0); Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0)); axis.setAppearance(app); objTrans1.addChild(axis); objTrans1.addChild(objTrans); objRoot.addChild(objTrans1); return objRoot; }
From source file:LightTest.java
protected Group createSphere(float x, float y, float z, float radius) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); tg.setTransform(t3d);/*w ww. j a v a2 s. c om*/ // create an Appearance and Material Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); tg.addChild(new Sphere(radius, Primitive.GENERATE_NORMALS, app)); return tg; }
From source file:TickTockCollision.java
public Box(double xsize, double ysize, double zsize) { super();// w w w .j a v a 2s. c o m double xmin = -xsize / 2.0; double xmax = xsize / 2.0; double ymin = -ysize / 2.0; double ymax = ysize / 2.0; double zmin = -zsize / 2.0; double zmax = zsize / 2.0; QuadArray box = new QuadArray(24, QuadArray.COORDINATES); Point3d verts[] = new Point3d[24]; // front face verts[0] = new Point3d(xmax, ymin, zmax); verts[1] = new Point3d(xmax, ymax, zmax); verts[2] = new Point3d(xmin, ymax, zmax); verts[3] = new Point3d(xmin, ymin, zmax); // back face verts[4] = new Point3d(xmin, ymin, zmin); verts[5] = new Point3d(xmin, ymax, zmin); verts[6] = new Point3d(xmax, ymax, zmin); verts[7] = new Point3d(xmax, ymin, zmin); // right face verts[8] = new Point3d(xmax, ymin, zmin); verts[9] = new Point3d(xmax, ymax, zmin); verts[10] = new Point3d(xmax, ymax, zmax); verts[11] = new Point3d(xmax, ymin, zmax); // left face verts[12] = new Point3d(xmin, ymin, zmax); verts[13] = new Point3d(xmin, ymax, zmax); verts[14] = new Point3d(xmin, ymax, zmin); verts[15] = new Point3d(xmin, ymin, zmin); // top face verts[16] = new Point3d(xmax, ymax, zmax); verts[17] = new Point3d(xmax, ymax, zmin); verts[18] = new Point3d(xmin, ymax, zmin); verts[19] = new Point3d(xmin, ymax, zmax); // bottom face verts[20] = new Point3d(xmin, ymin, zmax); verts[21] = new Point3d(xmin, ymin, zmin); verts[22] = new Point3d(xmax, ymin, zmin); verts[23] = new Point3d(xmax, ymin, zmax); box.setCoordinates(0, verts); setGeometry(box); setAppearance(new Appearance()); }
From source file:AppearanceExplorer.java
void setupAppearance() { appearance = new Appearance(); // ColoringAttributes coloringColor = new Color3f(red); coloringAttr = new ColoringAttributes(coloringColor, coloringShadeModel); coloringAttr.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE); coloringAttr.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE); appearance.setColoringAttributes(coloringAttr); // set up the editor coloringAttrEditor = new ColoringAttributesEditor(coloringAttr); // PointAttributes pointAttr = new PointAttributes(pointSize, pointAAEnable); pointAttr.setCapability(PointAttributes.ALLOW_SIZE_WRITE); pointAttr.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setPointAttributes(pointAttr); // set up the editor pointAttrEditor = new PointAttributesEditor(pointAttr); // LineAttributes lineAttr = new LineAttributes(lineWidth, linePattern, lineAAEnable); lineAttr.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_PATTERN_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setLineAttributes(lineAttr); // set up the editor lineAttrEditor = new LineAttributesEditor(lineAttr); // PolygonAttributes polygonAttr = new PolygonAttributes(polygonMode, polygonCull, 0.0f); polygonAttr.setPolygonOffset(polygonOffsetBias); polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor); polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); appearance.setPolygonAttributes(polygonAttr); // set up the editor polygonAttrEditor = new PolygonAttributesEditor(polygonAttr); // Rendering attributes renderAttr = new RenderingAttributes(renderDepthBuffer, renderDepthBufferWrite, 0.0f, RenderingAttributes.ALWAYS, renderVisible, renderIgnoreVertexColor, renderRasterOpEnable, renderRasterOp);/* w w w.ja v a2s.c o m*/ renderAttr.setCapability(RenderingAttributes.ALLOW_IGNORE_VERTEX_COLORS_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_FUNCTION_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_VALUE_WRITE); appearance.setRenderingAttributes(renderAttr); appearance.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE); // set up the editor renderAttrEditor = new RenderingAttributesEditor(renderAttr); // TransparencyAttributes transpAttr = new TransparencyAttributes(transpMode, transpValue); transpAttr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE); appearance.setTransparencyAttributes(transpAttr); // set up the editor transpAttrEditor = new TransparencyAttributesEditor(transpAttr); // Material material = new Material(red, black, red, white, 20.f); material.setLightingEnable(false); material.setCapability(Material.ALLOW_COMPONENT_WRITE); appearance.setMaterial(material); // material presets String[] materialNames = { "Red", "White", "Red Ambient", "Red Diffuse", "Grey Emissive", "White Specular", "Aluminium", "Blue Plastic", "Copper", "Gold", "Red Alloy", "Black Onyx" }; Material[] materialPresets = new Material[materialNames.length]; materialPresets[0] = new Material(red, black, red, white, 20.0f); materialPresets[1] = new Material(white, black, white, white, 20.0f); materialPresets[2] = new Material(red, black, black, black, 20.0f); materialPresets[3] = new Material(black, black, red, black, 20.0f); materialPresets[4] = new Material(black, grey, black, black, 20.0f); materialPresets[5] = new Material(black, black, black, white, 20.0f); Color3f alum = new Color3f(0.37f, 0.37f, 0.37f); Color3f alumSpec = new Color3f(0.89f, 0.89f, 0.89f); materialPresets[6] = new Material(alum, black, alum, alumSpec, 17); Color3f bluePlastic = new Color3f(0.20f, 0.20f, 0.70f); Color3f bluePlasticSpec = new Color3f(0.85f, 0.85f, 0.85f); materialPresets[7] = new Material(bluePlastic, black, bluePlastic, bluePlasticSpec, 22); Color3f copper = new Color3f(0.30f, 0.10f, 0.00f); ; Color3f copperSpec = new Color3f(0.75f, 0.30f, 0.00f); materialPresets[8] = new Material(copper, black, copper, copperSpec, 10); Color3f gold = new Color3f(0.49f, 0.34f, 0.00f); Color3f goldSpec = new Color3f(0.89f, 0.79f, 0.00f); materialPresets[9] = new Material(gold, black, gold, goldSpec, 15); Color3f redAlloy = new Color3f(0.34f, 0.00f, 0.34f); Color3f redAlloySpec = new Color3f(0.84f, 0.00f, 0.00f); materialPresets[10] = new Material(redAlloy, black, redAlloy, redAlloySpec, 15); Color3f blackOnyxSpec = new Color3f(0.72f, 0.72f, 0.72f); materialPresets[11] = new Material(black, black, black, blackOnyxSpec, 23); // set up the editor materialEditor = new MaterialPresetEditor(material, materialNames, materialPresets); // Texture2D // set the values to the defaults texEnable = false; texMipMapMode = Texture.BASE_LEVEL; texBoundaryModeS = Texture.WRAP; texBoundaryModeT = Texture.WRAP; texMinFilter = Texture.BASE_LEVEL_POINT; texMagFilter = Texture.BASE_LEVEL_POINT; texBoundaryColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f); // set up the image choices String[] texImageNames = { "Earth", "Fish", }; String[] texImageFileNames = { "earth.jpg", "fish1.gif", }; int texImageFileIndex = 0; // set up the appearance to allow the texture to be changed appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE); // set up the editor (this will create the initial Texture2D and // assign it to the appearance) texture2DEditor = new Texture2DEditor(appearance, codeBaseString, texImageNames, texImageFileNames, texImageFileIndex, texEnable, texBoundaryModeS, texBoundaryModeT, texMinFilter, texMagFilter, texMipMapMode, texBoundaryColor); // TextureAttributes texMode = TextureAttributes.REPLACE; texBlendColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f); texTransform = new Transform3D(); texPerspCorrect = TextureAttributes.NICEST; textureAttr = new TextureAttributes(texMode, texTransform, texBlendColor, texPerspCorrect); // set the capabilities to allow run time changes textureAttr.setCapability(TextureAttributes.ALLOW_MODE_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE); // connect it to the appearance appearance.setTextureAttributes(textureAttr); // setup the editor textureAttrEditor = new TextureAttributesEditor(textureAttr); // set up the tex coordinate generation texGenEnable = false; texGenMode = TexCoordGeneration.OBJECT_LINEAR; texGenPlaneS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f); texGenPlaneT = new Vector4f(0.0f, 1.0f, 0.0f, 0.0f); // set the appearance so that we can replace the tex gen when live appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE); // setup the editor texGenEditor = new TexCoordGenerationEditor(appearance, texGenEnable, texGenMode, texGenPlaneS, texGenPlaneT); }
From source file:GeomInfoApp.java
Appearance createMaterialAppearance() { Appearance materialAppear = new Appearance(); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); materialAppear.setPolygonAttributes(polyAttrib); Material material = new Material(); material.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f)); materialAppear.setMaterial(material); return materialAppear; }
From source file:ExSound.java
private Group buildForeground() { ///*w w w . java 2 s . 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:GeomInfoApp.java
Appearance createWireFrameAppearance() { Appearance materialAppear = new Appearance(); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE); materialAppear.setPolygonAttributes(polyAttrib); ColoringAttributes redColoring = new ColoringAttributes(); redColoring.setColor(1.0f, 0.0f, 0.0f); materialAppear.setColoringAttributes(redColoring); return materialAppear; }