Here is my method for creating the mesh. Long post but wanted to include some of the data. Nothing is null, or oversized. I understand my mesh is messed up. I am having a hard time figuring out why/where. I understand my texCoords may not be correct, but they should be different enough so that triangles do not have vertexes with the same cords.
[java]
public static int calcNumVertices(Brace[] trackBraces){
int braceVertices=0;
for (int h = 1; h < trackBraces.length; h++) {
int bracePointsLen = trackBraces[h - 1].getBracePointPositions().length;
braceVertices += bracePointsLen*6;
}
return braceVertices;
}
public static Mesh newTrackGeom() {
//Setup mesh
Mesh mesh = new Mesh();
mesh.setMode(Mesh.Mode.Triangles);
mesh.setStatic();
//Create Test Track
Track track = TrackOne.createTrack();
//All of the track sections
Brace[] trackBraces = track.getGraphicsSection(0, track.size());
int verticesNum = calcNumVertices(trackBraces);
Vector3f[] vertices = new Vector3f[verticesNum];
Vector2f[] texCoord = new Vector2f[verticesNum];
float[] normals = new float[verticesNum*3];
int[] indexes = new int[verticesNum];
int count = 0;
int idxCount = 0;
int ncount = 0;
int texcount = 0;
for(int h = 1; h < trackBraces.length; h++){
Vector3 normal = new Vector3();
Vector3 edge1 = new Vector3();
Vector3 edge2 = new Vector3();
Vector3[] brace1Pts = trackBraces[h - 1].getBracePointPositions();
Vector3[] brace2Pts = trackBraces[h].getBracePointPositions();
Vector3 prevPt1 = brace1Pts[brace1Pts.length - 1];
Vector3 prevPt2 = brace2Pts[brace2Pts.length - 1];
Vector3 currPt1, currPt2;
for(int f = 0; f < brace1Pts.length; f++){
currPt1 = brace1Pts[f];
currPt2 = brace2Pts[f];
Vector3.subtract(currPt2, currPt1, edge1);
Vector3.subtract(currPt1, prevPt1, edge2);
Vector3.cross(edge2, edge1, normal);
Vector3.normalize(normal);
//Vectors to make each quad.
Vector3f vec1 = new Vector3f(prevPt1.x, prevPt1.y, prevPt1.z);
Vector3f vec2 = new Vector3f(currPt1.x, currPt1.y, currPt1.z);
Vector3f vec3 = new Vector3f(currPt2.x, currPt2.y, currPt2.z);
Vector3f vec4 = new Vector3f(prevPt2.x, prevPt2.y, prevPt2.z);
//Set TexCoord Array
texCoord[texcount++] = new Vector2f(0,0);
texCoord[texcount++] = new Vector2f(1,0);
texCoord[texcount++] = new Vector2f(0,1);
texCoord[texcount++] = new Vector2f(1,1);
texCoord[texcount++] = new Vector2f(0,1);
texCoord[texcount++] = new Vector2f(0,0);
//Set vertices, indexes, and normals.
//Note: for testing I am setting more vertices than needed.
vertices[count] = vec1;
indexes[idxCount++] = count;
setNormal(normals, normal,ncount);
ncount+=3;
count++;
vertices[count] = vec2;
indexes[idxCount++] = count;
setNormal(normals, normal,ncount);
ncount+=3;
count++;
vertices[count] = vec3;
indexes[idxCount++] = count;
setNormal(normals, normal,ncount);
ncount+=3;
count++;
vertices[count] = vec3;
indexes[idxCount++] = count-1;
setNormal(normals, normal,ncount);
ncount+=3;
count++;
vertices[count] = vec4;
indexes[idxCount++]= count;
setNormal(normals, normal,ncount);
ncount+=3;
count++;
vertices[count] = vec1;
indexes[idxCount++] = count-5;
setNormal(normals, normal,ncount);
ncount+=3;
count++;
prevPt1 = currPt1;
prevPt2 = currPt2;
}
}
//Printing loops here
//Set the vertex position, index, texture, and normal buffers
mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
mesh.updateBound();
mesh.updateCounts();
return mesh;
}
}
[/java]
Sample output:
Index Array:
Indexes[0] = 0
Indexes[1] = 1
Indexes[2] = 2
Indexes[3] = 2
Indexes[4] = 4
Indexes[5] = 0
Indexes[6] = 6
Indexes[7] = 7
Indexes[8] = 8
Indexes[9] = 8
Indexes[10] = 10
Indexes[11] = 6
Indexes[12] = 12
Indexes[13] = 13
Indexes[14] = 14
Indexes[15] = 14
Indexes[16] = 16
Indexes[17] = 12
Indexes[18] = 18
Indexes[19] = 19
Indexes[20] = 20
Vertex Array:
Vertices[0] = (-2.0, -1.5, 0.0)
Vertices[1] = (2.0, -1.5, 0.0)
Vertices[2] = (2.0, -1.5, -10.0)
Vertices[3] = (2.0, -1.5, -10.0)
Vertices[4] = (-2.0, -1.5, -10.0)
Vertices[5] = (-2.0, -1.5, 0.0)
Vertices[6] = (2.0, -1.5, 0.0)
Vertices[7] = (3.0, -1.0, 0.0)
Vertices[8] = (3.0, -1.0, -10.0)
Vertices[9] = (3.0, -1.0, -10.0)
Vertices[10] = (2.0, -1.5, -10.0)
Vertices[11] = (2.0, -1.5, 0.0)
Vertices[12] = (3.0, -1.0, 0.0)
Vertices[13] = (3.0, 1.0, 0.0)
Vertices[14] = (3.0, 1.0, -10.0)
Vertices[15] = (3.0, 1.0, -10.0)
Vertices[16] = (3.0, -1.0, -10.0)
Vertices[17] = (3.0, -1.0, 0.0)
Vertices[18] = (3.0, 1.0, 0.0)
Vertices[19] = (2.0, 1.5, 0.0)
Vertices[20] = (2.0, 1.5, -10.0)
Texture Array:
texCoord[0] = (0.0, 0.0)
texCoord[1] = (1.0, 0.0)
texCoord[2] = (0.0, 1.0)
texCoord[3] = (1.0, 1.0)
texCoord[4] = (0.0, 1.0)
texCoord[5] = (0.0, 0.0)
texCoord[6] = (0.0, 0.0)
texCoord[7] = (1.0, 0.0)
texCoord[8] = (0.0, 1.0)
texCoord[9] = (1.0, 1.0)
texCoord[10] = (0.0, 1.0)
Thanks again.