fix issue with new bridge tool interpolation [#35636]

This commit is contained in:
Campbell Barton
2013-06-05 21:31:01 +00:00
parent 71758cb5d7
commit 4835f63be2
3 changed files with 32 additions and 12 deletions

View File

@@ -47,7 +47,7 @@ typedef struct BMEdgeLoopStore {
} BMEdgeLoopStore;
#define BM_EDGELOOP_IS_CLOSED (1 << 0)
#define EDGELOOP_EPS 0.00001f
/* -------------------------------------------------------------------- */
/* BM_mesh_edgeloops_find & Util Functions */
@@ -580,7 +580,7 @@ void BM_edgeloop_calc_center(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store)
}
void BM_edgeloop_calc_normal(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store)
bool BM_edgeloop_calc_normal(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store)
{
LinkData *node_curr = el_store->verts.first;
float const *v_prev = NODE_AS_CO(el_store->verts.last);
@@ -601,8 +601,13 @@ void BM_edgeloop_calc_normal(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store)
}
} while (true);
if (UNLIKELY(normalize_v3(el_store->no) == 0.0f)) {
if (UNLIKELY(normalize_v3(el_store->no) < EDGELOOP_EPS)) {
el_store->no[2] = 1.0f; /* other axis set to 0.0 */
return false;
}
else {
return true;
}
}
@@ -612,7 +617,7 @@ void BM_edgeloop_calc_normal(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store)
*
* Instead use an alignment vector and calculate the normal based on that.
*/
void BM_edgeloop_calc_normal_aligned(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store, const float no_align[3])
bool BM_edgeloop_calc_normal_aligned(BMesh *UNUSED(bm), BMEdgeLoopStore *el_store, const float no_align[3])
{
LinkData *node_curr = el_store->verts.first;
float const *v_prev = NODE_AS_CO(el_store->verts.last);
@@ -637,8 +642,12 @@ void BM_edgeloop_calc_normal_aligned(BMesh *UNUSED(bm), BMEdgeLoopStore *el_stor
}
} while (true);
if (UNLIKELY(normalize_v3(el_store->no) == 0.0f)) {
if (UNLIKELY(normalize_v3(el_store->no) < EDGELOOP_EPS)) {
el_store->no[2] = 1.0f; /* other axis set to 0.0 */
return false;
}
else {
return true;
}
}

View File

@@ -58,8 +58,8 @@ const float *BM_edgeloop_normal_get(struct BMEdgeLoopStore *el_store);
const float *BM_edgeloop_center_get(struct BMEdgeLoopStore *el_store);
void BM_edgeloop_edges_get(struct BMEdgeLoopStore *el_store, BMEdge **e_arr);
void BM_edgeloop_calc_center(BMesh *bm, struct BMEdgeLoopStore *el_store);
void BM_edgeloop_calc_normal(BMesh *bm, struct BMEdgeLoopStore *el_store);
void BM_edgeloop_calc_normal_aligned(BMesh *bm, struct BMEdgeLoopStore *el_store,
bool BM_edgeloop_calc_normal(BMesh *bm, struct BMEdgeLoopStore *el_store);
bool BM_edgeloop_calc_normal_aligned(BMesh *bm, struct BMEdgeLoopStore *el_store,
const float no_align[3]);
void BM_edgeloop_flip(BMesh *bm, struct BMEdgeLoopStore *el_store);
void BM_edgeloop_expand(BMesh *bm, struct BMEdgeLoopStore *el_store, int el_store_len);

View File

@@ -547,6 +547,7 @@ static void bm_edgering_pair_interpolate(BMesh *bm, LoopPairStore *lpair,
{
const int resolu = cuts + 2;
const int dims = 3;
bool is_a_no_valid, is_b_no_valid;
int i;
float el_store_a_co[3], el_store_b_co[3];
@@ -559,20 +560,30 @@ static void bm_edgering_pair_interpolate(BMesh *bm, LoopPairStore *lpair,
BM_edgeloop_calc_center(bm, el_store_a);
BM_edgeloop_calc_center(bm, el_store_b);
BM_edgeloop_calc_normal(bm, el_store_a);
BM_edgeloop_calc_normal(bm, el_store_b);
is_a_no_valid = BM_edgeloop_calc_normal(bm, el_store_a);
is_b_no_valid = BM_edgeloop_calc_normal(bm, el_store_b);
copy_v3_v3(el_store_a_co, BM_edgeloop_center_get(el_store_a));
copy_v3_v3(el_store_b_co, BM_edgeloop_center_get(el_store_b));
copy_v3_v3(el_store_a_no, BM_edgeloop_normal_get(el_store_a));
copy_v3_v3(el_store_b_no, BM_edgeloop_normal_get(el_store_b));
/* correct normals need to be flipped to face each other
* we know both normals point in the same direction so one will need flipping */
{
float el_dir[3];
float no[3];
sub_v3_v3v3(el_dir, el_store_a_co, el_store_b_co);
normalize_v3_v3(no, el_dir);
if (is_a_no_valid == false) {
is_a_no_valid = BM_edgeloop_calc_normal_aligned(bm, el_store_a, no);
}
if (is_b_no_valid == false) {
is_b_no_valid = BM_edgeloop_calc_normal_aligned(bm, el_store_b, no);
}
(void)is_a_no_valid, (void)is_b_no_valid;
copy_v3_v3(el_store_a_no, BM_edgeloop_normal_get(el_store_a));
copy_v3_v3(el_store_b_no, BM_edgeloop_normal_get(el_store_b));
if (dot_v3v3(el_store_a_no, el_dir) > 0.0f) {
negate_v3(el_store_a_no);