Optimized SubMesh to hold only used vertices #84

Merged
Bogdan Nagirniak merged 3 commits from BLEN-474 into hydra-render 2023-08-02 16:45:15 +02:00
Showing only changes of commit a422272471 - Show all commits

View File

@ -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);
} }
} }
} }