forked from blender/blender
Optimized SubMesh to hold only used vertices #84
@ -283,20 +283,14 @@ void MeshData::write_submeshes(Mesh *mesh)
|
||||
else {
|
||||
/* Optimizing submeshes: getting only used vertices, rearranged indices */
|
||||
for (SubMesh &sm : submeshes_) {
|
||||
Map<int, int> index_map;
|
||||
for (int i : sm.face_vertex_indices) {
|
||||
index_map.add(i, 0);
|
||||
Vector<int> index_map(vertices.size(), 0);
|
||||
|
||||
for (int &face_vertex_index : sm.face_vertex_indices) {
|
||||
const int v = face_vertex_index;
|
||||
if (index_map[v] == 0) {
|
||||
sm.vertices.push_back(vertices[v]);
|
||||
index_map[v] = sm.vertices.size();
|
||||
}
|
||||
i = 0;
|
||||
for (int &v : index_map.values()) {
|
||||
v = i++;
|
||||
}
|
||||
sm.vertices.resize(index_map.size());
|
||||
for (auto it : index_map.items()) {
|
||||
sm.vertices[it.value] = vertices[it.key];
|
||||
}
|
||||
for (int &v : sm.face_vertex_indices) {
|
||||
v = index_map.lookup(v);
|
||||
face_vertex_index = index_map[v] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
I would guess something like this is more efficient, instead of multiple loops and hash maps.
You are right, your algorithm is more efficient and faster, thank you.