Example usage for javax.media.j3d IndexedTriangleStripArray IndexedTriangleStripArray

List of usage examples for javax.media.j3d IndexedTriangleStripArray IndexedTriangleStripArray

Introduction

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

Prototype

public IndexedTriangleStripArray(int vertexCount, int vertexFormat, int indexCount, int[] stripIndexCounts) 

Source Link

Document

Constructs an empty IndexedTriangleStripArray object using the specified parameters.

Usage

From source file:GeometryByReferenceNIOBuffer.java

public GeometryArray createGeometry(int type) {
    GeometryArray tetra = null;/* www .j  a  va2 s . com*/
    if (type == 1) {
        tetra = new TriangleArray(12, TriangleArray.COORDINATES | TriangleArray.COLOR_3
                | TriangleArray.BY_REFERENCE | TriangleArray.USE_NIO_BUFFER);

        tetra.setCoordRefBuffer(floatBufferCoord);
        tetra.setColorRefBuffer(floatBufferColor);

    } else if (type == 2) {
        tetra = new TriangleStripArray(
                12, TriangleStripArray.COORDINATES | TriangleStripArray.COLOR_3
                        | TriangleStripArray.BY_REFERENCE | TriangleStripArray.USE_NIO_BUFFER,
                stripVertexCounts);
        tetra.setCoordRefBuffer(floatBufferCoord);
        tetra.setColorRefBuffer(floatBufferColor);

    } else if (type == 3) { // Indexed Geometry
        tetra = new IndexedTriangleArray(4,
                IndexedTriangleArray.COORDINATES | IndexedTriangleArray.COLOR_3
                        | IndexedTriangleArray.BY_REFERENCE | IndexedTriangleArray.USE_NIO_BUFFER,
                //IndexedTriangleStripArray.USE_COORD_INDEX_ONLY,
                12);
        tetra.setCoordRefBuffer(indexedFloatBufferCoord);
        tetra.setColorRefBuffer(indexedFloatBufferColor);
        ((IndexedTriangleArray) tetra).setCoordinateIndices(0, indices);
        ((IndexedTriangleArray) tetra).setColorIndices(0, indices);
    } else if (type == 4) { // Indexed strip geometry
        tetra = new IndexedTriangleStripArray(4,
                IndexedTriangleStripArray.COORDINATES | IndexedTriangleStripArray.COLOR_3
                        | IndexedTriangleStripArray.BY_REFERENCE | IndexedTriangleStripArray.USE_NIO_BUFFER
                        | IndexedTriangleStripArray.USE_COORD_INDEX_ONLY,
                12, stripVertexCounts);
        tetra.setCoordRefBuffer(indexedFloatBufferCoord);
        tetra.setColorRefBuffer(indexedFloatBufferColor);
        ((IndexedTriangleStripArray) tetra).setCoordinateIndices(0, indices);
        ((IndexedTriangleStripArray) tetra).setColorIndices(0, indices);
    }

    if (tetra != null)
        tetra.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
    return tetra;
}

From source file:GeometryByReferenceTest.java

public GeometryArray createGeometry(int type) {
    GeometryArray tetra = null;// w  w  w  .  ja  v a  2  s.  c  om
    if (type == 1) {
        tetra = new TriangleArray(12,
                TriangleArray.COORDINATES | TriangleArray.COLOR_3 | TriangleArray.BY_REFERENCE);

        tetra.setCoordRefFloat(floatVerts);
        tetra.setColorRefFloat(floatClrs);

    } else if (type == 2) {
        tetra = new TriangleStripArray(12,
                TriangleStripArray.COORDINATES | TriangleStripArray.COLOR_3 | TriangleStripArray.BY_REFERENCE,
                stripVertexCounts);
        tetra.setCoordRefFloat(floatVerts);
        tetra.setColorRefFloat(floatClrs);

    } else if (type == 3) { // Indexed Geometry
        tetra = new IndexedTriangleArray(4, IndexedTriangleArray.COORDINATES | IndexedTriangleArray.COLOR_3
                | IndexedTriangleArray.BY_REFERENCE, 12);
        tetra.setCoordRefFloat(indexedFloatVerts);
        tetra.setColorRefFloat(indexedFloatClrs);
        ((IndexedTriangleArray) tetra).setCoordinateIndices(0, indices);
        ((IndexedTriangleArray) tetra).setColorIndices(0, indices);
    } else if (type == 4) { // Indexed strip geometry
        tetra = new IndexedTriangleStripArray(4, IndexedTriangleStripArray.COORDINATES
                | IndexedTriangleStripArray.COLOR_3 | IndexedTriangleStripArray.BY_REFERENCE, 12,
                stripVertexCounts);
        tetra.setCoordRefFloat(indexedFloatVerts);
        tetra.setColorRefFloat(indexedFloatClrs);
        ((IndexedTriangleStripArray) tetra).setCoordinateIndices(0, indices);
        ((IndexedTriangleStripArray) tetra).setColorIndices(0, indices);
    }

    if (tetra != null)
        tetra.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);
    return tetra;
}

From source file:ExBackgroundImage.java

private void rebuild() {
    // Build a shape
    if (shape == null) {
        shape = new Shape3D();
        shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
        shape.setAppearance(mainAppearance);
        addChild(shape);/*from w ww  .j a  v  a  2s .co m*/
    } else {
        shape.setAppearance(mainAppearance);
    }

    if (xDimension < 2 || zDimension < 2 || heights == null || heights.length < 4) {
        tristrip = null;
        shape.setGeometry(null);
        return;
    }

    // Create a list of coordinates, one per grid row/column
    double[] coordinates = new double[xDimension * zDimension * 3];
    double x, z;
    int n = 0, k = 0;
    z = ((double) (zDimension - 1)) * zSpacing / 2.0; // start at front edge
    for (int i = 0; i < zDimension; i++) {
        x = -((double) (xDimension - 1)) * xSpacing / 2.0;// start at left
        // edge
        for (int j = 0; j < xDimension; j++) {
            coordinates[n++] = x;
            coordinates[n++] = heights[k++];
            coordinates[n++] = z;
            x += xSpacing;
        }
        z -= zSpacing;
    }

    // Create a list of normals, one per grid row/column
    float[] normals = new float[xDimension * zDimension * 3];
    Vector3f one = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f two = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f norm = new Vector3f(0.0f, 0.0f, 0.0f);
    n = 0;
    k = 0;
    for (int i = 0; i < zDimension - 1; i++) {
        for (int j = 0; j < xDimension - 1; j++) {
            // Vector to right in X
            one.set((float) xSpacing, (float) (heights[k + 1] - heights[k]), 0.0f);

            // Vector back in Z
            two.set(0.0f, (float) (heights[k + xDimension] - heights[k]), (float) -zSpacing);

            // Cross them to get the normal
            norm.cross(one, two);
            normals[n++] = norm.x;
            normals[n++] = norm.y;
            normals[n++] = norm.z;
            k++;
        }

        // Last normal in row is a copy of the previous one
        normals[n] = normals[n - 3]; // X
        normals[n + 1] = normals[n - 2]; // Y
        normals[n + 2] = normals[n - 1]; // Z
        n += 3;
        k++;
    }

    // Last row of normals is a copy of the previous row
    for (int j = 0; j < xDimension; j++) {
        normals[n] = normals[n - xDimension * 3]; // X
        normals[n + 1] = normals[n - xDimension * 3 + 1]; // Y
        normals[n + 2] = normals[n - xDimension * 3 + 2]; // Z
        n += 3;
    }

    // Create a list of texture coordinates, one per grid row/column
    float[] texcoordinates = new float[xDimension * zDimension * 2];
    float deltaS = 1.0f / (float) (xDimension - 1);
    float deltaT = 1.0f / (float) (zDimension - 1);
    float s = 0.0f;
    float t = 0.0f;
    n = 0;
    for (int i = 0; i < zDimension; i++) {
        s = 0.0f;
        for (int j = 0; j < xDimension; j++) {
            texcoordinates[n++] = s;
            texcoordinates[n++] = t;
            s += deltaS;
        }
        t += deltaT;
    }

    // Create a list of triangle strip indexes. Each strip goes
    // down one row (X direction) of the elevation grid.
    int[] indexes = new int[xDimension * (zDimension - 1) * 2];
    int[] stripCounts = new int[zDimension - 1];
    n = 0;
    k = 0;
    for (int i = 0; i < zDimension - 1; i++) {
        stripCounts[i] = xDimension * 2;
        for (int j = 0; j < xDimension; j++) {
            indexes[n++] = k + xDimension;
            indexes[n++] = k;
            k++;
        }
    }

    // Create geometry for collection of triangle strips, one
    // strip per row of the elevation grid
    tristrip = new IndexedTriangleStripArray(coordinates.length,
            GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2,
            indexes.length, stripCounts);
    tristrip.setCoordinates(0, coordinates);
    tristrip.setNormals(0, normals);
    tristrip.setTextureCoordinates(0, texcoordinates);
    tristrip.setCoordinateIndices(0, indexes);
    tristrip.setNormalIndices(0, indexes);
    tristrip.setTextureCoordinateIndices(0, indexes);

    // Set the geometry for the shape
    shape.setGeometry(tristrip);
}