From a61d126618514b0f2eeb22555e758949dcbdd22b Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Mon, 3 Jul 2023 23:14:31 +0300 Subject: [PATCH 1/3] init --- source/blender/blenkernel/BKE_mesh.h | 12 +++++++ source/blender/blenkernel/intern/mesh.cc | 32 +++++++++++++++++++ .../node_geo_deform_curves_on_surface.cc | 10 +++--- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index e9f91715650..06e3d796f70 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -504,6 +504,18 @@ void BKE_mesh_calc_normals_split_ex(struct Mesh *mesh, struct MLoopNorSpaceArray *r_lnors_spacearr, float (*r_corner_normals)[3]); +#ifdef __cplusplus + +namespace blender::bke { + +void calc_split_normals_for_mesh(const Mesh *mesh, + const bool use_split_normals, + MutableSpan r_corner_normals); + +} + +#endif + /** * Higher level functions hiding most of the code needed around call to * #normals_loop_custom_set(). diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 535b6e3b877..29ef8711eb9 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -1910,6 +1910,38 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, {reinterpret_cast(r_corner_normals), mesh->totloop}); } +namespace blender::bke { + +void calc_split_normals_for_mesh(const Mesh *mesh, + const bool use_split_normals, + MutableSpan r_corner_normals) +{ + const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : float(M_PI); + + const bool *sharp_edges = static_cast( + CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); + const bool *sharp_faces = static_cast( + CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); + + blender::bke::mesh::normals_calc_loop(mesh->vert_positions(), + mesh->edges(), + mesh->polys(), + mesh->corner_verts(), + mesh->corner_edges(), + {}, + mesh->vert_normals(), + mesh->poly_normals(), + sharp_edges, + sharp_faces, + use_split_normals, + split_angle, + nullptr, + nullptr, + r_corner_normals); +} + +} // namespace blender::bke + void BKE_mesh_calc_normals_split(Mesh *mesh) { BKE_mesh_calc_normals_split_ex(mesh, nullptr, ensure_corner_normal_layer(*mesh)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc index b024a27d647..b7f7e339607 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc @@ -318,10 +318,12 @@ static void node_geo_exec(GeoNodeExecParams params) * const mesh, so they are calculated here every time. */ Array corner_normals_orig(surface_mesh_orig->totloop); Array corner_normals_eval(surface_mesh_eval->totloop); - BKE_mesh_calc_normals_split_ex( - surface_mesh_orig, nullptr, reinterpret_cast(corner_normals_orig.data())); - BKE_mesh_calc_normals_split_ex( - surface_mesh_eval, nullptr, reinterpret_cast(corner_normals_eval.data())); + const bool surface_mesh_orig_autosmooth = (surface_mesh_orig->flag & ME_AUTOSMOOTH) != 0; + const bool surface_mesh_eval_autosmooth = (surface_mesh_eval->flag & ME_AUTOSMOOTH) != 0; + bke::calc_split_normals_for_mesh( + surface_mesh_orig, surface_mesh_orig_autosmooth, corner_normals_orig); + bke::calc_split_normals_for_mesh( + surface_mesh_eval, surface_mesh_eval_autosmooth, corner_normals_eval); std::atomic invalid_uv_count = 0; -- 2.30.2 From 113a84aaffe4b559df4240c69887c4a2d10d1513 Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Mon, 3 Jul 2023 23:30:44 +0300 Subject: [PATCH 2/3] cleanup --- source/blender/blenkernel/BKE_mesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 06e3d796f70..ed7a1eef3f7 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -509,7 +509,7 @@ void BKE_mesh_calc_normals_split_ex(struct Mesh *mesh, namespace blender::bke { void calc_split_normals_for_mesh(const Mesh *mesh, - const bool use_split_normals, + bool use_split_normals, MutableSpan r_corner_normals); } -- 2.30.2 From b5b66cd6b63e6001ff3c913a76d0ec38bd07dcaf Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Tue, 4 Jul 2023 01:45:49 +0300 Subject: [PATCH 3/3] progress --- source/blender/blenkernel/BKE_mesh.h | 12 ------ source/blender/blenkernel/intern/mesh.cc | 39 ++----------------- .../node_geo_deform_curves_on_surface.cc | 10 ++--- 3 files changed, 8 insertions(+), 53 deletions(-) diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index ed7a1eef3f7..e9f91715650 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -504,18 +504,6 @@ void BKE_mesh_calc_normals_split_ex(struct Mesh *mesh, struct MLoopNorSpaceArray *r_lnors_spacearr, float (*r_corner_normals)[3]); -#ifdef __cplusplus - -namespace blender::bke { - -void calc_split_normals_for_mesh(const Mesh *mesh, - bool use_split_normals, - MutableSpan r_corner_normals); - -} - -#endif - /** * Higher level functions hiding most of the code needed around call to * #normals_loop_custom_set(). diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 29ef8711eb9..cd6e1471489 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -1884,9 +1884,10 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, ((mesh->flag & ME_AUTOSMOOTH) != 0); const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : float(M_PI); - /* may be nullptr */ - blender::short2 *clnors = (blender::short2 *)CustomData_get_layer_for_write( - &mesh->ldata, CD_CUSTOMLOOPNORMAL, mesh->totloop); + /* May be nullptr. Const_cast to avoid data race while normals computing from different threads + * for the same mesh. */ + blender::short2 *clnors = const_cast(static_cast( + CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL))); const bool *sharp_edges = static_cast( CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); const bool *sharp_faces = static_cast( @@ -1910,38 +1911,6 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, {reinterpret_cast(r_corner_normals), mesh->totloop}); } -namespace blender::bke { - -void calc_split_normals_for_mesh(const Mesh *mesh, - const bool use_split_normals, - MutableSpan r_corner_normals) -{ - const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : float(M_PI); - - const bool *sharp_edges = static_cast( - CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); - const bool *sharp_faces = static_cast( - CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face")); - - blender::bke::mesh::normals_calc_loop(mesh->vert_positions(), - mesh->edges(), - mesh->polys(), - mesh->corner_verts(), - mesh->corner_edges(), - {}, - mesh->vert_normals(), - mesh->poly_normals(), - sharp_edges, - sharp_faces, - use_split_normals, - split_angle, - nullptr, - nullptr, - r_corner_normals); -} - -} // namespace blender::bke - void BKE_mesh_calc_normals_split(Mesh *mesh) { BKE_mesh_calc_normals_split_ex(mesh, nullptr, ensure_corner_normal_layer(*mesh)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc index b7f7e339607..b024a27d647 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc @@ -318,12 +318,10 @@ static void node_geo_exec(GeoNodeExecParams params) * const mesh, so they are calculated here every time. */ Array corner_normals_orig(surface_mesh_orig->totloop); Array corner_normals_eval(surface_mesh_eval->totloop); - const bool surface_mesh_orig_autosmooth = (surface_mesh_orig->flag & ME_AUTOSMOOTH) != 0; - const bool surface_mesh_eval_autosmooth = (surface_mesh_eval->flag & ME_AUTOSMOOTH) != 0; - bke::calc_split_normals_for_mesh( - surface_mesh_orig, surface_mesh_orig_autosmooth, corner_normals_orig); - bke::calc_split_normals_for_mesh( - surface_mesh_eval, surface_mesh_eval_autosmooth, corner_normals_eval); + BKE_mesh_calc_normals_split_ex( + surface_mesh_orig, nullptr, reinterpret_cast(corner_normals_orig.data())); + BKE_mesh_calc_normals_split_ex( + surface_mesh_eval, nullptr, reinterpret_cast(corner_normals_eval.data())); std::atomic invalid_uv_count = 0; -- 2.30.2