• Advertisement

Archived

This topic is now archived and is closed to further replies.

Sorting face indices...

This topic is 5459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I am coding a KDT for my visibility test, and in general it works fine, but after read some docs about the odered vertex I noticed that my indices are all but ordered, for example. My faces indices (using indexed triangle list) has the following indices: 167 178 165 177 166 176 165 176 166 55 56 44 45 44 56 ..... And as far as I know this could hurt the performance, so I was wondering if someone could help me with a good algorithm to remap my faces indices in a more optimal way like for example: 0 1 2 3 2 1 3 4 5 ..... I really appreciate any help about this. Regards, Oscar Gracian

Share this post


Link to post
Share on other sites
Advertisement
Here's an easy one...


      
void RemapIndices (unsigned int* const indices, const unsigned int numIndices, Vertex* const verts, const unsigned int numVerts)
{
assert(indices != 0);
assert(numIndices > 0);
assert(numVerts > 0);

unsigned int i; // loop counter


// allocate temporary storage

unsigned int* const remap = new unsigned int [numVerts];
assert(remap != 0);

Vertex* const newVerts = new Vertex [numVerts];
assert(newVerts != 0);

// initialise

const unsigned int NULL_INDEX = 0xffffffff;
for (i = 0; i < numVerts; ++i)
{
remap[i] = NULL_INDEX;
}

// build new indices

unsigned int next = 0;
for (i = 0; i < numIndices; ++i)
{
if (remap[indices[i]] == NULL_INDEX)
{
remap[indices[i]] = next++;
}

indices[i] = remap[indices[i]];
}
assert(next == numVerts);

// build new vertices

for (i = 0; i < numVerts; ++i)
{
assert(remap[i] != NULL_INDEX);
newVerts[remap[i]] = verts[i];
}

memcpy(verts, newVerts, numVerts * sizeof(Vertex));

// free temporary storage

delete [] newVerts;
delete [] remap;
}


[edited by - Osc on March 10, 2003 8:49:35 AM]

[edited by - Osc on March 10, 2003 8:50:22 AM]

Share this post


Link to post
Share on other sites
Hi Osc

Thanks for your replay!, it is exactly what i was looking for!

Best Regards,
Oscar

Share this post


Link to post
Share on other sites

  • Advertisement