Example usage for javax.media.j3d PolygonAttributes POLYGON_FILL

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

Introduction

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

Prototype

int POLYGON_FILL

To view the source code for javax.media.j3d PolygonAttributes POLYGON_FILL.

Click Source Link

Document

Render polygonal primitives by filling the interior of the polygon.

Usage

From source file:AppearanceExplorer.java

PolygonAttributesEditor(PolygonAttributes init) {
    super(BoxLayout.Y_AXIS);
    polygonAttr = init;//w  ww. ja  va  2s . co  m
    polygonMode = polygonAttr.getPolygonMode();
    cullFace = polygonAttr.getCullFace();
    polygonOffset = polygonAttr.getPolygonOffset();
    polygonOffsetFactor = polygonAttr.getPolygonOffsetFactor();
    backFaceNormalFlip = polygonAttr.getBackFaceNormalFlip();

    String[] modeNames = { "POLYGON_POINT", "POLYGON_LINE", "POLYGON_FILL", };
    int[] modeValues = { PolygonAttributes.POLYGON_POINT, PolygonAttributes.POLYGON_LINE,
            PolygonAttributes.POLYGON_FILL, };
    IntChooser modeChooser = new IntChooser("Mode:", modeNames, modeValues, polygonMode);
    modeChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            polygonMode = event.getValue();
            polygonAttr.setPolygonMode(polygonMode);
        }
    });
    add(modeChooser);

    String[] cullNames = { "CULL_NONE", "CULL_BACK", "CULL_FRONT", };
    int[] cullValues = { PolygonAttributes.CULL_NONE, PolygonAttributes.CULL_BACK,
            PolygonAttributes.CULL_FRONT, };
    IntChooser cullChooser = new IntChooser("Cull:", cullNames, cullValues, cullFace);
    cullChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            cullFace = event.getValue();
            polygonAttr.setCullFace(cullFace);
        }
    });
    add(cullChooser);

    FloatLabelJSlider polygonOffsetSlider = new FloatLabelJSlider("Offset", 0.1f, 0.0f, 2.0f, polygonOffset);
    polygonOffsetSlider.setMajorTickSpacing(1.0f);
    polygonOffsetSlider.setPaintTicks(true);
    polygonOffsetSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            polygonOffset = e.getValue();
            polygonAttr.setPolygonOffset(polygonOffset);
        }
    });
    add(polygonOffsetSlider);

    LogFloatLabelJSlider polygonOffsetFactorSlider = new LogFloatLabelJSlider("Offset Factor", 0.1f, 10000.0f,
            polygonOffsetFactor);
    polygonOffsetFactorSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            polygonOffsetFactor = e.getValue();
            polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor);
        }
    });
    add(polygonOffsetFactorSlider);

    JCheckBox backFaceNormalFlipCheckBox = new JCheckBox("BackFaceNormalFlip", backFaceNormalFlip);
    backFaceNormalFlipCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            backFaceNormalFlip = checkbox.isSelected();
            polygonAttr.setBackFaceNormalFlip(backFaceNormalFlip);
        }
    });
    // no ablity to change without replcing polygon attributes
    backFaceNormalFlipCheckBox.setEnabled(false);

    add(new LeftAlignComponent(backFaceNormalFlipCheckBox));
}

From source file:Demo3D.java

/**
 * This methode serves to construct the earth.
 * /*from  w w  w .  ja v  a 2s  .c om*/
 * @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;
}