Hey man I’ve used IndexedTriangleArray in PPL and the water demo
public Shape3D getJCDTorus(float OuterRadius, float InnerRadius , int Slice ,
int Stack , float repeatTextureS, float repeatTextureT){
TexCoord3f texCoords[] = new TexCoord3f[(Slice + 1)*(Stack + 1)],
torusTangents[] = new TexCoord3f[(Slice + 1)*(Stack + 1)],
torusBinormals[] = new TexCoord3f[(Slice + 1)*(Stack + 1)];
Vector3f torusNormals[] = new Vector3f[(Slice + 1)*(Stack + 1)];
Point3f torusVertices[] = new Point3f[(Slice + 1)*(Stack + 1)];
float x = 0,
z = 0,
temp = 0,
sliceStep = 2f*(float)Math.PI/Slice,
stackStep = 2f*(float)Math.PI/Stack,
sliceAngle = 0,
stackAngle = 0,
filterTriangles = 0;
int indices[] = new int[Slice*Stack*6];
for(int i = 0; i<(Slice + 1); i++){
if(i == Slice )
sliceAngle = 0;
x = (float)Math.sin(sliceAngle);
z = (float)Math.cos(sliceAngle);
torusVertices[i] = new Point3f(OuterRadius - InnerRadius*x,
0 ,
InnerRadius*z );
torusNormals[i] = new Vector3f(-x,0,z);
texCoords[i] = new TexCoord3f(0, (float)i/Slice*repeatTextureT,0);
sliceAngle += sliceStep;
}
for(int a = 1, p = Slice + 1; a < Stack + 1; a++){
stackAngle += stackStep;
if(a == Stack)
stackAngle = 0;
for(int i = 0; i< Slice +1 ; i++, p++){
rotateTupleZ(torusVertices[p] = new Point3f() , torusVertices[i], stackAngle);
rotateTupleZ(torusNormals[p] = new Vector3f(), torusNormals[i] , stackAngle);
texCoords[p] = new TexCoord3f((float)a/Stack*repeatTextureS,
(float)i/Slice*repeatTextureT,0);
}
}
for(int j=0; j<Stack; j++)
for(int i=0; i<Slice; i++){
indices[((j*Slice+i)*2)*3+0] = j*(Slice+1)+i;
indices[((j*Slice+i)*2)*3+1] = (j+1)*(Slice+1)+i;
indices[((j*Slice+i)*2)*3+2] = j*(Slice+1)+i+1;
indices[((j*Slice+i)*2+1)*3+0]= j*(Slice+1)+i+1;
indices[((j*Slice+i)*2+1)*3+1]= (j+1)*(Slice+1)+i;
indices[((j*Slice+i)*2+1)*3+2]= (j+1)*(Slice+1)+i+1;
}
OjectStructure.generateTBN(indices , torusVertices , torusNormals,
torusTangents, torusBinormals, texCoords );
createNormalVectorsShape(torusVertices, torusNormals,
torusTangents, torusBinormals);
IndexedTriangleArray torusGeometry = new IndexedTriangleArray(torusVertices.length,
GeometryArray.TEXTURE_COORDINATE_3 |
GeometryArray.COORDINATES |
GeometryArray.NORMALS,
3,
new int[]{0,1, 2},
indices.length);
torusGeometry.setIndex(indices);
torusGeometry.setNormals(0, torusNormals);
torusGeometry.setCoordinates(0, torusVertices);
torusGeometry.setValidIndexCount(indices.length);
torusGeometry.setTextureCoordinates(0,0, texCoords);
torusGeometry.setTextureCoordinates(1,0, torusTangents);
torusGeometry.setTextureCoordinates(2,0, torusBinormals);
polygonAttributes = new PolygonAttributes();
polygonAttributes.setPolygonMode(PolygonAttributes.POLYGON_FILL);
setTextureAttributes();
setTextureUnitStateDot3BumpMap();
torusAppearance.setPolygonAttributes(polygonAttributes);
vertexShader = new VertexProgram(getShaderCode("Data/ppl.jcd"),lightLocation);
torusAppearance.setVertexShaderProgram(vertexShader);
return new Shape3D(torusGeometry,torusAppearance);
}