Fix T51350: 2D curve normals flip when deformed

Deforming 2D curves & text with modifiers/shape-keys
could flip the normals.

Now check the back-facing flag instead of `z < 0`.
This commit is contained in:
Campbell Barton 2017-05-26 19:03:30 +10:00
parent 98df7d778f
commit f78ba0df02
Notes: blender-bot 2023-02-14 07:01:29 +01:00
Referenced by issue #51350, Moving 2d curves can flip shading normals
1 changed files with 9 additions and 2 deletions

View File

@ -167,10 +167,12 @@ void BKE_displist_normals_add(ListBase *lb)
if (dl->nors == NULL) {
dl->nors = MEM_callocN(sizeof(float) * 3, "dlnors");
if (dl->verts[2] < 0.0f)
if (dl->flag & DL_BACK_CURVE) {
dl->nors[2] = -1.0f;
else
}
else {
dl->nors[2] = 1.0f;
}
}
}
else if (dl->type == DL_SURF) {
@ -469,6 +471,7 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, const float normal_proj
sf_arena = BLI_memarena_new(BLI_SCANFILL_ARENA_SIZE, __func__);
while (cont) {
int dl_flag_accum = 0;
cont = 0;
totvert = 0;
nextcol = 0;
@ -514,6 +517,7 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, const float normal_proj
nextcol = 1;
}
}
dl_flag_accum |= dl->flag;
}
dl = dl->next;
}
@ -526,6 +530,7 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, const float normal_proj
if (tot) {
dlnew = MEM_callocN(sizeof(DispList), "filldisplist");
dlnew->type = DL_INDEX3;
dlnew->flag = (dl_flag_accum & (DL_BACK_CURVE | DL_FRONT_CURVE));
dlnew->col = colnr;
dlnew->nr = totvert;
dlnew->parts = tot;
@ -603,6 +608,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
dlnew->nr = dl->parts;
dlnew->parts = 1;
dlnew->type = DL_POLY;
dlnew->flag = DL_BACK_CURVE;
dlnew->col = dl->col;
dlnew->charidx = dl->charidx;
@ -623,6 +629,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
dlnew->nr = dl->parts;
dlnew->parts = 1;
dlnew->type = DL_POLY;
dlnew->flag = DL_FRONT_CURVE;
dlnew->col = dl->col;
dlnew->charidx = dl->charidx;