diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-05-20 16:28:56 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-05-20 17:00:13 +0300 |
commit | 24e1d7f4f4aba8e94effd6aec4a3d7d8308d4015 (patch) | |
tree | 537ce4973f8a01065ac78696830400c8d9136762 /source/blender | |
parent | 8edfcf653a97628504de893b0d9b091783d136fc (diff) |
BMesh: decimate wasn't using face/edge centers
When calculating quadrics, using the first-vertex isn't correct.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_quadric.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/quadric.c | 10 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_decimate_collapse.c | 24 |
3 files changed, 22 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_quadric.h b/source/blender/blenlib/BLI_quadric.h index 82c39463dd2..251469ab88f 100644 --- a/source/blender/blenlib/BLI_quadric.h +++ b/source/blender/blenlib/BLI_quadric.h @@ -38,7 +38,7 @@ typedef struct Quadric { } Quadric; /* conversion */ -void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset); +void BLI_quadric_from_plane(Quadric *q, const float v[4]); void BLI_quadric_to_tensor_m3(const Quadric *q, float m[3][3]); void BLI_quadric_to_vector_v3(const Quadric *q, float v[3]); diff --git a/source/blender/blenlib/intern/quadric.c b/source/blender/blenlib/intern/quadric.c index 814d05ca80e..4aa0cdd509d 100644 --- a/source/blender/blenlib/intern/quadric.c +++ b/source/blender/blenlib/intern/quadric.c @@ -42,7 +42,7 @@ #define QUADRIC_FLT_TOT (sizeof(Quadric) / sizeof(float)) -void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset) +void BLI_quadric_from_plane(Quadric *q, const float v[4]) { q->a2 = v[0] * v[0]; q->b2 = v[1] * v[1]; @@ -52,11 +52,11 @@ void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset) q->ac = v[0] * v[2]; q->bc = v[1] * v[2]; - q->ad = v[0] * offset; - q->bd = v[1] * offset; - q->cd = v[2] * offset; + q->ad = v[0] * v[3]; + q->bd = v[1] * v[3]; + q->cd = v[2] * v[3]; - q->d2 = offset * offset; + q->d2 = v[3] * v[3]; } void BLI_quadric_to_tensor_m3(const Quadric *q, float m[3][3]) diff --git a/source/blender/bmesh/tools/bmesh_decimate_collapse.c b/source/blender/bmesh/tools/bmesh_decimate_collapse.c index fde60397167..f2e2d25c0a6 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_collapse.c +++ b/source/blender/bmesh/tools/bmesh_decimate_collapse.c @@ -77,12 +77,15 @@ static void bm_decim_build_quadrics(BMesh *bm, Quadric *vquadrics) BMLoop *l_first; BMLoop *l_iter; - const float *co = BM_FACE_FIRST_LOOP(f)->v->co; - const float *no = f->no; - const float offset = -dot_v3v3(no, co); + float center[3]; + float plane[4]; Quadric q; - BLI_quadric_from_v3_dist(&q, no, offset); + BM_face_calc_center_mean(f, center); + copy_v3_v3(plane, f->no); + plane[3] = -dot_v3v3(plane, center); + + BLI_quadric_from_plane(&q, plane); l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { @@ -94,14 +97,19 @@ static void bm_decim_build_quadrics(BMesh *bm, Quadric *vquadrics) BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { if (UNLIKELY(BM_edge_is_boundary(e))) { float edge_vector[3]; - float edge_cross[3]; + float edge_plane[4]; sub_v3_v3v3(edge_vector, e->v2->co, e->v1->co); f = e->l->f; - cross_v3_v3v3(edge_cross, edge_vector, f->no); + cross_v3_v3v3(edge_plane, edge_vector, f->no); - if (normalize_v3(edge_cross) > FLT_EPSILON) { + if (normalize_v3(edge_plane) > FLT_EPSILON) { Quadric q; - BLI_quadric_from_v3_dist(&q, edge_cross, -dot_v3v3(edge_cross, e->v1->co)); + float center[3]; + + mid_v3_v3v3(center, e->v1->co, e->v2->co); + edge_plane[3] = -dot_v3v3(edge_plane, center); + + BLI_quadric_from_plane(&q, edge_plane); BLI_quadric_mul(&q, BOUNDARY_PRESERVE_WEIGHT); BLI_quadric_add_qu_qu(&vquadrics[BM_elem_index_get(e->v1)], &q); |