diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-08-10 14:24:26 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-08-10 14:24:26 +0300 |
commit | b9898ebde44d6584ea37a05aaeca8760d31ccc7b (patch) | |
tree | e6dfc796cc82b4b8b8c248c4ff29d2e2047ff84c /source/blender/bmesh/intern/bmesh_construct.c | |
parent | b17380971a144896b34b7863a82bbda3ff68a39f (diff) | |
parent | 553b581f25c1782c4231816965cd3f6ce58a449a (diff) |
Merge branch 'master' into filebrowser_redesign
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_construct.c')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 88 |
1 files changed, 11 insertions, 77 deletions
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index 224f6ad1e5c..c8eab9c4b8c 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -390,79 +390,13 @@ void BM_verts_sort_radial_plane(BMVert **vert_arr, int len) struct SortIntByFloat *vang = BLI_array_alloca(vang, len); BMVert **vert_arr_map = BLI_array_alloca(vert_arr_map, len); - float totv_inv = 1.0f / (float)len; - int i = 0; + float nor[3], cent[3]; + int index_tangent = 0; + BM_verts_calc_normal_from_cloud_ex(vert_arr, len, nor, cent, &index_tangent); + const float *far = vert_arr[index_tangent]->co; - float cent[3], nor[3]; - - const float *far = NULL, *far_cross = NULL; - - float far_vec[3]; - float far_cross_vec[3]; - float sign_vec[3]; /* work out if we are pos/neg angle */ - - float far_dist_sq, far_dist_max_sq; - float far_cross_dist, far_cross_best = 0.0f; - - /* get the center point and collect vector array since we loop over these a lot */ - zero_v3(cent); - for (i = 0; i < len; i++) { - madd_v3_v3fl(cent, vert_arr[i]->co, totv_inv); - } - - /* find the far point from cent */ - far_dist_max_sq = 0.0f; - for (i = 0; i < len; i++) { - far_dist_sq = len_squared_v3v3(vert_arr[i]->co, cent); - if (far_dist_sq > far_dist_max_sq || far == NULL) { - far = vert_arr[i]->co; - far_dist_max_sq = far_dist_sq; - } - } - - sub_v3_v3v3(far_vec, far, cent); - // far_dist = len_v3(far_vec); /* real dist */ /* UNUSED */ - - /* --- */ - - /* find a point 90deg about to compare with */ - far_cross_best = 0.0f; - for (i = 0; i < len; i++) { - - if (far == vert_arr[i]->co) { - continue; - } - - sub_v3_v3v3(far_cross_vec, vert_arr[i]->co, cent); - far_cross_dist = normalize_v3(far_cross_vec); - - /* more of a weight then a distance */ - far_cross_dist = ( - /* First we want to have a value close to zero mapped to 1. */ - 1.0f - fabsf(dot_v3v3(far_vec, far_cross_vec)) * - /* Second we multiply by the distance - * so points close to the center are not preferred. */ - far_cross_dist); - - if (far_cross_dist > far_cross_best || far_cross == NULL) { - far_cross = vert_arr[i]->co; - far_cross_best = far_cross_dist; - } - } - - sub_v3_v3v3(far_cross_vec, far_cross, cent); - - /* --- */ - - /* now we have 2 vectors we can have a cross product */ - cross_v3_v3v3(nor, far_vec, far_cross_vec); - normalize_v3(nor); - cross_v3_v3v3(sign_vec, far_vec, nor); /* this vector should match 'far_cross_vec' closely */ - - /* --- */ - - /* now calculate every points angle around the normal (signed) */ - for (i = 0; i < len; i++) { + /* Now calculate every points angle around the normal (signed). */ + for (int i = 0; i < len; i++) { vang[i].sort_value = angle_signed_on_axis_v3v3v3_v3(far, cent, vert_arr[i]->co, nor); vang[i].data = i; vert_arr_map[i] = vert_arr[i]; @@ -473,7 +407,7 @@ void BM_verts_sort_radial_plane(BMVert **vert_arr, int len) /* --- */ - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { vert_arr[i] = vert_arr_map[vang[i].data]; } } @@ -487,7 +421,7 @@ static void bm_vert_attrs_copy(BMesh *source_mesh, uint64_t cd_mask) { if ((source_mesh == target_mesh) && (source_vertex == target_vertex)) { - BLI_assert(!"BMVert: source and targer match"); + BLI_assert(!"BMVert: source and target match"); return; } if ((cd_mask & CD_MASK_NORMAL) == 0) { @@ -507,7 +441,7 @@ static void bm_edge_attrs_copy(BMesh *source_mesh, uint64_t UNUSED(cd_mask)) { if ((source_mesh == target_mesh) && (source_edge == target_edge)) { - BLI_assert(!"BMEdge: source and targer match"); + BLI_assert(!"BMEdge: source and target match"); return; } CustomData_bmesh_free_block_data(&target_mesh->edata, target_edge->head.data); @@ -522,7 +456,7 @@ static void bm_loop_attrs_copy(BMesh *source_mesh, uint64_t UNUSED(cd_mask)) { if ((source_mesh == target_mesh) && (source_loop == target_loop)) { - BLI_assert(!"BMLoop: source and targer match"); + BLI_assert(!"BMLoop: source and target match"); return; } CustomData_bmesh_free_block_data(&target_mesh->ldata, target_loop->head.data); @@ -537,7 +471,7 @@ static void bm_face_attrs_copy(BMesh *source_mesh, uint64_t cd_mask) { if ((source_mesh == target_mesh) && (source_face == target_face)) { - BLI_assert(!"BMFace: source and targer match"); + BLI_assert(!"BMFace: source and target match"); return; } if ((cd_mask & CD_MASK_NORMAL) == 0) { |