Mesh: Avoid recalculating bounds after some operations
Share the bounds cache across the input and output meshes of some mesh operations that don't change the min and max positions: simple subdivision, edge/face deletion, and triangulation. If the source mesh's bounds are computed, or if the mesh is persistent, this can save recalculation of the bounding box, which takes a few milliseconds for large meshes.
This commit is contained in:
@@ -1215,6 +1215,11 @@ Mesh *BKE_subdiv_to_mesh(Subdiv *subdiv,
|
||||
});
|
||||
}
|
||||
|
||||
if (subdiv->settings.is_simple) {
|
||||
/* In simple subdivision, min and max positions are not changed, avoid recomputing bounds. */
|
||||
result->runtime->bounds_cache = coarse_mesh->runtime->bounds_cache;
|
||||
}
|
||||
|
||||
// BKE_mesh_validate(result, true, true);
|
||||
BKE_subdiv_stats_end(&subdiv->stats, SUBDIV_STATS_SUBDIV_TO_MESH);
|
||||
/* Using normals from the limit surface gives different results than Blender's vertex normal
|
||||
|
||||
@@ -1014,6 +1014,9 @@ static void do_mesh_separation(GeometrySet &geometry_set,
|
||||
selected_loops_num,
|
||||
selected_poly_indices,
|
||||
mesh_in);
|
||||
|
||||
/* Positions are not changed by the operation, so the bounds are the same. */
|
||||
mesh_out->runtime->bounds_cache = mesh_in.runtime->bounds_cache;
|
||||
break;
|
||||
}
|
||||
case GEO_NODE_DELETE_GEOMETRY_MODE_ONLY_FACE: {
|
||||
@@ -1070,6 +1073,9 @@ static void do_mesh_separation(GeometrySet &geometry_set,
|
||||
selected_loops_num,
|
||||
selected_poly_indices,
|
||||
mesh_in);
|
||||
|
||||
/* Positions are not changed by the operation, so the bounds are the same. */
|
||||
mesh_out->runtime->bounds_cache = mesh_in.runtime->bounds_cache;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ static Mesh *triangulate_mesh_selection(const Mesh &mesh,
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, min_vertices, true, nullptr, nullptr, nullptr);
|
||||
Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cd_mask_extra, &mesh);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
/* Positions are not changed by the triangulation operation, so the bounds are the same. */
|
||||
result->runtime->bounds_cache = mesh.runtime->bounds_cache;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user