Example usage for javax.media.j3d TexCoordGeneration TEXTURE_COORDINATE_2

List of usage examples for javax.media.j3d TexCoordGeneration TEXTURE_COORDINATE_2

Introduction

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

Prototype

int TEXTURE_COORDINATE_2

To view the source code for javax.media.j3d TexCoordGeneration TEXTURE_COORDINATE_2.

Click Source Link

Document

Generates 2D texture coordinates (S and T).

Usage

From source file:SimpleTextureGen.java

/**
 * This defines the appearance for the shape using a texture. It uses a
 * TextureLoader to load the texture image from an external file and a
 * TexCoordGeneration to define the texture coordinates.
 * // w w w  . jav  a2s . c om
 * @return Appearance that uses a texture.
 */
protected Appearance DefineAppearance() {
    //This is used to automatically define the texture coordinates.
    //The coordinates are generated in object coordinates, but by
    //commented out the line with 'OBJECT_LINEAR' and uncommenting
    //the line 'EYE_LINEAR' the program will use eye coordinates.
    TexCoordGeneration textCoorder = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
            //TexCoordGeneration.EYE_LINEAR,
            TexCoordGeneration.TEXTURE_COORDINATE_2);
    //Load the texture from the external image file
    TextureLoader textLoad = new TextureLoader("housebrick.jpg", this);
    //Access the image from the loaded texture
    ImageComponent2D textImage = textLoad.getImage();
    //Create a two dimensional texture
    Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGB, textImage.getWidth(),
            textImage.getHeight());
    //Set the texture from the image loaded
    texture.setImage(0, textImage);
    //Create the appearance that will use the texture
    Appearance app = new Appearance();
    app.setTexture(texture);
    //Pass the coordinate generator to the appearance
    app.setTexCoordGeneration(textCoorder);
    //Define how the texture will be mapped onto the surface
    //by creating the appropriate texture attributes
    TextureAttributes textAttr = new TextureAttributes();
    textAttr.setTextureMode(TextureAttributes.REPLACE);
    app.setTextureAttributes(textAttr);
    app.setMaterial(new Material());
    return app;
}

From source file:TexCoordTest.java

void createAppearance(double yMaxHeight) {
    // create an Appearance and assign a Material
    m_Appearance = new Appearance();
    m_Appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE);

    Color3f black = new Color3f(0, 0.2f, 0);
    Color3f objColor = new Color3f(0.1f, 0.7f, 0.2f);
    m_Appearance.setMaterial(new Material(objColor, black, objColor, black, 0.8f));

    // load the texture image
    TextureLoader texLoader = new TextureLoader("stripes.gif", Texture.RGB, this);

    // clamp the coordinates in the S dimension, that way they
    // will not wrap when the calculated texture coordinate falls outside
    // the range 0 to 1. When the texture coordinate is outside this range
    // no texture coordinate will be used
    Texture tex = texLoader.getTexture();
    tex.setBoundaryModeS(Texture.CLAMP);

    // assign the texute image to the appearance
    m_Appearance.setTexture(tex);/*www.j  a  v  a 2  s.c om*/

    // create the TexCoordGeneration object.
    // we are only using 1D texture coordinates (S) - texture coordinates
    // are calculated from a vertex's distance from the Y = 0 plane
    // the 4th parameter to the Vector4f is the distance in *texture
    // coordinates*
    // that we shift the texture coordinates by (i.e. Y = 0 corresponds to S
    // = 0.5)
    TexCoordGeneration texGen = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
            TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(0, (float) (1.0 / (2 * yMaxHeight)), 0, 0.5f),
            new Vector4f(0, 0, 0, 0), new Vector4f(0, 0, 0, 0));

    // create our "non-live" TexCoordGeneration object so we
    // can update the "genMode" parameter after we go live.
    m_TexGen = (TexCoordGeneration) texGen.cloneNodeComponent(true);

    // assign the TexCoordGeneration to the Appearance
    m_Appearance.setTexCoordGeneration(texGen);

    // we just glue the texture image to the surface, we are not
    // blending or modulating the texture image based on material
    // attributes. You can experiment with MODULATE or BLEND.
    TextureAttributes texAttribs = new TextureAttributes();
    texAttribs.setTextureMode(TextureAttributes.DECAL);
    m_Appearance.setTextureAttributes(texAttribs);
}

From source file:AppearanceTest.java

public void onTEXTURE_COORDINATE_2() {
    getTexCoordGeneration().setFormat(TexCoordGeneration.TEXTURE_COORDINATE_2);
    assignToAppearance();
}

From source file:AppearanceExplorer.java

void setTexGen() {
    texGen = new TexCoordGeneration(mode, TexCoordGeneration.TEXTURE_COORDINATE_2, planeS, planeT);
    texGen.setCapability(TexCoordGeneration.ALLOW_ENABLE_WRITE);
    texGen.setEnable(enable);/*from   ww w  .java 2s . c o  m*/
    app.setTexCoordGeneration(texGen);
}