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 cfa53e0fbe,
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.
This commit is contained in:
Hans Goudey 2022-11-16 18:22:09 -06:00
parent c481549870
commit bf0180d206
3 changed files with 0 additions and 63 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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]);