I just found out I gotta unshare MS3D Vertices, what a pain!!! I have to create normals/tex coords for all the vertices the file structure doesn't cover!
How lame!!!
Bleh, heres code..
Here's what I did:
Code:
void TriangleMesh::UnshareVertices()
{
int verx, trix, i;
int nTriangles;
int _numVertices = this->numVertices;
float s, t;
int material;
for (verx=0; verx<this->numVertices; verx++)
{
nTriangles = 0;
for (trix=0; trix<this->numTriangles; trix++)
{
for (i=0; i<3; i++)
{
if (verx == triangles [trix].vIndices [i])
{
nTriangles++;
if (nTriangles == 1)
{
arrayBone [verx] = vertices [verx].boneID;
arrayVertex [verx] = vertices [verx].v;
arrayVertexSkel [verx] = vertices [verx].vSkel;
// Save s/t and material# for later reference
s = triangles [trix].s [i];
t = triangles [trix].t [i];
material = groups [triangles [trix].groupIndex].materialIndex;
// Set s/t, normal and skeleton normal from triangle to this vertex array element
arrayTexCoord [(verx*2)] = triangles [trix].s [i];
arrayTexCoord [(verx*2)+1] = triangles [trix].t [i];
arrayNormal [verx] = triangles [trix].vNormals [i];
arrayNormalSkel [verx] = triangles [trix].vNormalsSkel [i];
}
else
{
if ((triangles [trix].s [i] != s || triangles [trix].t [i] != t) &&
(groups [triangles [trix].groupIndex].materialIndex == material))
{
// Create new Vertex:
// * Update vertex index for this triangle
triangles [trix].vIndices [i] = _numVertices;
// * Add bone ID, x/y/z, skeleton x/y/z, s/t, normal and skeletion normal to vertex array
arrayBone [_numVertices] = vertices [verx].boneID;
arrayVertex [_numVertices] = vertices [verx].v;
arrayVertexSkel [_numVertices] = vertices [verx].vSkel;
arrayTexCoord [(_numVertices*2)] = triangles [trix].s [i];
arrayTexCoord [(_numVertices*2)+1] = triangles [trix].t [i];
arrayNormal [_numVertices] = triangles [trix].vNormals [i];
arrayNormalSkel [_numVertices] = triangles [trix].vNormalsSkel [i];
// * Increment max vertex index
_numVertices++;
}
}
}
}
}
}
this->numVertices = _numVertices;
}
For each group in the MS3D file, I create an array of indexes, with the size of the # of triangles in that group * 3, and fill those with the list of vertices I just created in the code above.
Code:
for (int i=0; i<numGroups; i++)
{
groups[i].indexArray = new unsigned short[groups[i].numTriangles * 3];
for (int j=0; j<groups [i].numTriangles; j++)
{
TriangleMesh::Triangle *tri = &triangles[groups[i].triangleIndices[j]];
groups[i].indexArray[(j*3)] = tri->vIndices[0];
groups[i].indexArray[(j*3)+1] = tri->vIndices[1];
groups[i].indexArray[(j*3)+2] = tri->vIndices[2];
}
}
Then, before I start rendering, I:
Code:
glTexCoordPointer(2, GL_FLOAT, 0, arrayTexCoord);
glNormalPointer(GL_FLOAT, 0, (GLfloat *)arrayNormal);
glVertexPointer(3, GL_FLOAT, 0, (GLfloat *)arrayVertex);
THEN, for each group, I render with:
Code:
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDrawElements(GL_TRIANGLES, groups[grpx].numTriangles * 3, GL_UNSIGNED_SHORT, groups[grpx].indexArray);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
I need to change it so I'm loading it all intoa super vertex struct so I can centralize that rendering function..
The only reason I'm not using classes or anything is because I'd like to make it alot simpler to interleave the arrays and set the stride and do pointer math correctly.