Example usage for javax.media.j3d PolygonAttributes setPolygonMode

List of usage examples for javax.media.j3d PolygonAttributes setPolygonMode

Introduction

In this page you can find the example usage for javax.media.j3d PolygonAttributes setPolygonMode.

Prototype

public void setPolygonMode(int polygonMode) 

Source Link

Document

Sets the polygon rasterization mode for this appearance component object.

Usage

From source file:SimpleWire.java

/**
 * This constructs a cube using the Box utility class. The attributes are
 * set so that the lines are drawn and not the faces.
 * /* w  w  w  .  j  ava 2 s  . c o m*/
 * @return Node that is the cube
 */
protected Node buildShape() {
    Appearance app = new Appearance();
    //Create the polygon attributes
    PolygonAttributes polyAttr = new PolygonAttributes();
    //Set them so that the draw mode is polygon line
    polyAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    //Use these in the appearance
    app.setPolygonAttributes(polyAttr);
    return new Box(1.0f, 1.0f, 1.0f, app);
}

From source file:TwistStripApp.java

public BranchGroup createSceneGraph() {

    BranchGroup contentRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentRoot.addChild(objSpin);/*ww  w.j  a va  2  s  .c  om*/

    Shape3D twist = new Twist();
    objSpin.addChild(twist);

    // Duplicate the twist strip geometry and set the
    // appearance of the new Shape3D object to line mode
    // without culling.
    // Add the POLYGON_FILLED and POLYGON_LINE strips
    // in the scene graph at the same point.
    // This will show the triangles of the original Mobius strip that
    // are clipped. The PolygonOffset is set to prevent stitching.
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrib.setPolygonOffset(0.001f);
    Appearance polyAppear = new Appearance();
    polyAppear.setPolygonAttributes(polyAttrib);
    objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear));

    Alpha rotationAlpha = new Alpha(-1, 16000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 1
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    // make background white
    Background background = new Background(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    contentRoot.addChild(background);

    // Let Java 3D perform optimizations on this scene graph.
    contentRoot.compile();

    return contentRoot;
}

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;
}

From source file:TriangulatorTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);

    objTrans.addChild(rotator);// ww  w .  ja  v a  2s.co  m

    // triangulate the polygon
    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);

    gi.setCoordinates(m_VertexArray);

    int[] stripCountArray = { 10, 5 };
    int[] countourCountArray = { stripCountArray.length };

    gi.setContourCounts(countourCountArray);
    gi.setStripCounts(stripCountArray);

    Triangulator triangulator = new Triangulator();
    triangulator.triangulate(gi);

    NormalGenerator normalGenerator = new NormalGenerator();
    normalGenerator.generateNormals(gi);

    // create an appearance
    Appearance ap = new Appearance();

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    ap.setPolygonAttributes(polyAttrbutes);

    // add both a wireframe and a solid version
    // of the triangulated surface
    Shape3D shape1 = new Shape3D(gi.getGeometryArray(), ap);
    Shape3D shape2 = new Shape3D(gi.getGeometryArray());

    objTrans.addChild(shape1);
    objTrans.addChild(shape2);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:AppearanceTest.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 w  w  w .  j  a  v  a  2  s  . 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(0.5f, 0.0f, 0.2f);
        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(0.2f, 0.2f, 1.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:Text3DTest.java

TransformGroup createText3D(TornadoRotation rotator, String szText, int nSize, float scale, float trans,
        int nPath) {
    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(scale);//from  w  w w  . ja v a2s. c  o  m
    t3d.setTranslation(new Vector3d(0.0, trans, -10.0));
    tg.setTransform(t3d);

    // use a customized FontExtrusion object to control the depth of the
    // text
    double X1 = 0;
    double Y1 = 0;
    double X2 = 3;
    double Y2 = 0;
    Shape extrusionShape = new java.awt.geom.Line2D.Double(X1, Y1, X2, Y2);

    FontExtrusion fontEx = new FontExtrusion(extrusionShape);

    Font3D f3d = new Font3D(new Font("TimesRoman", Font.PLAIN, nSize), fontEx);

    TornadoText3D text3D = new TornadoText3D(f3d, szText, new Point3f(0.0f, 0.0f, 0.0f), Text3D.ALIGN_CENTER,
            nPath);

    rotator.addTornadoText3D(text3D);

    // create an appearance
    Color3f black = new Color3f(0.1f, 0.1f, 0.1f);
    Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f);

    Appearance app = new Appearance();
    app.setMaterial(new Material(objColor, black, objColor, black, 90.0f));

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    app.setPolygonAttributes(polyAttrbutes);

    tg.addChild(new Shape3D(text3D, app));
    return tg;
}

From source file:IntersectTest.java

public IntersectInfoBehavior(Canvas3D canvas3D, BranchGroup branchGroup, float size) {
    pickCanvas = new PickCanvas(canvas3D, branchGroup);
    pickCanvas.setTolerance(5.0f);//from   ww  w .j av a2  s .  c o m
    pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);
    this.size = size;
    // Create an Appearance.
    redlook = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.0f, 0.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    redlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    redlook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    redlookwf = new Appearance();
    redlookwf.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    PolygonAttributes pa = new PolygonAttributes();
    pa.setPolygonMode(pa.POLYGON_LINE);
    pa.setCullFace(pa.CULL_NONE);
    redlookwf.setPolygonAttributes(pa);

    oldlook = new Appearance();
    objColor = new Color3f(1.0f, 1.0f, 1.0f);
    oldlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));

    greenlook = new Appearance();
    objColor = new Color3f(0.0f, 0.8f, 0.0f);
    greenlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    bluelook = new Appearance();
    objColor = new Color3f(0.0f, 0.0f, 0.8f);
    bluelook.setMaterial(new Material(objColor, black, objColor, white, 50.0f));
    for (int i = 0; i < 6; i++) {
        switch (i) {
        case 0:
            sph[i] = new Sphere(size * 1.15f, redlook);
            break;
        case 1:
            sph[i] = new Sphere(size * 1.1f, greenlook);
            break;
        default:
            sph[i] = new Sphere(size, bluelook);
            break;
        }
        sph[i].setPickable(false);
        sphTrans[i] = new TransformGroup();
        sphTrans[i].setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        sphTrans[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        // Add sphere, transform
        branchGroup.addChild(sphTrans[i]);
        sphTrans[i].addChild(sph[i]);
    }
}

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: {/*from   ww  w. j a v a  2 s . com*/
        // 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:BehaviorTest.java

public void addBehaviorToParentGroup(Group nodeParentGroup) {
    nodeParentGroup.addChild(this);

    m_TransformGroup = new TransformGroup();
    m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    m_BoundsSwitch = new Switch();
    m_BoundsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    Appearance app = new Appearance();

    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    app.setPolygonAttributes(polyAttrbutes);

    m_BoundsSwitch.addChild(new Sphere(1, app));

    ColorCube cube = new ColorCube();
    cube.setAppearance(app);/*from  w  ww. j  a  va  2  s  .com*/

    Group g = new Group();
    g.addChild(cube);
    m_BoundsSwitch.addChild(g);

    m_BoundsSwitch.setWhichChild(Switch.CHILD_NONE);

    m_TransformGroup.addChild(m_BoundsSwitch);
    nodeParentGroup.addChild(m_TransformGroup);
}

From source file:CuboidTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);/*from w ww .j av  a  2s  .com*/

    // create an appearance
    Appearance ap = new Appearance();

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    ap.setPolygonAttributes(polyAttrbutes);

    objTrans.addChild(new Cuboid(50, 30, 20, ap));
    objTrans.addChild(new Box(25, 15, 10, ap));

    objRoot.addChild(objTrans);

    return objRoot;
}