forked from blender/blender
Optimized SubMesh to hold only used vertices #84
@ -283,20 +283,14 @@ void MeshData::write_submeshes(Mesh *mesh)
|
|||||||
else {
|
else {
|
||||||
/* Optimizing submeshes: getting only used vertices, rearranged indices */
|
/* Optimizing submeshes: getting only used vertices, rearranged indices */
|
||||||
for (SubMesh &sm : submeshes_) {
|
for (SubMesh &sm : submeshes_) {
|
||||||
Map<int, int> index_map;
|
Vector<int> index_map(vertices.size(), 0);
|
||||||
|
|||||||
for (int i : sm.face_vertex_indices) {
|
for (int &face_vertex_index : sm.face_vertex_indices) {
|
||||||
index_map.add(i, 0);
|
const int v = face_vertex_index;
|
||||||
}
|
if (index_map[v] == 0) {
|
||||||
i = 0;
|
sm.vertices.push_back(vertices[v]);
|
||||||
for (int &v : index_map.values()) {
|
index_map[v] = sm.vertices.size();
|
||||||
v = i++;
|
}
|
||||||
}
|
face_vertex_index = index_map[v] - 1;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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.