[Bf-blender-cvs] [bf0180d2060] master: Sculpt: Remove some normal calculation with deformed sculpting

Hans Goudey noreply at git.blender.org
Thu Nov 17 01:22:48 CET 2022


Commit: bf0180d2060b3d6480eded681a7efef3d61c001a
Author: Hans Goudey
Date:   Wed Nov 16 18:22:09 2022 -0600
Branches: master
https://developer.blender.org/rBbf0180d2060b3d6480eded681a7efef3d61c001a

Sculpt: Remove some normal calculation with deformed sculpting

Remove unnecessary (and No-op) normal calculation when sculpting on top
of deformed coordinates. Examples are shape keys and deform modifiers.
On a 1 million face mesh, this saved 100ms per stroke update.
This function actually did nothing since cfa53e0fbeed7178c7,
so that large improvement comes for free.

Conceptually this is correct because when sculpting on deformed
coordinates, we don't change the positions of the base mesh directly.
In the future it might be better to allocate a separate array for
normals when using deformed coordinates, but it's not clear that's
necessary yet.

===================================================================

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/mesh_normals.cc
M	source/blender/blenkernel/intern/pbvh.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index edd7601ac1d..1eadc3a39b0 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -472,12 +472,6 @@ void BKE_mesh_calc_normals(struct Mesh *me);
  * Called after calculating all modifiers.
  */
 void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
-void BKE_mesh_calc_normals_looptri(const struct MVert *mverts,
-                                   int numVerts,
-                                   const struct MLoop *mloop,
-                                   const struct MLoopTri *looptri,
-                                   int looptri_num,
-                                   float (*r_tri_nors)[3]);
 
 /**
  * Define sharp edges as needed to mimic 'autosmooth' from angle threshold.
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index 49729ede956..6750d3c34fd 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -444,60 +444,6 @@ void BKE_mesh_calc_normals(Mesh *mesh)
   BKE_mesh_vertex_normals_ensure(mesh);
 }
 
-void BKE_mesh_calc_normals_looptri(const MVert *mverts,
-                                   int numVerts,
-                                   const MLoop *mloop,
-                                   const MLoopTri *looptri,
-                                   int looptri_num,
-                                   float (*r_tri_nors)[3])
-{
-  float(*tnorms)[3] = (float(*)[3])MEM_calloc_arrayN(size_t(numVerts), sizeof(*tnorms), "tnorms");
-  float(*fnors)[3] = (r_tri_nors) ? r_tri_nors :
-                                    (float(*)[3])MEM_calloc_arrayN(
-                                        size_t(looptri_num), sizeof(*fnors), "meshnormals");
-
-  if (!tnorms || !fnors) {
-    goto cleanup;
-  }
-
-  for (int i = 0; i < looptri_num; i++) {
-    const MLoopTri *lt = &looptri[i];
-    float *f_no = fnors[i];
-    const uint vtri[3] = {
-        mloop[lt->tri[0]].v,
-        mloop[lt->tri[1]].v,
-        mloop[lt->tri[2]].v,
-    };
-
-    normal_tri_v3(f_no, mverts[vtri[0]].co, mverts[vtri[1]].co, mverts[vtri[2]].co);
-
-    accumulate_vertex_normals_tri_v3(tnorms[vtri[0]],
-                                     tnorms[vtri[1]],
-                                     tnorms[vtri[2]],
-                                     f_no,
-                                     mverts[vtri[0]].co,
-                                     mverts[vtri[1]].co,
-                                     mverts[vtri[2]].co);
-  }
-
-  /* Following Mesh convention; we use vertex coordinate itself for normal in this case. */
-  for (int i = 0; i < numVerts; i++) {
-    const MVert *mv = &mverts[i];
-    float *no = tnorms[i];
-
-    if (UNLIKELY(normalize_v3(no) == 0.0f)) {
-      normalize_v3_v3(no, mv->co);
-    }
-  }
-
-cleanup:
-  MEM_freeN(tnorms);
-
-  if (fnors != r_tri_nors) {
-    MEM_freeN(fnors);
-  }
-}
-
 void BKE_lnor_spacearr_init(MLoopNorSpaceArray *lnors_spacearr,
                             const int numLoops,
                             const char data_type)
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 24ea2de98f6..942d124ded4 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3140,9 +3140,6 @@ void BKE_pbvh_vert_coords_apply(PBVH *pbvh, const float (*vertCos)[3], const int
       }
     }
 
-    /* coordinates are new -- normals should also be updated */
-    BKE_mesh_calc_normals_looptri(
-        pbvh->verts, pbvh->totvert, pbvh->mloop, pbvh->looptri, pbvh->totprim, NULL);
 
     for (int a = 0; a < pbvh->totnode; a++) {
       BKE_pbvh_node_mark_update(&pbvh->nodes[a]);



More information about the Bf-blender-cvs mailing list