#20 *2triangles conditioners skip some polylists/polygons

open
Herbert Law
Conditioner (8)
5
2009-09-15
2009-09-15
Ionia
No

I've been trying to triangulate Seymour.dae (one of the sample models from the model bank) and was left scratching my head when half of his polylists seemed to get lost when I ran polylists2triangles on him. I dug around in the code a little and discovered that the conditioner wasn't iterating through the polylists correctly. It needs to store the number of polylists before removing any and then convert polylist zero each time (like it says in the comment, for shame) in order not to skip any. Original and fixed code below. Also note that something similar needs to be done to polygons2triangles (and possibly others, I didn't check any further) since it has the same issue. I would try to fix it in the repository, but I don't know what I would need to do to be able to do that and I need to go to sleep (it's 4am after all).

Original:
int Polylist2Triangles::execute()
{
...
for(size_t currentPolylist = 0; currentPolylist < thisMesh->getPolylist_array().getCount(); currentPolylist++)
{
// Get the polylist out of the mesh
// Always get index 0 because every pass through this loop deletes the <polygons> element as it finishes with it
domPolylist *thisPolylist = thisMesh->getPolylist_array()[currentPolylist];
createTrianglesFromPolylist( thisMesh, thisPolylist );
// Remove the polylist from the mesh
thisMesh->removeChildElement(thisPolylist);
}
...
}

Fixed:
size_t numPolylists = thisMesh->getPolylist_array().getCount();
for(size_t currentPolylist = 0; currentPolylist < numPolylists; currentPolylist++)
{
// Get the polylist out of the mesh
// Always get index 0 because every pass through this loop deletes the <polygons> element as it finishes with it
domPolylist *thisPolylist = thisMesh->getPolylist_array()[0];
createTrianglesFromPolylist( thisMesh, thisPolylist );
// Remove the polylist from the mesh
thisMesh->removeChildElement(thisPolylist);
}

Discussion