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:
authorCampbell Barton <ideasman42@gmail.com>2012-05-13 01:01:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-05-13 01:01:26 +0400
commitb224cbe6b6fd4fcfee08be4f8287d9931a7eb605 (patch)
tree88d71336c08393d44aeaf65d6525aaaa4f472552
parented12a5d001a5521cf71d740c2e48c62e6a67b8bd (diff)
fix for own bad logic with polygon normal calculation, was reading one past the loop array (reported as bug #31431).
-rw-r--r--source/blender/blenkernel/intern/mesh.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 944f06cf740..16e75fff702 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -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 */
}
}