List of usage examples for javax.media.j3d Appearance setColoringAttributes
public void setColoringAttributes(ColoringAttributes coloringAttributes)
From source file:PickWorld.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); Color3f gray = new Color3f(0.4f, 0.4f, 0.4f); idx = idx % 5;/*from www .j ava2s . c o m*/ switch (idx) { // Lit solid case 0: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Lit solid, specular only case 1: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.4f, 0.2f); app.setMaterial(new Material(black, black, objColor, white, 80.0f)); break; } case 2: { // Set up the texture map TextureLoader tex = new TextureLoader("apimage.jpg", this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(gray, black, gray, white, 1.0f)); break; } // Texture mapped, lit solid case 3: { // Set up the texture map TextureLoader tex = new TextureLoader("earth.jpg", this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(gray, black, gray, white, 1.0f)); break; } // Another lit solid with a different color case 4: { // Set up the material properties Color3f objColor = new Color3f(1.0f, 1.0f, 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:ConicWorld.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); idx = idx % 5;/*from w w w. j a v a 2s . c om*/ switch (idx) { // Lit solid case 0: { // 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; } // Lit solid, no specular case 1: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); break; } // Lit solid, specular only case 2: { // Set up the material properties Color3f objColor = new Color3f(0.0f, 0.8f, 0.8f); app.setMaterial(new Material(black, black, objColor, white, 80.0f)); break; } // Texture mapped, lit solid case 3: { // Set up the texture map TextureLoader tex = new TextureLoader(texImage, this); app.setTexture(tex.getTexture()); // Set up the material properties app.setMaterial(new Material(white, black, white, black, 1.0f)); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); break; } // Another lit solid with a different color case 4: { // Set up the material properties Color3f objColor = new Color3f(1.0f, 1.0f, 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:ffx.potential.MolecularAssembly.java
/** * <p>//from w w w . j a va 2 s.c om * createBox</p> */ public void createBox() { int vertices = 8; LineArray la = new LineArray(4 * vertices, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS); la.setCapability(LineArray.ALLOW_COORDINATE_WRITE); la.setCapability(LineArray.ALLOW_COORDINATE_READ); la.setCapability(LineArray.ALLOW_COLOR_WRITE); la.setCapability(LineArray.ALLOW_COUNT_READ); la.setCapability(LineArray.ALLOW_INTERSECT); la.setCapability(LineArray.ALLOW_FORMAT_READ); // Create a normal // for (ListIterator li = bondlist.listIterator(); li.hasNext(); ){ // la.setCoordinate(i, a1); // la.setColor(i, col); // la.setNormal(i++, a1); // } ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD); Appearance app = new Appearance(); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(RendererCache.bondwidth); lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttributes.setLineAntialiasingEnable(true); app.setLineAttributes(lineAttributes); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); RenderingAttributes ra = new RenderingAttributes(); ra.setAlphaTestValue(0.1f); ra.setAlphaTestFunction(RenderingAttributes.GREATER); ra.setDepthBufferEnable(true); ra.setDepthBufferWriteEnable(true); app.setRenderingAttributes(ra); app.setColoringAttributes(cola); Shape3D wireframe = new Shape3D(la, app); // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD); wireframe.setUserData(this); wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 10.0)); try { wireframe.setBoundsAutoCompute(false); } catch (Exception e) { e.printStackTrace(); } wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ); wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ); // return wire; }
From source file:ffx.potential.MolecularAssembly.java
private Shape3D renderWire() { ArrayList<ROLS> bonds = getBondList(); int numbonds = bonds.size(); if (numbonds < 1) { return null; }//ww w. j av a 2 s. co m Vector3d bondmidpoint = new Vector3d(); double[] mid = { 0, 0, 0 }; Vector3d v1 = new Vector3d(); Vector3d v2 = new Vector3d(); float[] a1 = { 0, 0, 0 }; float[] a2 = { 0, 0, 0 }; float[] col = new float[4]; Bond bond; Atom atom1, atom2; LineArray la = new LineArray(4 * numbonds, GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS); la.setCapability(LineArray.ALLOW_COORDINATE_WRITE); la.setCapability(LineArray.ALLOW_COORDINATE_READ); la.setCapability(LineArray.ALLOW_COLOR_WRITE); la.setCapability(LineArray.ALLOW_COUNT_READ); la.setCapability(LineArray.ALLOW_INTERSECT); la.setCapability(LineArray.ALLOW_FORMAT_READ); atomLookUp = new Atom[4 * numbonds]; int i = 0; col[3] = 0.9f; for (ListIterator li = bonds.listIterator(); li.hasNext();) { bond = (Bond) li.next(); bond.setWire(la, i); atom1 = bond.getAtom(0); atom2 = bond.getAtom(1); atom1.getV3D(v1); atom2.getV3D(v2); a1[0] = (float) v1.x; a1[1] = (float) v1.y; a1[2] = (float) v1.z; a2[0] = (float) v2.x; a2[1] = (float) v2.y; a2[2] = (float) v2.z; // Find the bond center bondmidpoint.add(v1, v2); bondmidpoint.scale(0.5d); bondmidpoint.get(mid); // Atom #1 Atom.AtomColor.get(atom1.getAtomicNumber()).get(col); atomLookUp[i] = atom1; la.setCoordinate(i, a1); la.setColor(i, col); la.setNormal(i, a2); i++; atomLookUp[i] = atom1; la.setCoordinate(i, mid); la.setColor(i, col); la.setNormal(i, a2); i++; // Atom #2 Atom.AtomColor.get(atom2.getAtomicNumber()).get(col); atomLookUp[i] = atom2; la.setCoordinate(i, a2); la.setColor(i, col); la.setNormal(i, a1); i++; atomLookUp[i] = atom2; la.setCoordinate(i, mid); la.setColor(i, col); la.setNormal(i, a1); i++; } ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD); Appearance app = new Appearance(); lineAttributes = new LineAttributes(); lineAttributes.setLineWidth(RendererCache.bondwidth); lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttributes.setLineAntialiasingEnable(true); app.setLineAttributes(lineAttributes); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ); app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE); RenderingAttributes ra = new RenderingAttributes(); ra.setAlphaTestValue(0.1f); ra.setAlphaTestFunction(RenderingAttributes.GREATER); ra.setDepthBufferEnable(true); ra.setDepthBufferWriteEnable(true); app.setRenderingAttributes(ra); app.setColoringAttributes(cola); Shape3D wireframe = new Shape3D(la, app); // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD); wireframe.setUserData(this); wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000.0)); try { wireframe.setBoundsAutoCompute(false); } catch (Exception e) { e.printStackTrace(); } wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ); wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ); wireframe.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ); return wireframe; }
From source file:ExDepthCue.java
public Shape3D buildSurface(double freqAlpha, double freqTheta, double radius, float red, float green, float blue) { int nAngles = 64; double amp = radius / 4.0; int nAlpha = nAngles / 2; double theta, alpha; double x, y, z, rprime, r; double deltaTheta, deltaAlpha; int i, j;/*ww w . j av a 2 s .c o m*/ int i1, i2, i3, i4; deltaTheta = 360.0 / (nAngles - 1.0); deltaAlpha = 180.0 / (nAlpha - 1.0); // Build an appearance Appearance app = new Appearance(); LineAttributes latt = new LineAttributes(); latt.setLineWidth(1.0f); app.setLineAttributes(latt); ColoringAttributes catt = new ColoringAttributes(); catt.setColor(red, green, blue); app.setColoringAttributes(catt); PolygonAttributes patt = new PolygonAttributes(); patt.setCullFace(PolygonAttributes.CULL_NONE); patt.setPolygonMode(PolygonAttributes.POLYGON_LINE); app.setPolygonAttributes(patt); // Compute coordinates double[] coordinates = new double[nAlpha * nAngles * 3]; alpha = 90.0; int n = 0; for (i = 0; i < nAlpha; i++) { theta = 0.0; for (j = 0; j < nAngles; j++) { r = radius + amp * Math.sin((freqAlpha * ((double) i / (double) (nAlpha - 1)) + freqTheta * ((double) j / (double) (nAngles - 1))) * 2.0 * Math.PI); y = r * Math.sin(alpha / 180.0 * Math.PI); rprime = y / Math.tan(alpha / 180.0 * Math.PI); x = rprime * Math.cos(theta / 180.0 * Math.PI); z = rprime * Math.sin(theta / 180.0 * Math.PI); coordinates[n + 0] = x; coordinates[n + 1] = y; coordinates[n + 2] = z; n += 3; theta += deltaTheta; } alpha -= deltaAlpha; } // Compute coordinate indexes int[] indexes = new int[(nAlpha - 1) * nAngles * 4]; n = 0; for (i = 0; i < nAlpha - 1; i++) { for (j = 0; j < nAngles; j++) { i1 = i * nAngles + j; if (j == nAngles - 1) { i2 = i1 - j; i3 = (i + 1) * nAngles; } else { i2 = i1 + 1; i3 = (i + 1) * nAngles + j + 1; } i4 = (i + 1) * nAngles + j; indexes[n + 0] = i1; indexes[n + 1] = i2; indexes[n + 2] = i3; indexes[n + 3] = i4; n += 4; } } // Build the shape IndexedQuadArray lines = new IndexedQuadArray(coordinates.length / 3, // Number // of // coordinates GeometryArray.COORDINATES, // coordinates only indexes.length); // Number of indexes lines.setCoordinates(0, coordinates); lines.setCoordinateIndices(0, indexes); Shape3D shape = new Shape3D(lines, app); return shape; }
From source file:ExAppearance.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 ww w .j ava 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.2f, 0.4f); 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); // Set up line attributes LineAttributes lta = new LineAttributes(); lta.setLineWidth(10.0f); app.setLineAttributes(lta); break; } // Unlit points case 2: { // 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); // 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(10.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("apimage.jpg", this); app.setTexture(tex.getTexture()); // 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.0f, 0.0f, 0.8f); 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:SplineInterpolatorTest.java
public Group createLand(Group g) { Land land = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); Group hiResGroup = land.createObject(new Appearance(), new Vector3d(), new Vector3d(LAND_WIDTH, 1, LAND_LENGTH), "boston.gif", null, null); Appearance app = new Appearance(); app.setColoringAttributes(new ColoringAttributes(WATER_COLOR_RED / 255f, WATER_COLOR_GREEN / 255f, WATER_COLOR_BLUE / 255f, ColoringAttributes.FASTEST)); Land base = new Land(this, hiResGroup, ComplexObject.GEOMETRY); base.createObject(app, new Vector3d(0, -5, 0), new Vector3d(4 * LAND_WIDTH, 1, 4 * LAND_LENGTH), null, null, null);//from ww w .j a va 2 s.co m return hiResGroup; }
From source file:ExBluePrint.java
private Group buildGadget() { if (debug)//from ww w .j av a2s.c o m System.err.println(" gadget..."); // // Create two appearances: // wireframeApp: draw as blue wireframe // shadedApp: draw as metalic shaded polygons // // Wireframe: // no Material - defaults to coloring attributes color // polygons as lines, with backfaces // thick lines Appearance wireframeApp = new Appearance(); ColoringAttributes wireframeCatt = new ColoringAttributes(); wireframeCatt.setColor(0.0f, 0.2559f, 0.4213f); wireframeCatt.setShadeModel(ColoringAttributes.SHADE_FLAT); wireframeApp.setColoringAttributes(wireframeCatt); PolygonAttributes wireframePatt = new PolygonAttributes(); wireframePatt.setPolygonMode(PolygonAttributes.POLYGON_LINE); wireframePatt.setCullFace(PolygonAttributes.CULL_NONE); wireframeApp.setPolygonAttributes(wireframePatt); LineAttributes wireframeLatt = new LineAttributes(); wireframeLatt.setLineWidth(2.0f); wireframeApp.setLineAttributes(wireframeLatt); // Shaded: // silver material Appearance shadedApp = new Appearance(); Material shadedMat = new Material(); shadedMat.setAmbientColor(0.30f, 0.30f, 0.30f); shadedMat.setDiffuseColor(0.30f, 0.30f, 0.50f); shadedMat.setSpecularColor(0.60f, 0.60f, 0.80f); shadedMat.setShininess(0.10f); shadedApp.setMaterial(shadedMat); ColoringAttributes shadedCatt = new ColoringAttributes(); shadedCatt.setShadeModel(ColoringAttributes.SHADE_GOURAUD); shadedApp.setColoringAttributes(shadedCatt); // // Create a switch group to hold two versions of the // shape: one wireframe, and one shaded // Transform3D tr = new Transform3D(); tr.set(new Vector3f(-1.0f, 0.2f, 0.0f)); TransformGroup gadget = new TransformGroup(tr); shadingSwitch = new Switch(); shadingSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); Group wireframe = new Group(); Group shaded = new Group(); shadingSwitch.addChild(wireframe); shadingSwitch.addChild(shaded); shadingSwitch.setWhichChild(1); // shaded gadget.addChild(shadingSwitch); // // Build a gear (wireframe and shaded) // tr = new Transform3D(); tr.rotY(Math.PI / 2.0); TransformGroup tg = new TransformGroup(tr); SpurGear gear = new SpurGearThinBody(24, // tooth count 1.6f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGearThinBody(24, // tooth count 1.6f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); // // Build another gear (wireframe and shaded) // tr.rotY(Math.PI / 2.0); Vector3f trans = new Vector3f(-0.5f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); gear = new SpurGearThinBody(30, // tooth count 2.0f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGearThinBody(30, // tooth count 2.0f, // pitch circle radius 0.3f, // shaft radius 0.08f, // addendum 0.05f, // dedendum 0.3f, // gear thickness 0.28f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); // // Build a cylindrical shaft (wireframe and shaded) // tr.rotZ(-Math.PI / 2.0); trans = new Vector3f(1.0f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); Cylinder cyl = new Cylinder(0.3f, // radius 4.0f, // length Primitive.GENERATE_NORMALS, // format 16, // radial resolution 1, // length-wise resolution wireframeApp);// appearance tg.addChild(cyl); wireframe.addChild(tg); tg = new TransformGroup(tr); cyl = new Cylinder(0.3f, // radius 4.0f, // length Primitive.GENERATE_NORMALS, // format 16, // radial resolution 1, // length-wise resolution shadedApp); // appearance tg.addChild(cyl); shaded.addChild(tg); // // Build shaft teeth (wireframe and shaded) // tr.rotY(Math.PI / 2.0); trans = new Vector3f(2.05f, 0.0f, 0.0f); tr.setTranslation(trans); tg = new TransformGroup(tr); gear = new SpurGear(12, // tooth count 0.5f, // pitch circle radius 0.3f, // shaft radius 0.05f, // addendum 0.05f, // dedendum 1.5f, // gear thickness 0.8f, // tooth tip thickness wireframeApp);// appearance tg.addChild(gear); wireframe.addChild(tg); tg = new TransformGroup(tr); gear = new SpurGear(12, // tooth count 0.5f, // pitch circle radius 0.3f, // shaft radius 0.05f, // addendum 0.05f, // dedendum 1.5f, // gear thickness 0.8f, // tooth tip thickness shadedApp); // appearance tg.addChild(gear); shaded.addChild(tg); return gadget; }