Example #1
0
void VertexArray::removeDuplicateVertices(VertexArray& varray, IndexArray& iarray)
{
	Log("Starting vertex count: %d", varray.count);
	
	// Lets remove duplicate vertices to get a smaller varray, iarray stays the same.

	// For each vertex, find duplicates after it
	for(std::size_t i = 0; i < varray.count ; ++i)
	{
		// For each i, iterate from i+1 to end
		for(std::size_t j = i + 1; j < varray.count; ++j)
		{
			if(varray.isVertexEqual(i,j))
			{
				
				// swap two vertices, also swap their references
				varray.swapVertices(j, varray.count-1);
				iarray.swapIndices(j, varray.count-1);
				
				varray.removeLast();

				// whatever indices were pointing at j, which is now gone, now point to i
				iarray.redirectFromTo(varray.count, i);
				

				//Log("%d and %d are duplicates. Redirecting all references of %d to %d.", i, j, j, i);

				j--;
			}
		}
	}

	Log("Done removing duplicated. Varray size: %d, IArray size %d", varray.count, iarray.indices.size());
}