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 {
/* 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);
}
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);
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();
}
face_vertex_index = index_map[v] - 1;
}
}
}