Example usage for javax.media.j3d ColoringAttributes setShadeModel

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

Introduction

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

Prototype

public void setShadeModel(int shadeModel) 

Source Link

Document

Sets the shade mode for this ColoringAttributes component object.

Usage

From source file:J3dSwingFrame.java

/**
 * Construct the default appearance.// w ww. j av a2  s.co 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:ExBluePrint.java

private Group buildGadget() {
    if (debug)//w  ww  .  j ava  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;
}