normals&texture

I’m programming an application witch loads a WRML file with a scene. So I have a list of vertexes and a list of faces. Every vertex can be used by many faces, thus WRML provides different normals and texture coordinates every time it’s used.

The problem is I would want to use glDrawElements() witch is faster than thousands of calls to glVertex, glNormal, glTexCoord. But with that function i must specify arrays that can provide only one normal and texture coordinate for every vertex.

One solution could be replying vertexes, so if they are average used by 3-4 faces each one, I would use 3-4 times bigger memory… I think it’s not a tricky way of coding… Could you help me? Thanx

Marco.

I came across a similar problem. Retaining a data structure where the vertices & normals were shared (speed up skin deformation calculations) whilst making use of vertex arrays for display.

I’m not saying this is the best way to do it, If anyone has a better solution I’d love to hear it…

starting with a basic class for a vertex,

class vertex
{
float x,y,z;
int *output;
int count;

vertex(void){x=y=z=0; count=0; output=0; }

void addVertexArrayOutput( int ref );

}

The basic idea was that the vertices would be deformed using an array of the above classes. When the calculation was done, that would be put out to the vertex arrays using reference numbers held in the ‘output’ array. The count value indicates how many positions in the vertex array this vertex is used in.

Making the assumption that a vertex is shared if and only if the vertex, normal and texturing co-ordinate are the same, the data has to be compacted from its original form into the vertex arrays.

for each triangle we have to specify three vertex array numbers. We then have to check to see if any of the vertices have been used before. If it isn’t add an extra position to the vertex array.

in psuedo-ish C++

for( i=0; i<polyCount; i++ )
{
for( j=0; j<poly[i].vertexCount; j++)
{
// has vertex been used before
if( poly[i].vertexRef[j]->output )
{
check to see if any of the vertex array output positions have the same normal, & texturing co-ordinate. If yes, use that position, if not add a new one.
}
else
{
add a new position
}
}
}

I hope you kind of see what I’m doing, if not mail me and I’ll give you a bit more info