diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-05-28 19:08:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-05-28 19:08:13 +0400 |
commit | 88d385ef70a1b8775abad29c2ec3180ff3474c82 (patch) | |
tree | a07ad22acb9cb1426336738bf437eb6fb4752426 | |
parent | 33d609144ef60c0223b2925cd39a713ed8c9060c (diff) |
fix [#35509] MedianPoint choice has bad normals
-rw-r--r-- | source/blender/bmesh/intern/bmesh_marking.c | 67 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 54 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.h | 1 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 4 |
4 files changed, 59 insertions, 67 deletions
diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index 2cc84671e41..2608a79d455 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -675,6 +675,7 @@ void BM_editselection_plane(BMEditSelection *ese, float r_plane[3]) else vec[2] = 1.0f; cross_v3_v3v3(r_plane, eve->no, vec); } + normalize_v3(r_plane); } else if (ese->htype == BM_EDGE) { BMEdge *eed = (BMEdge *)ese->ele; @@ -690,74 +691,12 @@ void BM_editselection_plane(BMEditSelection *ese, float r_plane[3]) else { sub_v3_v3v3(r_plane, eed->v1->co, eed->v2->co); } - + normalize_v3(r_plane); } else if (ese->htype == BM_FACE) { BMFace *efa = (BMFace *)ese->ele; - float vec[3] = {0.0f, 0.0f, 0.0f}; - - /* for now, use face normal */ - - /* make a fake plane thats at rightangles to the normal - * we cant make a crossvec from a vec thats the same as the vec - * unlikely but possible, so make sure if the normal is (0, 0, 1) - * that vec isn't the same or in the same direction even. */ - if (UNLIKELY(efa->len < 3)) { - /* crappy fallback method */ - if (efa->no[0] < 0.5f) vec[0] = 1.0f; - else if (efa->no[1] < 0.5f) vec[1] = 1.0f; - else vec[2] = 1.0f; - cross_v3_v3v3(r_plane, efa->no, vec); - } - else { - if (efa->len == 3) { - BMVert *verts[3]; - float lens[3]; - float difs[3]; - int order[3] = {0, 1, 2}; - - BM_face_as_array_vert_tri(efa, verts); - - lens[0] = len_v3v3(verts[0]->co, verts[1]->co); - lens[1] = len_v3v3(verts[1]->co, verts[2]->co); - lens[2] = len_v3v3(verts[2]->co, verts[0]->co); - - /* find the shortest or the longest loop */ - difs[0] = fabsf(lens[1] - lens[2]); - difs[1] = fabsf(lens[2] - lens[0]); - difs[2] = fabsf(lens[0] - lens[1]); - - axis_sort_v3(difs, order); - sub_v3_v3v3(r_plane, verts[order[0]]->co, verts[(order[0] + 1) % 3]->co); - } - else if (efa->len == 4) { - BMVert *verts[4]; - float vecA[3], vecB[3]; - - // BM_iter_as_array(NULL, BM_VERTS_OF_FACE, efa, (void **)verts, 4); - BM_face_as_array_vert_quad(efa, verts); - - sub_v3_v3v3(vecA, verts[3]->co, verts[2]->co); - sub_v3_v3v3(vecB, verts[0]->co, verts[1]->co); - add_v3_v3v3(r_plane, vecA, vecB); - - sub_v3_v3v3(vecA, verts[0]->co, verts[3]->co); - sub_v3_v3v3(vecB, verts[1]->co, verts[2]->co); - add_v3_v3v3(vec, vecA, vecB); - /* use the biggest edge length */ - if (dot_v3v3(r_plane, r_plane) < dot_v3v3(vec, vec)) { - copy_v3_v3(r_plane, vec); - } - } - else { - BMLoop *l_long = BM_face_find_longest_loop(efa); - - sub_v3_v3v3(r_plane, l_long->v->co, l_long->next->v->co); - } - - } + BM_face_calc_plane(efa, r_plane); } - normalize_v3(r_plane); } diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index a6cad4a6ead..cce1808ed3b 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -292,6 +292,60 @@ float BM_face_calc_perimeter(BMFace *f) } /** + * Compute a meaningful direction along the face (use for manipulator axis). + * \note result isnt normalized. + */ +void BM_face_calc_plane(BMFace *f, float r_plane[3]) +{ + if (f->len == 3) { + BMVert *verts[3]; + float lens[3]; + float difs[3]; + int order[3] = {0, 1, 2}; + + BM_face_as_array_vert_tri(f, verts); + + lens[0] = len_v3v3(verts[0]->co, verts[1]->co); + lens[1] = len_v3v3(verts[1]->co, verts[2]->co); + lens[2] = len_v3v3(verts[2]->co, verts[0]->co); + + /* find the shortest or the longest loop */ + difs[0] = fabsf(lens[1] - lens[2]); + difs[1] = fabsf(lens[2] - lens[0]); + difs[2] = fabsf(lens[0] - lens[1]); + + axis_sort_v3(difs, order); + sub_v3_v3v3(r_plane, verts[order[0]]->co, verts[(order[0] + 1) % 3]->co); + } + else if (f->len == 4) { + BMVert *verts[4]; + float vec[3], vec_a[3], vec_b[3]; + + // BM_iter_as_array(NULL, BM_VERTS_OF_FACE, efa, (void **)verts, 4); + BM_face_as_array_vert_quad(f, verts); + + sub_v3_v3v3(vec_a, verts[3]->co, verts[2]->co); + sub_v3_v3v3(vec_b, verts[0]->co, verts[1]->co); + add_v3_v3v3(r_plane, vec_a, vec_b); + + sub_v3_v3v3(vec_a, verts[0]->co, verts[3]->co); + sub_v3_v3v3(vec_b, verts[1]->co, verts[2]->co); + add_v3_v3v3(vec, vec_a, vec_b); + /* use the biggest edge length */ + if (dot_v3v3(r_plane, r_plane) < dot_v3v3(vec, vec)) { + copy_v3_v3(r_plane, vec); + } + } + else { + BMLoop *l_long = BM_face_find_longest_loop(f); + + sub_v3_v3v3(r_plane, l_long->v->co, l_long->next->v->co); + } + + normalize_v3(r_plane); +} + +/** * computes center of face in 3d. uses center of bounding box. */ void BM_face_calc_center_bounds(BMFace *f, float r_cent[3]) diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h index d857ba77fe7..428a98e776c 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.h +++ b/source/blender/bmesh/intern/bmesh_polygon.h @@ -35,6 +35,7 @@ int BM_face_calc_tessellation(BMFace *f, BMLoop **r_loops, int (*r_index)[3]) ; float BM_face_calc_area(BMFace *f); float BM_face_calc_perimeter(BMFace *f); +void BM_face_calc_plane(BMFace *f, float r_plane[3]); void BM_face_calc_center_bounds(BMFace *f, float center[3]); void BM_face_calc_center_mean(BMFace *f, float center[3]); void BM_face_calc_center_mean_weighted(BMFace *f, float center[3]); diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 25c4682a588..70e01ef3718 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -560,10 +560,8 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { + BM_face_calc_plane(efa, vec); add_v3_v3(normal, efa->no); - sub_v3_v3v3(vec, - BM_FACE_FIRST_LOOP(efa)->v->co, - BM_FACE_FIRST_LOOP(efa)->next->v->co); add_v3_v3(plane, vec); } } |