diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-09-19 08:48:34 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-09-19 08:48:34 +0400 |
commit | db051f2b2ddae22b6ff7468ae5cca7884d5b06da (patch) | |
tree | 67dc02d3c2d30fde68c8d7889bf93cff0ccff3d4 /source | |
parent | 946c9580b5d2735072fa2a4bd817c23fe269ec91 (diff) |
fix MESH_OT_tris_convert_to_quads() limit options (uv and vertex color) were not working at all.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_math_color.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 15 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 9 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_join_triangles.c | 141 |
5 files changed, 88 insertions, 80 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h index 6fe5d48d06e..7c8bf88943d 100644 --- a/source/blender/blenlib/BLI_math_color.h +++ b/source/blender/blenlib/BLI_math_color.h @@ -115,6 +115,8 @@ void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]); void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b); +MINLINE int compare_rgb_uchar(const unsigned char a[3], const unsigned char b[3], const int limit); + /***************** lift/gamma/gain / ASC-CDL conversion *****************/ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power); diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 6c81ca3f0a9..de1d423bfad 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -173,6 +173,7 @@ MINLINE int is_one_v3(const float a[3]); MINLINE int equals_v2v2(const float v1[2], const float v2[2]); MINLINE int equals_v3v3(const float a[3], const float b[3]); +MINLINE int compare_v2v2(const float a[3], const float b[3], const float limit); MINLINE int compare_v3v3(const float a[3], const float b[3], const float limit); MINLINE int compare_len_v3v3(const float a[3], const float b[3], const float limit); diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 6b90cbfe9c3..f520b2318e5 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -273,5 +273,20 @@ MINLINE float rgb_to_luma_y(const float rgb[3]) return 0.212671f * rgb[0] + 0.71516f * rgb[1] + 0.072169f * rgb[2]; } +MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char col_b[3], const int limit) +{ + int r = (int)col_a[0] - (int)col_b[0]; + if (ABS(r) < limit) { + int g = (int)col_a[1] - (int)col_b[1]; + if (ABS(g) < limit) { + int b = (int)col_a[2] - (int)col_b[2]; + if (ABS(b) < limit) { + return 1; + } + } + } + + return 0; +} #endif /* __MATH_COLOR_INLINE_C__ */ diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 0a8f57214d7..c409e536b45 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -724,6 +724,15 @@ MINLINE int equals_v4v4(const float v1[4], const float v2[4]) return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3])); } +MINLINE int compare_v2v2(const float v1[2], const float v2[2], const float limit) +{ + if (fabsf(v1[0] - v2[0]) < limit) + if (fabsf(v1[1] - v2[1]) < limit) + return 1; + + return 0; +} + MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit) { if (fabsf(v1[0] - v2[0]) < limit) diff --git a/source/blender/bmesh/operators/bmo_join_triangles.c b/source/blender/bmesh/operators/bmo_join_triangles.c index d780e309118..4d052dd2959 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.c +++ b/source/blender/bmesh/operators/bmo_join_triangles.c @@ -110,93 +110,73 @@ static float measure_facepair(BMVert *v1, BMVert *v2, #define T2QUV_LIMIT 0.005f #define T2QCOL_LIMIT 3 -static int compareFaceAttribs(BMesh *bm, BMEdge *e, int douvs, int dovcols) +static int bm_edge_faces_cmp(BMesh *bm, BMEdge *e, const int do_uv, const int do_tf, const int do_vcol) { - MTexPoly *tp1, *tp2; - MLoopCol *lcol1, *lcol2, *lcol3, *lcol4; - MLoopUV *luv1, *luv2, *luv3, *luv4; - BMLoop *l1, *l2, *l3, *l4; - int mergeok_uvs = !douvs, mergeok_vcols = !dovcols; - - l1 = e->l; - l3 = e->l->radial_next; + /* first get loops */ + BMLoop *l[4]; + + l[0] = e->l; + l[2] = e->l->radial_next; - /* match up loops on each side of an edge corresponding to each ver */ - if (l1->v == l3->v) { - l2 = l1->next; - l4 = l2->next; + /* match up loops on each side of an edge corresponding to each vert */ + if (l[0]->v == l[2]->v) { + l[1] = l[0]->next; + l[3] = l[1]->next; } else { - l2 = l1->next; + l[1] = l[0]->next; - l4 = l3; - l3 = l4->next; + l[3] = l[2]; + l[2] = l[3]->next; } - lcol1 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPCOL); - lcol2 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPCOL); - lcol3 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPCOL); - lcol4 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPCOL); - - luv1 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPUV); - luv2 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPUV); - luv3 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPUV); - luv4 = CustomData_bmesh_get(&bm->ldata, l1->head.data, CD_MLOOPUV); - - tp1 = CustomData_bmesh_get(&bm->pdata, l1->f->head.data, CD_MTEXPOLY); - tp2 = CustomData_bmesh_get(&bm->pdata, l2->f->head.data, CD_MTEXPOLY); - - if (!lcol1) - mergeok_vcols = 1; - - if (!luv1) - mergeok_uvs = 1; - - /* compare faceedges for each face attribute. Additional per face attributes can be added late */ - - /* do VCOL */ - if (lcol1 && dovcols) { - char *cols[4] = {(char *)lcol1, (char *)lcol2, (char *)lcol3, (char *)lcol4}; - int i; - - for (i = 0; i < 3; i++) { - if (cols[0][i] + T2QCOL_LIMIT < cols[2][i] - T2QCOL_LIMIT) - break; - if (cols[1][i] + T2QCOL_LIMIT < cols[3][i] - T2QCOL_LIMIT) - break; + /* Test UV's */ + if (do_uv) { + const MLoopUV *luv[4] = { + CustomData_bmesh_get(&bm->ldata, l[0]->head.data, CD_MLOOPUV), + CustomData_bmesh_get(&bm->ldata, l[1]->head.data, CD_MLOOPUV), + CustomData_bmesh_get(&bm->ldata, l[2]->head.data, CD_MLOOPUV), + CustomData_bmesh_get(&bm->ldata, l[3]->head.data, CD_MLOOPUV), + }; + + /* do UV */ + if (luv[0] && (!compare_v2v2(luv[0]->uv, luv[2]->uv, T2QUV_LIMIT) || + !compare_v2v2(luv[1]->uv, luv[3]->uv, T2QUV_LIMIT))) + { + return FALSE; } - - if (i == 3) - mergeok_vcols = 1; } - /* do UV */ - if (luv1 && douvs) { - if (tp1->tpage != tp2->tpage) { - /* do nothing */ - } - else { - int i; + if (do_tf) { + const MTexPoly *tp[2] = { + CustomData_bmesh_get(&bm->pdata, l[0]->f->head.data, CD_MTEXPOLY), + CustomData_bmesh_get(&bm->pdata, l[1]->f->head.data, CD_MTEXPOLY), + }; - for (i = 0; i < 2; i++) { - if (luv1->uv[0] + T2QUV_LIMIT > luv3->uv[0] && luv1->uv[0] - T2QUV_LIMIT < luv3->uv[0] && - luv1->uv[1] + T2QUV_LIMIT > luv3->uv[1] && luv1->uv[1] - T2QUV_LIMIT < luv3->uv[1]) - { - if (luv2->uv[0] + T2QUV_LIMIT > luv4->uv[0] && luv2->uv[0] - T2QUV_LIMIT < luv4->uv[0] && - luv2->uv[1] + T2QUV_LIMIT > luv4->uv[1] && luv2->uv[1] - T2QUV_LIMIT < luv4->uv[1]) - { - mergeok_uvs = 1; - } - } - } + if (tp[0] && (tp[0]->tpage != tp[1]->tpage)) { + return FALSE; } } - if (douvs == mergeok_uvs && dovcols == mergeok_vcols) { - return TRUE; + /* Test Vertex Colors */ + if (do_vcol) { + const MLoopCol *lcol[4] = { + CustomData_bmesh_get(&bm->ldata, l[0]->head.data, CD_MLOOPCOL), + CustomData_bmesh_get(&bm->ldata, l[1]->head.data, CD_MLOOPCOL), + CustomData_bmesh_get(&bm->ldata, l[2]->head.data, CD_MLOOPCOL), + CustomData_bmesh_get(&bm->ldata, l[3]->head.data, CD_MLOOPCOL), + }; + + if (lcol[0]) { + if (!compare_rgb_uchar((unsigned char*)&lcol[0]->r, (unsigned char*)&lcol[2]->r, T2QCOL_LIMIT) || + !compare_rgb_uchar((unsigned char*)&lcol[1]->r, (unsigned char*)&lcol[3]->r, T2QCOL_LIMIT)) + { + return FALSE; + } + } } - return FALSE; + return TRUE; } typedef struct JoinEdge { @@ -229,11 +209,12 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) BMEdge *e; BLI_array_declare(jedges); JoinEdge *jedges = NULL; - int dosharp = BMO_slot_bool_get(op, "cmp_sharp"); - int douvs = BMO_slot_bool_get(op, "cmp_uvs"); - int dovcols = BMO_slot_bool_get(op, "cmp_vcols"); - int domat = BMO_slot_bool_get(op, "cmp_materials"); - float limit = BMO_slot_float_get(op, "limit"); + int do_sharp = BMO_slot_bool_get(op, "cmp_sharp"); + int do_uv = BMO_slot_bool_get(op, "cmp_uvs"); + int do_tf = do_uv; /* texture face, make make its own option eventually */ + int do_vcol = BMO_slot_bool_get(op, "cmp_vcols"); + int do_mat = BMO_slot_bool_get(op, "cmp_materials"); + float limit = BMO_slot_float_get(op, "limit"); int i, totedge; /* flag all edges of all input face */ @@ -282,13 +263,13 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) v3 = e->l->next->v; v4 = e->l->radial_next->prev->v; - if (dosharp && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) + if (do_sharp && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) continue; - - if ((douvs || dovcols) && compareFaceAttribs(bm, e, douvs, dovcols)) + + if (do_mat && f1->mat_nr != f2->mat_nr) continue; - if (domat && f1->mat_nr != f2->mat_nr) + if ((do_uv || do_tf || do_vcol) && (bm_edge_faces_cmp(bm, e, do_uv, do_tf, do_vcol) == FALSE)) continue; measure = measure_facepair(v1, v2, v3, v4, limit); |