Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-09-27 01:59:44 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2022-10-03 14:12:13 +0300
commit86538e31f5945009b6fae0f14b958ed07762f016 (patch)
tree5c4564fb6a90bdd15ff926a905d366c4bfcee085 /source/blender
parent25cc656003d1b42a88406a78e0cc74a163951136 (diff)
Scew Modifier: Remove eager normal calculation
The screw modifier calculated normals eagerly (whether or not the next modifier actually used them). However, this was incorrect and set invalid normals. It isn't necessary because they can be calculated later anyway. The potential performance improvement isn't worth the complexity or maintenance burden. Fixes T101075 Differential Revision: https://developer.blender.org/D16073
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/modifiers/intern/MOD_screw.c99
1 files changed, 1 insertions, 98 deletions
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 9588b9acd3b..d75f7c155aa 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -56,7 +56,6 @@ static void initData(ModifierData *md)
typedef struct ScrewVertConnect {
float dist; /* distance from the center axis */
float co[3]; /* location relative to the transformed axis */
- float no[3]; /* calc normal of the vertex */
uint v[2]; /* 2 verts on either side of this one */
MEdge *e[2]; /* edges on either side, a bit of a waste since each edge ref's 2 edges */
char flag;
@@ -376,9 +375,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
/* The `screw_ofs` cannot change from now on. */
const bool do_remove_doubles = (ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f);
- /* Only calculate normals if `do_remove_doubles` since removing doubles frees the normals. */
- const bool do_normal_create = (ltmd->flag & MOD_SCREW_NORMAL_CALC) &&
- (do_remove_doubles == false);
result = BKE_mesh_new_nomain_from_template(
mesh, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys);
@@ -476,9 +472,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
- float(*vert_normals_new)[3] = do_normal_create ? BKE_mesh_vertex_normals_for_write(result) :
- NULL;
-
if (ltmd->flag & MOD_SCREW_NORMAL_CALC) {
/*
@@ -508,14 +501,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
vc = vert_connect;
/* Copy Vert Locations */
- /* - We can do this in a later loop - only do here if no normal calc */
- if (!totedge) {
- for (i = 0; i < totvert; i++, mv_orig++, mv_new++) {
- copy_v3_v3(mv_new->co, mv_orig->co);
- normalize_v3_v3(vc->no, mv_new->co); /* no edges- this is really a dummy normal */
- }
- }
- else {
+ if (totedge != 0) {
// printf("\n\n\n\n\nStarting Modifier\n");
/* set edge users */
med_new = medge_new;
@@ -767,77 +753,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
}
-
- /* *VERTEX NORMALS*
- * we know the surrounding edges are ordered correctly now
- * so its safe to create vertex normals.
- *
- * calculate vertex normals that can be propagated on lathing
- * use edge connectivity work this out */
- if (do_normal_create) {
- if (SV_IS_VALID(vc->v[0])) {
- if (SV_IS_VALID(vc->v[1])) {
- /* 2 edges connected. */
- /* make 2 connecting vert locations relative to the middle vert */
- sub_v3_v3v3(tmp_vec1, mvert_new[vc->v[0]].co, mvert_new[i].co);
- sub_v3_v3v3(tmp_vec2, mvert_new[vc->v[1]].co, mvert_new[i].co);
- /* normalize so both edges have the same influence, no matter their length */
- normalize_v3(tmp_vec1);
- normalize_v3(tmp_vec2);
-
- /* vc_no_tmp1 - this line is the average direction of both connecting edges
- *
- * Use the edge order to make the subtraction, flip the normal the right way
- * edge should be there but check just in case... */
- if (vc->e[0]->v1 == i) {
- sub_v3_v3(tmp_vec1, tmp_vec2);
- }
- else {
- sub_v3_v3v3(tmp_vec1, tmp_vec2, tmp_vec1);
- }
- }
- else {
- /* only 1 edge connected - same as above except
- * don't need to average edge direction */
- if (vc->e[0]->v2 == i) {
- sub_v3_v3v3(tmp_vec1, mvert_new[i].co, mvert_new[vc->v[0]].co);
- }
- else {
- sub_v3_v3v3(tmp_vec1, mvert_new[vc->v[0]].co, mvert_new[i].co);
- }
- }
-
- /* tmp_vec2 - is a line 90d from the pivot to the vec
- * This is used so the resulting normal points directly away from the middle */
- cross_v3_v3v3(tmp_vec2, axis_vec, vc->co);
-
- if (UNLIKELY(is_zero_v3(tmp_vec2))) {
- /* we're _on_ the axis, so copy it based on our winding */
- if (vc->e[0]->v2 == i) {
- negate_v3_v3(vc->no, axis_vec);
- }
- else {
- copy_v3_v3(vc->no, axis_vec);
- }
- }
- else {
- /* edge average vector and right angle to the pivot make the normal */
- cross_v3_v3v3(vc->no, tmp_vec1, tmp_vec2);
- }
- }
- else {
- copy_v3_v3(vc->no, vc->co);
- }
-
- /* we won't be looping on this data again so copy normals here */
- if ((angle < 0.0f) != do_flip) {
- negate_v3(vc->no);
- }
-
- normalize_v3(vc->no);
- copy_v3_v3(vert_normals_new[i], vc->no);
- }
- /* Done with normals */
}
}
}
@@ -878,14 +793,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
mv_new = &mvert_new[varray_stride]; /* advance to the next slice */
for (j = 0; j < totvert; j++, mv_new_base++, mv_new++) {
- /* set normal */
- if (vert_connect) {
- if (do_normal_create) {
- /* Set the normal now its transformed. */
- mul_v3_m3v3(vert_normals_new[mv_new - mvert_new], mat3, vert_connect[j].no);
- }
- }
-
/* set location */
copy_v3_v3(mv_new->co, mv_new_base->co);
@@ -1126,10 +1033,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
MEM_freeN(vert_loop_map);
}
- if (do_normal_create) {
- BKE_mesh_vertex_normals_clear_dirty(result);
- }
-
if (do_remove_doubles) {
result = mesh_remove_doubles_on_axis(result,
mvert_new,