diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-06-20 12:28:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-06-20 12:28:51 +0300 |
commit | e019d8fb8c3bdab9c2eb20f6217c93af704979f5 (patch) | |
tree | 45d2c477590c18c3b03d303fa3786b23e8633a65 | |
parent | e3fe56d9d1463bd0ac313b10dc1a1ad5b340f942 (diff) |
Transform: UV islands were split by winding
This meant front/back faces from a projection would be seen as separate islands.
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.c | 33 | ||||
-rw-r--r-- | source/blender/editors/include/ED_mesh.h | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_utils.c | 34 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_uv.c | 8 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 2 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_smart_stitch.c | 4 |
6 files changed, 55 insertions, 30 deletions
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index 8b41aded3d9..1d8978586b6 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -79,14 +79,12 @@ UvVertMap *BKE_mesh_uv_vert_map_create( if (totuv == 0) return NULL; - winding = MEM_callocN(sizeof(*winding) * totpoly, "winding"); vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap"); - - if (!vmap) - return NULL; - - vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totvert, "UvMapVert*"); buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf) * (size_t)totuv, "UvMapVert"); + vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totvert, "UvMapVert*"); + if (use_winding) { + winding = MEM_callocN(sizeof(*winding) * totpoly, "winding"); + } if (!vmap->vert || !vmap->buf) { BKE_mesh_uv_vert_map_free(vmap); @@ -96,7 +94,11 @@ UvVertMap *BKE_mesh_uv_vert_map_create( mp = mpoly; for (a = 0; a < totpoly; a++, mp++) { if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL))) { - float (*tf_uv)[2] = (float (*)[2])BLI_buffer_resize_data(&tf_uv_buf, vec2f, mp->totloop); + float (*tf_uv)[2]; + + if (use_winding) { + tf_uv = (float (*)[2])BLI_buffer_resize_data(&tf_uv_buf, vec2f, mp->totloop); + } nverts = mp->totloop; @@ -107,14 +109,16 @@ UvVertMap *BKE_mesh_uv_vert_map_create( buf->next = vmap->vert[mloop[mp->loopstart + i].v]; vmap->vert[mloop[mp->loopstart + i].v] = buf; - copy_v2_v2(tf_uv[i], mloopuv[mpoly[a].loopstart + i].uv); + if (use_winding) { + copy_v2_v2(tf_uv[i], mloopuv[mpoly[a].loopstart + i].uv); + } + buf++; } - if (use_winding) + if (use_winding) { winding[a] = cross_poly_v2((const float (*)[2])tf_uv, (unsigned int)nverts) > 0; - else - winding[a] = 0; + } } } @@ -142,7 +146,7 @@ UvVertMap *BKE_mesh_uv_vert_map_create( if (fabsf(uv[0] - uv2[0]) < limit[0] && fabsf(uv[1] - uv2[1]) < limit[1] && - winding[iterv->f] == winding[v->f]) + (!use_winding || winding[iterv->f] == winding[v->f])) { if (lastv) lastv->next = next; else vlist = next; @@ -161,7 +165,10 @@ UvVertMap *BKE_mesh_uv_vert_map_create( vmap->vert[a] = newvlist; } - MEM_freeN(winding); + if (use_winding) { + MEM_freeN(winding); + } + BLI_buffer_free(&tf_uv_buf); return vmap; diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 3f16055e762..9534da622fb 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -107,7 +107,9 @@ void EDBM_mesh_reveal(struct BMEditMesh *em); void EDBM_update_generic(struct BMEditMesh *em, const bool do_tessface, const bool is_destructive); -struct UvElementMap *BM_uv_element_map_create(struct BMesh *bm, const bool selected, const bool do_islands); +struct UvElementMap *BM_uv_element_map_create( + struct BMesh *bm, + const bool selected, const bool use_winding, const bool do_islands); void BM_uv_element_map_free(struct UvElementMap *vmap); struct UvElement *BM_uv_element_get(struct UvElementMap *map, struct BMFace *efa, struct BMLoop *l); diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 2e43c9b0be8..d521b2c01e5 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -768,7 +768,9 @@ UvMapVert *BM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v) /* A specialized vert map used by stitch operator */ -UvElementMap *BM_uv_element_map_create(BMesh *bm, const bool selected, const bool do_islands) +UvElementMap *BM_uv_element_map_create( + BMesh *bm, + const bool selected, const bool use_winding, const bool do_islands) { BMVert *ev; BMFace *efa; @@ -807,14 +809,22 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, const bool selected, const boo element_map->vert = (UvElement **)MEM_callocN(sizeof(*element_map->vert) * totverts, "UvElementVerts"); buf = element_map->buf = (UvElement *)MEM_callocN(sizeof(*element_map->buf) * totuv, "UvElement"); - winding = MEM_mallocN(sizeof(*winding) * totfaces, "winding"); + if (use_winding) { + winding = MEM_mallocN(sizeof(*winding) * totfaces, "winding"); + } BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, j) { - winding[j] = false; + if (use_winding) { + winding[j] = false; + } if (!selected || BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - float (*tf_uv)[2] = (float (*)[2])BLI_buffer_resize_data(&tf_uv_buf, vec2f, efa->len); + float (*tf_uv)[2]; + + if (use_winding) { + tf_uv = (float (*)[2])BLI_buffer_resize_data(&tf_uv_buf, vec2f, efa->len); + } BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { buf->l = l; @@ -825,13 +835,17 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, const bool selected, const boo buf->next = element_map->vert[BM_elem_index_get(l->v)]; element_map->vert[BM_elem_index_get(l->v)] = buf; - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - copy_v2_v2(tf_uv[i], luv->uv); + if (use_winding) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + copy_v2_v2(tf_uv[i], luv->uv); + } buf++; } - winding[j] = cross_poly_v2((const float (*)[2])tf_uv, efa->len) > 0; + if (use_winding) { + winding[j] = cross_poly_v2((const float (*)[2])tf_uv, efa->len) > 0; + } } } @@ -864,7 +878,7 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, const bool selected, const boo sub_v2_v2v2(uvdiff, uv2, uv); if (fabsf(uvdiff[0]) < STD_UV_CONNECT_LIMIT && fabsf(uvdiff[1]) < STD_UV_CONNECT_LIMIT && - winding[BM_elem_index_get(iterv->l->f)] == winding[BM_elem_index_get(v->l->f)]) + (!use_winding || winding[BM_elem_index_get(iterv->l->f)] == winding[BM_elem_index_get(v->l->f)])) { if (lastv) lastv->next = next; else vlist = next; @@ -884,7 +898,9 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, const bool selected, const boo element_map->vert[i] = newvlist; } - MEM_freeN(winding); + if (use_winding) { + MEM_freeN(winding); + } if (do_islands) { unsigned int *map; diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 4e1517b4e0d..03ca38f2df7 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -612,18 +612,18 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm if (do_island_optimization) { /* We will need island information */ if (ts->uv_flag & UV_SYNC_SELECTION) { - data->elementMap = BM_uv_element_map_create(bm, false, true); + data->elementMap = BM_uv_element_map_create(bm, false, true, true); } else { - data->elementMap = BM_uv_element_map_create(bm, true, true); + data->elementMap = BM_uv_element_map_create(bm, true, true, true); } } else { if (ts->uv_flag & UV_SYNC_SELECTION) { - data->elementMap = BM_uv_element_map_create(bm, false, false); + data->elementMap = BM_uv_element_map_create(bm, false, false, true); } else { - data->elementMap = BM_uv_element_map_create(bm, true, false); + data->elementMap = BM_uv_element_map_create(bm, true, false, true); } } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index bcd69538b44..abaa55e3e9c 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2741,7 +2741,7 @@ static void createTransUVs(bContext *C, TransInfo *t) if (is_prop_connected || is_island_center) { /* create element map with island information */ const bool use_facesel = (ts->uv_flag & UV_SYNC_SELECTION) == 0; - elementmap = BM_uv_element_map_create(em->bm, use_facesel, true); + elementmap = BM_uv_element_map_create(em->bm, use_facesel, false, true); if (elementmap == NULL) { return; } diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index f7a8735ccca..828537fd585 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -1649,10 +1649,10 @@ static int stitch_init(bContext *C, wmOperator *op) /* in uv synch selection, all uv's are visible */ if (ts->uv_flag & UV_SYNC_SELECTION) { - state->element_map = BM_uv_element_map_create(state->em->bm, false, true); + state->element_map = BM_uv_element_map_create(state->em->bm, false, true, true); } else { - state->element_map = BM_uv_element_map_create(state->em->bm, true, true); + state->element_map = BM_uv_element_map_create(state->em->bm, true, true, true); } if (!state->element_map) { state_delete(state); |