Original Post
hi. last night i've exporter a mesh from maya (yaaay.. happy me) and stripped stripped out all the unused vertices and rebuild the indexbuffer. However, these methods are veery slow so i'll turn here for some help. This is the method where i extract the used vertices:
for(std::size_t i = 0; i < vertex_data.size(); ++i)
{
bool duplicate = false;
vertex_x = vertex_data.x;
vertex_y = vertex_data.y;
vertex_z = vertex_data.z;
normal_x = normal_data.x;
normal_y = normal_data.y;
normal_z = normal_data.z;
for(std::size_t j = 0; j < final_vertex_data.size(); ++j)
{
if( final_vertex_data[j].x == vertex_x && final_vertex_data[j].y == vertex_y && final_vertex_data[j].z == vertex_z &&
final_normal_data[j].x == normal_x && final_normal_data[j].y == normal_y && final_normal_data[j].z == normal_z)
duplicate = true;
}
if(!duplicate)
{
final_vertex_data.push_back(MPoint(vertex_x, vertex_y, vertex_z));
final_normal_data.push_back(MVector(normal_x, normal_y, normal_z));
}
}
and where i rebuild my indices
for(std::size_t orig_index = 0; orig_index < index_data.size(); ++orig_index)
{
vertex_x = vertex_data[index_data[orig_index]].x;
vertex_y = vertex_data[index_data[orig_index]].y;
vertex_z = vertex_data[index_data[orig_index]].z;
normal_x = normal_data[index_data[orig_index]].x;
normal_y = normal_data[index_data[orig_index]].y;
normal_z = normal_data[index_data[orig_index]].z;
for(std::size_t j = 0; j < final_vertex_data.size(); ++j)
{
if( final_vertex_data[j].x == vertex_x && final_vertex_data[j].y == vertex_y && final_vertex_data[j].z == vertex_z &&
final_normal_data[j].x == normal_x && final_normal_data[j].y == normal_y && final_normal_data[j].z == normal_z)
final_index_data.push_back(static_cast<int>(j));
}
}
there methods were really quick-coded and not so very optimized (as you might see ;)) and I won't ask you to optimize my code, just give me som optimization hints. I tried to format my code as good as I could