forked from bartvdbraak/blender
fix for own bad logic with polygon normal calculation, was reading one past the loop array (reported as bug #31431).
This commit is contained in:
parent
ed12a5d001
commit
b224cbe6b6
@ -2771,16 +2771,19 @@ static void mesh_calc_ngon_normal(MPoly *mpoly, MLoop *loopstart,
|
||||
{
|
||||
const int nverts = mpoly->totloop;
|
||||
float const *v_prev = mvert[loopstart[nverts - 1].v].co;
|
||||
float const *v_curr = mvert[loopstart->v].co;
|
||||
float n[3] = {0.0f};
|
||||
float const *v_curr;
|
||||
int i;
|
||||
|
||||
zero_v3(normal);
|
||||
|
||||
/* Newell's Method */
|
||||
for (i = 0; i < nverts; v_prev = v_curr, v_curr = mvert[loopstart[++i].v].co) {
|
||||
add_newell_cross_v3_v3v3(n, v_prev, v_curr);
|
||||
for (i = 0; i < nverts; i++) {
|
||||
v_curr = mvert[loopstart[i].v].co;
|
||||
add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
|
||||
v_prev = v_curr;
|
||||
}
|
||||
|
||||
if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
|
||||
if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
|
||||
normal[2] = 1.0f; /* other axis set to 0.0 */
|
||||
}
|
||||
}
|
||||
@ -2818,16 +2821,19 @@ static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart,
|
||||
{
|
||||
const int nverts = mpoly->totloop;
|
||||
float const *v_prev = vertex_coords[loopstart[nverts - 1].v];
|
||||
float const *v_curr = vertex_coords[loopstart->v];
|
||||
float n[3] = {0.0f};
|
||||
float const *v_curr;
|
||||
int i;
|
||||
|
||||
zero_v3(normal);
|
||||
|
||||
/* Newell's Method */
|
||||
for (i = 0; i < nverts; v_prev = v_curr, v_curr = vertex_coords[loopstart[++i].v]) {
|
||||
add_newell_cross_v3_v3v3(n, v_prev, v_curr);
|
||||
for (i = 0; i < nverts; i++) {
|
||||
v_curr = vertex_coords[loopstart[i].v];
|
||||
add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
|
||||
v_prev = v_curr;
|
||||
}
|
||||
|
||||
if (UNLIKELY(normalize_v3_v3(normal, n) == 0.0f)) {
|
||||
if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
|
||||
normal[2] = 1.0f; /* other axis set to 0.0 */
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user