Example usage for javax.media.j3d Appearance setTexCoordGeneration

List of usage examples for javax.media.j3d Appearance setTexCoordGeneration

Introduction

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

Prototype

public void setTexCoordGeneration(TexCoordGeneration texCoordGeneration) 

Source Link

Document

Sets the texCoordGeneration object to the specified object.

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.
 * /*from  w w  w .j a va 2  s  .c  o m*/
 * @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;
}