Example usage for javax.media.j3d TexCoordGeneration cloneNodeComponent

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

Introduction

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

Prototype

public NodeComponent cloneNodeComponent(boolean forceDuplicate) 

Source Link

Document

Used to create a new instance of a NodeComponent object.

Usage

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);/*from w ww.jav a2  s .c o m*/

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