Example usage for javax.media.j3d TriangleArray setTextureCoordinate

List of usage examples for javax.media.j3d TriangleArray setTextureCoordinate

Introduction

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

Prototype

public void setTextureCoordinate(int texCoordSet, int index, float texCoord[]) 

Source Link

Document

Sets the texture coordinate associated with the vertex at the specified index in the specified texture coordinate set for this object.

Usage

From source file:AppearanceTest.java

public Tetrahedron() {
    int i;/*from   ww w. j a  v a  2s .  c o  m*/

    TriangleArray tetra = new TriangleArray(12,
            TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2);

    tetra.setCoordinates(0, verts);
    for (i = 0; i < 12; i++) {
        tetra.setTextureCoordinate(0, i, texCoord[i % 3]);
    }

    int face;
    Vector3f normal = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Point3f[] pts = new Point3f[3];
    for (i = 0; i < 3; i++)
        pts[i] = new Point3f();

    for (face = 0; face < 4; face++) {
        tetra.getCoordinates(face * 3, pts);
        v1.sub(pts[1], pts[0]);
        v2.sub(pts[2], pts[0]);
        normal.cross(v1, v2);
        normal.normalize();
        for (i = 0; i < 3; i++) {
            tetra.setNormal((face * 3 + i), normal);
        }
    }
    this.setGeometry(tetra);
    this.setAppearance(new Appearance());
}

From source file:TickTockPicking.java

public Tetrahedron() {
    int i;//from ww w  . j av a 2 s  .c  om

    TriangleArray tetra = new TriangleArray(12,
            TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2);

    tetra.setCoordinates(0, verts);
    for (i = 0; i < 12; i++) {
        tetra.setTextureCoordinate(0, i, texCoord[i % 3]);
    }

    int face;
    Vector3f normal = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Point3f[] pts = new Point3f[3];
    for (i = 0; i < 3; i++)
        pts[i] = new Point3f();

    for (face = 0; face < 4; face++) {
        tetra.getCoordinates(face * 3, pts);
        v1.sub(pts[1], pts[0]);
        v2.sub(pts[2], pts[0]);
        normal.cross(v1, v2);
        normal.normalize();
        for (i = 0; i < 3; i++) {
            tetra.setNormal((face * 3 + i), normal);
        }
    }

    tetra.setCapability(Geometry.ALLOW_INTERSECT);

    this.setGeometry(tetra);
    this.setAppearance(new Appearance());
}