Mesh: Avoid unnecessary normal calculation and dirty tags
This is mostly a cleanup to avoid hardcoding the eager calculation of normals it isn't necessary, by reducing calls to `BKE_mesh_calc_normals` and by removing calls to `BKE_mesh_normals_tag_dirty` when the mesh is newly created and already has dirty normals anyway. This reduces boilerplate code and makes the "dirty by default" state more clear. Any regressions from this commit should be easy to fix, though the lazy calculation is solid enough that none are expected.
This commit is contained in:
@@ -789,13 +789,6 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd,
|
||||
MEM_freeN(full_doubles_map);
|
||||
}
|
||||
|
||||
/* In case org dm has dirty normals, or we made some merging, mark normals as dirty in new mesh!
|
||||
* TODO: we may need to set other dirty flags as well?
|
||||
*/
|
||||
if (use_recalc_normals) {
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
}
|
||||
|
||||
if (vgroup_start_cap_remap) {
|
||||
MEM_freeN(vgroup_start_cap_remap);
|
||||
}
|
||||
|
||||
@@ -229,8 +229,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
|
||||
BM_mesh_free(bm);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -501,7 +501,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, mesh);
|
||||
|
||||
BM_mesh_free(bm);
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
}
|
||||
|
||||
if (result == nullptr) {
|
||||
@@ -536,7 +535,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, mesh);
|
||||
BM_mesh_free(bm);
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,8 +263,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct
|
||||
MEM_freeN(edgeMap);
|
||||
MEM_freeN(faceMap);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
/* TODO(sybren): also copy flags & tags? */
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ static void deformVerts(ModifierData *md,
|
||||
uint mvert_num = 0;
|
||||
|
||||
BKE_mesh_vert_coords_apply(mesh_src, vertexCos);
|
||||
BKE_mesh_calc_normals(mesh_src);
|
||||
BKE_mesh_normals_tag_dirty(mesh_src);
|
||||
|
||||
current_time = DEG_get_ctime(ctx->depsgraph);
|
||||
|
||||
|
||||
@@ -212,8 +212,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
TIMEIT_END(decim);
|
||||
#endif
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,6 @@ Mesh *doEdgeSplit(const Mesh *mesh, EdgeSplitModifierData *emd)
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, mesh);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1102,7 +1102,6 @@ static Mesh *explodeMesh(ExplodeModifierData *emd,
|
||||
/* finalization */
|
||||
BKE_mesh_calc_edges_tessface(explode);
|
||||
BKE_mesh_convert_mfaces_to_mpolys(explode);
|
||||
BKE_mesh_normals_tag_dirty(explode);
|
||||
|
||||
if (psmd->psys->lattice_deform_data) {
|
||||
BKE_lattice_deform_data_destroy(psmd->psys->lattice_deform_data);
|
||||
|
||||
@@ -748,7 +748,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
|
||||
}
|
||||
|
||||
BKE_mesh_calc_edges_loose(result);
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -302,8 +302,6 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co
|
||||
}
|
||||
}
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -361,7 +359,6 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
|
||||
|
||||
if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE) {
|
||||
result = generate_ocean_geometry(omd, mesh, resolution);
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
}
|
||||
else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) {
|
||||
result = (Mesh *)BKE_id_copy_ex(NULL, &mesh->id, NULL, LIB_ID_COPY_LOCALIZE);
|
||||
@@ -472,6 +469,8 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
|
||||
}
|
||||
}
|
||||
|
||||
BKE_mesh_normals_tag_dirty(mesh);
|
||||
|
||||
if (allocated_ocean) {
|
||||
BKE_ocean_free(omd->ocean);
|
||||
omd->ocean = NULL;
|
||||
@@ -490,15 +489,7 @@ static Mesh *doOcean(ModifierData *UNUSED(md), const ModifierEvalContext *UNUSED
|
||||
|
||||
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
||||
{
|
||||
Mesh *result;
|
||||
|
||||
result = doOcean(md, ctx, mesh);
|
||||
|
||||
if (result != mesh) {
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
return doOcean(md, ctx, mesh);
|
||||
}
|
||||
// #define WITH_OCEANSIM
|
||||
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
|
||||
|
||||
@@ -530,8 +530,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
MEM_SAFE_FREE(vert_part_index);
|
||||
MEM_SAFE_FREE(vert_part_value);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,6 @@ static void deformVerts(ModifierData *md,
|
||||
/* make new mesh */
|
||||
psmd->mesh_final = BKE_mesh_copy_for_eval(mesh_src, false);
|
||||
BKE_mesh_vert_coords_apply(psmd->mesh_final, vertexCos);
|
||||
BKE_mesh_calc_normals(psmd->mesh_final);
|
||||
|
||||
BKE_mesh_tessface_ensure(psmd->mesh_final);
|
||||
|
||||
|
||||
@@ -206,7 +206,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
|
||||
|
||||
BKE_mesh_copy_parameters_for_eval(result, mesh);
|
||||
BKE_mesh_calc_edges(result, true, false);
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +384,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
|
||||
mvert_new = result->mvert;
|
||||
float(*vert_normals_new)[3] = BKE_mesh_vertex_normals_for_write(result);
|
||||
BKE_mesh_vertex_normals_clear_dirty(result);
|
||||
mpoly_new = result->mpoly;
|
||||
mloop_new = result->mloop;
|
||||
medge_new = result->medge;
|
||||
@@ -1120,7 +1119,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
}
|
||||
|
||||
if ((ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f)) {
|
||||
Mesh *result_prev = result;
|
||||
result = mesh_remove_doubles_on_axis(result,
|
||||
mvert_new,
|
||||
totvert,
|
||||
@@ -1128,13 +1126,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
||||
axis_vec,
|
||||
ob_axis != NULL ? mtx_tx[3] : NULL,
|
||||
ltmd->merge_dist);
|
||||
if (result != result_prev) {
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
}
|
||||
}
|
||||
|
||||
if ((ltmd->flag & MOD_SCREW_NORMAL_CALC) == 0) {
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
if ((ltmd->flag & MOD_SCREW_NORMAL_CALC)) {
|
||||
BKE_mesh_vertex_normals_clear_dirty(mesh);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1950,8 +1950,6 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, origmesh);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
skin_set_orig_indices(result);
|
||||
|
||||
return result;
|
||||
|
||||
@@ -2016,8 +2016,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
|
||||
}
|
||||
}
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
/* Make edges. */
|
||||
{
|
||||
uint i = 0;
|
||||
|
||||
@@ -129,7 +129,7 @@ static void deformVerts(ModifierData *md,
|
||||
MVert *x, *v;
|
||||
|
||||
BKE_mesh_vert_coords_apply(surmd->mesh, vertexCos);
|
||||
BKE_mesh_calc_normals(surmd->mesh);
|
||||
BKE_mesh_normals_tag_dirty(surmd->mesh);
|
||||
|
||||
mesh_verts_num = surmd->mesh->totvert;
|
||||
|
||||
|
||||
@@ -89,8 +89,6 @@ static Mesh *triangulate_mesh(Mesh *mesh,
|
||||
me->flag |= ME_EDGEDRAW | ME_EDGERENDER;
|
||||
}
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,6 @@ static Mesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, Mesh *
|
||||
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, mesh);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
BKE_mesh_normals_tag_dirty(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user