Example usage for javax.media.j3d PolygonAttributes PolygonAttributes

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

Introduction

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

Prototype

public PolygonAttributes() 

Source Link

Document

Constructs a PolygonAttributes object with default parameters.

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 ww  . jav a  2  s.  c om
 * @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:ModelClipTest.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);/*www.  j a v  a2s  .  c  o  m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // This Transformgroup is used by the mouse manipulators to
    // move the CYlinder.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn1 = new Vector4d(0.0, 1.0, 0.0, 0.0);
    Vector4d eqn2 = new Vector4d(1.0, 1.0, 0.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn1);
    mc.setPlane(2, eqn2);
    mc.setEnable(1, true);
    mc.setEnable(2, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(1.0f, 2.0f, ap);
    objTrans.addChild(CylinderObj);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

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

    return objRoot;
}

From source file:Text2DTest.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);//from   w  w w  .  j a  va  2  s .  c om
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

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

    TransformGroup textTranslationGroup;
    Transform3D textTranslation;
    float yPos = -.5f;
    Shape3D textObject = new Text2D("Rotating Yellow Text", new Color3f(1f, 1f, 0f), "Serif", 60, Font.BOLD);
    Appearance app = textObject.getAppearance();

    PolygonAttributes pa = app.getPolygonAttributes();
    if (pa == null)
        pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    if (app.getPolygonAttributes() == null)
        app.setPolygonAttributes(pa);
    objTrans.addChild(textObject);

    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(objTrans);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    /* Blue 40point text */
    textObject = new Text2D("Blue 40point Text", new Color3f(0f, 0f, 1f), "Serif", 40, Font.BOLD);
    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(textObject);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    /* Green italic text */
    textObject = new Text2D("Green Italic Text", new Color3f(0f, 1f, 0f), "Serif", 70, Font.ITALIC);
    textTranslation = new Transform3D();
    textTranslation.setTranslation(new Vector3f(0f, yPos, 0f));
    textTranslationGroup = new TransformGroup(textTranslation);
    textTranslationGroup.addChild(textObject);
    objScale.addChild(textTranslationGroup);
    yPos += .5f;

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    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);

    return objRoot;
}

From source file:ModelClipTest2.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);/*from   w  w w .  ja v  a2  s  .  c om*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    //Shine it with two colored lights.
    Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);

    AmbientLight lgt0 = new AmbientLight(true, lColor2);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt0.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt0);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    // Create a Transformgroup for the geometry
    TransformGroup objRot = new TransformGroup();
    Transform3D t3d1 = new Transform3D();
    AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f);
    t3d1.setRotation(rot1);
    objRot.setTransform(t3d1);
    objScale.addChild(objRot);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap);
    objRot.addChild(CylinderObj);

    //Create a box
    Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap);
    objRot.addChild(BoxObj);

    // This Transformgroup is used by the mouse manipulators to
    // move the model clip planes.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRot.addChild(objTrans);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn);
    mc.setEnable(1, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

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

    return objRoot;
}

From source file:FarbWurfelAsQuads.java

/**
 * Wurfeldarstellung/*from   ww w  .ja v a 2  s .c  o m*/
 * 
 * @return Appearance
 */
private Appearance makeAppearance() {
    Appearance a = new Appearance();
    PolygonAttributes p = new PolygonAttributes();
    p.setCullFace(PolygonAttributes.CULL_NONE);
    a.setPolygonAttributes(p);
    return a;
}

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  . j av  a 2  s.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: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 w  w.  j ava  2s  .  co  m

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

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  www. ja  va2  s  .c o  m*/
        // 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 ww w. j av a  2s.  c om
    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: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);/*from   w ww  .  j  a va  2s .  c o m*/

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