Example usage for javax.media.j3d ColoringAttributes SHADE_GOURAUD

List of usage examples for javax.media.j3d ColoringAttributes SHADE_GOURAUD

Introduction

In this page you can find the example usage for javax.media.j3d ColoringAttributes SHADE_GOURAUD.

Prototype

int SHADE_GOURAUD

To view the source code for javax.media.j3d ColoringAttributes SHADE_GOURAUD.

Click Source Link

Document

Smoothly interpolate the color at each vertex across the primitive.

Usage

From source file:ExBluePrint.java

private Group buildGadget() {
    if (debug)//from  w  ww  . j av a 2 s. co  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;
}

From source file:J3dSwingFrame.java

/**
 * Construct the default appearance./*  ww  w . j  a  v  a  2s .c  o  m*/
 */
private void constructAppearance() {
    appearance = new Appearance();

    TextureAttributes tex_attr = new TextureAttributes();
    tex_attr.setTextureMode(TextureAttributes.DECAL);
    tex_attr.setPerspectiveCorrectionMode(TextureAttributes.FASTEST);

    appearance.setTextureAttributes(tex_attr);

    ColoringAttributes col_attr = new ColoringAttributes();
    col_attr.setShadeModel(ColoringAttributes.SHADE_GOURAUD);

    appearance.setColoringAttributes(col_attr);

    PolygonAttributes rend_attr = new PolygonAttributes();
    rend_attr.setCullFace(PolygonAttributes.CULL_NONE);
    //  uncomment this if you want it to display in line draw mode
    //    rend_attr.setPolygonMode(PolygonAttributes.POLYGON_LINE);

    appearance.setPolygonAttributes(rend_attr);

    Material mat = new Material();
    //    Color3f col = new Color3f(1, 0, 0);
    //    mat.setEmissiveColor(col);

    appearance.setMaterial(mat);

    setAppearance(appearance);
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * <p>// w  w w  .  j ava  2  s  . com
 * 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;
    }/*w w  w . j a  v a  2  s .com*/

    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:AppearanceTest.java

public void onGouraud() {
    getColoringAttributes().setShadeModel(ColoringAttributes.SHADE_GOURAUD);
}

From source file:AppearanceExplorer.java

public ColoringAttributesEditor(ColoringAttributes init) {
    super(BoxLayout.Y_AXIS);
    coloringAttr = init;//w  w  w  .  j a  va  2s .co  m
    coloringAttr.getColor(color);
    coloringShadeModel = coloringAttr.getShadeModel();

    String[] shadeNames = { "SHADE_FLAT", "SHADE_GOURAUD", "NICEST", "FASTEST" };
    int[] shadeValues = { ColoringAttributes.SHADE_FLAT, ColoringAttributes.SHADE_GOURAUD,
            ColoringAttributes.NICEST, ColoringAttributes.FASTEST };

    IntChooser shadeChooser = new IntChooser("Shade model:", shadeNames, shadeValues, coloringShadeModel);
    shadeChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            coloringAttr.setShadeModel(value);
        }
    });
    add(shadeChooser);

    Color3fEditor colorEditor = new Color3fEditor("Color", color);
    colorEditor.addColor3fListener(new Color3fListener() {
        public void colorChanged(Color3fEvent event) {
            event.getValue(color);
            coloringAttr.setColor(color);
        }
    });
    add(colorEditor);
}

From source file:Demo3D.java

/**
 * This methode serves to construct the earth.
 * /*from www.  j  a  v  a2s.  com*/
 * @return com.sun.j3d.utils.geometry.Sphere earth - the constructed earth
 */
public Sphere myEarth() {
    // Optical properties of the earth.

    // Ambient-diffuse-reflection coefficient
    diffAmb = new Color3f(1.0f, 1.0f, 1.0f);
    // Diffuse-reflection coefficient
    reflDiff = new Color3f(1.0f, 1.0f, 1.0f);
    // Specular-reflection coefficient (reflectance function)
    reflSpec = new Color3f(0.0f, 0.0f, 0.1f);
    // c = shininess: cos^c in the specular reflection
    c = 1;
    // Emitted light
    emittedLight = new Color3f(0.0f, 0.0f, 0.0f);

    appearance = new Appearance();

    // Create the material and set up the optical properties.
    material = new Material(diffAmb, emittedLight, reflDiff, reflSpec, c);
    appearance.setMaterial(material);

    // Set up the polygon's rendering-mode (with the polygonAttributes) and
    // the shading-mode (with the coloringAttributes).
    polygonAttributes = new PolygonAttributes();
    coloringAttributes = new ColoringAttributes();

    // Points
    if (renderingType.compareTo("points") == 0) {
        polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_POINT);
    }

    /* Lines*/
    else if (renderingType.compareTo("lines") == 0) {
        polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    }

    /* Polygons */
    else if (renderingType.compareTo("polygons") == 0) {
        /* is the default value*/
        polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
        coloringAttributes.setShadeModel(ColoringAttributes.SHADE_FLAT);
    }

    /* Gouraud */
    else if (renderingType.compareTo("gouraud") == 0) {
        polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL); /* is the default value*/
        coloringAttributes.setShadeModel(ColoringAttributes.SHADE_GOURAUD); /* is the default value*/
    }

    else if (renderingType.compareTo("texture") == 0) {
        polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL); /* is the default value*/
        coloringAttributes.setShadeModel(ColoringAttributes.SHADE_GOURAUD); /* is the default value*/

        /* Loading of the texture*/
        newTextureLoader = new NewTextureLoader("Images/Earth.jpg");
        newTextureLoader.setImageObserver(newTextureLoader.getImageObserver());
        texture = newTextureLoader.getTexture();

        appearance.setTexture(texture);

        /* Application mode of the texture */
        textAttr = new TextureAttributes();
        textAttr.setTextureMode(TextureAttributes.REPLACE); /* there still are:
                                                            BLEND, COMBINE,
                                                            DECAL, and MODULATE*/
        appearance.setTextureAttributes(textAttr);
    }

    appearance.setPolygonAttributes(polygonAttributes);
    appearance.setColoringAttributes(coloringAttributes);

    /* Construction of the earth with all its features.*/
    earth = new Sphere(scale_XYZ, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 10, appearance);
    return earth;
}