From 8b93265c19feeed2b758046359ac102a1f21278a Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 2 Aug 2021 13:47:32 -0400 Subject: Mesh: Tag normals dirty instead of calculating Because mesh vertex and face normals are just derived data, they can be calculated lazily instead of eagerly. Often normal calculation is a relatively expensive task, and the calculation is often redundant if the mesh is deformed afterwards anyway. Instead, normals should be calculated only when they are needed. This commit moves in that direction by adding a new function to tag a mesh's normals dirty and replacing normal calculation with it in some places. Differential Revision: https://developer.blender.org/D12107 --- source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc | 2 +- source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc | 6 ++---- source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc | 2 +- source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc index 4286db52115..91d569282c3 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc @@ -150,7 +150,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span coords) plConvexHullDelete(hull); - BKE_mesh_calc_normals(result); + BKE_mesh_normals_tag_dirty(result); return result; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc index 925ed0f8da8..d46ea2d2050 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc @@ -299,7 +299,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top, mesh->medge[0].v1 = 0; mesh->medge[0].v2 = 1; mesh->medge[0].flag |= ME_LOOSEEDGE; - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); return mesh; } @@ -534,12 +534,10 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top, } } - BKE_mesh_calc_normals(mesh); + BKE_mesh_normals_tag_dirty(mesh); calculate_uvs(mesh, top_is_point, bottom_is_point, verts_num, fill_type); - BLI_assert(BKE_mesh_is_valid(mesh)); - return mesh; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc index 245d7800621..165da8ec9f2 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_subdivide.cc @@ -88,7 +88,7 @@ static void geo_node_mesh_subdivide_exec(GeoNodeExecParams params) } Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh_in); - BKE_mesh_calc_normals(mesh_out); + BKE_mesh_normals_tag_dirty(mesh_out); MeshComponent &mesh_component = geometry_set.get_component_for_write(); mesh_component.replace(mesh_out); diff --git a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc index f0f032ed8f4..a2c10af9c4d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_subdivision_surface.cc @@ -93,7 +93,7 @@ static void geo_node_subdivision_surface_exec(GeoNodeExecParams params) } Mesh *mesh_out = BKE_subdiv_to_mesh(subdiv, &mesh_settings, mesh_in); - BKE_mesh_calc_normals(mesh_out); + BKE_mesh_normals_tag_dirty(mesh_out); MeshComponent &mesh_component = geometry_set.get_component_for_write(); mesh_component.replace(mesh_out); -- cgit v1.2.3