I'm guessing i have to use some form of hashing here, but I can't quite get my head around how this'll work. My algo goes something like this:
// go through each vertex for (int i = 0; i < vertList.size(); i++) { duplicateVert = findDuplicateVert(i); // snip ... } // snip... private int findDuplicateVert(int listPos) { Vertex cmpVert = vertList.get(listPos); for (int i = 0; i < listPos; i++) { if (vertList.get(i).compare(cmpVert) == true) { // found duplicate vert return i; } } return -1; // means we didn't find a duplicate vert }
As you can see it'll spend alot of time in findDuplicateVert() doing compare(). For large meshes this is an issue. The compare function tests whether 2 verts have the same xyz,uv coords, etc. I've never really used hashing functions, but I guess I could use the x coordinates as they key... just to reduce the number of times it goes through the list.. Are hash functions able to have multiple keys? Would be cool to be able to use the xyz coords as a key. I'll have to investigate java.util.Hashtable.
I'm at this stage with my stuff at the mo - been looking at 'refinery' for Collada - seems to be exactly what you're writing here - have you considered it?
cheers,
Aph