Fix #112900: Asset displaying mesh with hiding and no material indices

The case when there were no material indices, multiple materials, and
the mesh used hiding wasn't handled after 55970fa367.
This is a simple parallel loop adding up the non-hidden triangles.
This commit is contained in:
Hans Goudey
2023-09-26 15:09:51 -04:00
parent b56d39bdcc
commit c095962d06

View File

@@ -187,12 +187,30 @@ static void accumululate_material_counts_bm(
static void accumululate_material_counts_mesh(
const MeshRenderData &mr, threading::EnumerableThreadSpecific<Array<int>> &all_tri_counts)
{
const OffsetIndices faces = mr.faces;
if (!mr.material_indices) {
all_tri_counts.local().first() = poly_to_tri_count(mr.face_len, mr.loop_len);
if (mr.use_hide && mr.hide_poly) {
const Span hide_poly(mr.hide_poly, mr.face_len);
all_tri_counts.local().first() = threading::parallel_reduce(
faces.index_range(),
4096,
0,
[&](const IndexRange range, int count) {
for (const int face : range) {
if (!hide_poly[face]) {
count += bke::mesh::face_triangles_num(faces[face].size());
}
}
return count;
},
std::plus<int>());
}
else {
all_tri_counts.local().first() = poly_to_tri_count(mr.face_len, mr.loop_len);
}
return;
}
const OffsetIndices faces = mr.faces;
const Span material_indices(mr.material_indices, mr.face_len);
threading::parallel_for(material_indices.index_range(), 1024, [&](const IndexRange range) {
Array<int> &tri_counts = all_tri_counts.local();