Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_convert_mesh_uv.c
| Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | #define TMP_LOOP_SELECT_TAG BM_ELEM_TAG_ALT | ||||
| /* Any BM_ELEM_TAG'd loop is added to 'queue_next', this makes sure that we don't add things | /* Any BM_ELEM_TAG'd loop is added to 'queue_next', this makes sure that we don't add things | ||||
| * twice. */ | * twice. */ | ||||
| BLI_LINKSTACK_DECLARE(queue_next, BMLoop *); | BLI_LINKSTACK_DECLARE(queue_next, BMLoop *); | ||||
| BLI_LINKSTACK_INIT(queue); | BLI_LINKSTACK_INIT(queue); | ||||
| BLI_LINKSTACK_INIT(queue_next); | BLI_LINKSTACK_INIT(queue_next); | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); | const BMUVOffsets offsets = BM_uv_map_get_offsets(bm); | ||||
| BMIter fiter, liter; | BMIter fiter, liter; | ||||
| BMVert *f; | BMVert *f; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| BM_mesh_elem_index_ensure(bm, BM_LOOP); | BM_mesh_elem_index_ensure(bm, BM_LOOP); | ||||
| BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | ||||
| /* Visible faces was tagged in #createTransUVs. */ | /* Visible faces was tagged in #createTransUVs. */ | ||||
| if (!BM_elem_flag_test(f, BM_ELEM_TAG)) { | if (!BM_elem_flag_test(f, BM_ELEM_TAG)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | ||||
| float dist; | float dist; | ||||
| bool uv_vert_sel = uvedit_uv_select_test_ex(ts, l, cd_loop_uv_offset); | bool uv_vert_sel = uvedit_uv_select_test_ex(ts, l, offsets); | ||||
| if (uv_vert_sel) { | if (uv_vert_sel) { | ||||
| BLI_LINKSTACK_PUSH(queue, l); | BLI_LINKSTACK_PUSH(queue, l); | ||||
| BM_elem_flag_enable(l, TMP_LOOP_SELECT_TAG); | BM_elem_flag_enable(l, TMP_LOOP_SELECT_TAG); | ||||
| dist = 0.0f; | dist = 0.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| BM_elem_flag_disable(l, TMP_LOOP_SELECT_TAG); | BM_elem_flag_disable(l, TMP_LOOP_SELECT_TAG); | ||||
| Show All 14 Lines | #define TMP_LOOP_SELECT_TAG BM_ELEM_TAG_ALT | ||||
| do { | do { | ||||
| while ((l = BLI_LINKSTACK_POP(queue))) { | while ((l = BLI_LINKSTACK_POP(queue))) { | ||||
| BLI_assert(dists[BM_elem_index_get(l)] != FLT_MAX); | BLI_assert(dists[BM_elem_index_get(l)] != FLT_MAX); | ||||
| BMLoop *l_other, *l_connected; | BMLoop *l_other, *l_connected; | ||||
| BMIter l_connected_iter; | BMIter l_connected_iter; | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv); | ||||
| float l_uv[2]; | float l_uv[2]; | ||||
| copy_v2_v2(l_uv, luv->uv); | copy_v2_v2(l_uv, luv); | ||||
| mul_v2_v2(l_uv, aspect); | mul_v2_v2(l_uv, aspect); | ||||
| BM_ITER_ELEM (l_other, &liter, l->f, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l_other, &liter, l->f, BM_LOOPS_OF_FACE) { | ||||
| if (l_other == l) { | if (l_other == l) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| float other_uv[2], edge_vec[2]; | float other_uv[2], edge_vec[2]; | ||||
| MLoopUV *luv_other = BM_ELEM_CD_GET_VOID_P(l_other, cd_loop_uv_offset); | float *luv_other = BM_ELEM_CD_GET_FLOAT_P(l_other, offsets.uv); | ||||
| copy_v2_v2(other_uv, luv_other->uv); | copy_v2_v2(other_uv, luv_other); | ||||
| mul_v2_v2(other_uv, aspect); | mul_v2_v2(other_uv, aspect); | ||||
| sub_v2_v2v2(edge_vec, l_uv, other_uv); | sub_v2_v2v2(edge_vec, l_uv, other_uv); | ||||
| const int i = BM_elem_index_get(l); | const int i = BM_elem_index_get(l); | ||||
| const int i_other = BM_elem_index_get(l_other); | const int i_other = BM_elem_index_get(l_other); | ||||
| float dist = len_v2(edge_vec) + dists_prev[i]; | float dist = len_v2(edge_vec) + dists_prev[i]; | ||||
| Show All 13 Lines | while ((l = BLI_LINKSTACK_POP(queue))) { | ||||
| if (l_connected == l_other) { | if (l_connected == l_other) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Visible faces was tagged in #createTransUVs. */ | /* Visible faces was tagged in #createTransUVs. */ | ||||
| if (!BM_elem_flag_test(l_connected->f, BM_ELEM_TAG)) { | if (!BM_elem_flag_test(l_connected->f, BM_ELEM_TAG)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| MLoopUV *luv_connected = BM_ELEM_CD_GET_VOID_P(l_connected, cd_loop_uv_offset); | float *luv_connected = BM_ELEM_CD_GET_FLOAT_P(l_connected, offsets.uv); | ||||
| connected_vert_sel = BM_elem_flag_test_bool(l_connected, TMP_LOOP_SELECT_TAG); | connected_vert_sel = BM_elem_flag_test_bool(l_connected, TMP_LOOP_SELECT_TAG); | ||||
| /* Check if this loop is connected in UV space. | /* Check if this loop is connected in UV space. | ||||
| * If the uv loops share the same selection state (if not, they are not connected as | * If the uv loops share the same selection state (if not, they are not connected as | ||||
| * they have been ripped or other edit commands have separated them). */ | * they have been ripped or other edit commands have separated them). */ | ||||
| bool connected = other_vert_sel == connected_vert_sel && | bool connected = other_vert_sel == connected_vert_sel && | ||||
| equals_v2v2(luv_other->uv, luv_connected->uv); | equals_v2v2(luv_other, luv_connected); | ||||
| if (!connected) { | if (!connected) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* The loop vert is occupying the same space, so it has the same distance. */ | /* The loop vert is occupying the same space, so it has the same distance. */ | ||||
| const int i_connected = BM_elem_index_get(l_connected); | const int i_connected = BM_elem_index_get(l_connected); | ||||
| dists[i_connected] = dist; | dists[i_connected] = dist; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMIter iter, liter; | BMIter iter, liter; | ||||
| UvElementMap *elementmap = NULL; | UvElementMap *elementmap = NULL; | ||||
| struct { | struct { | ||||
| float co[2]; | float co[2]; | ||||
| int co_num; | int co_num; | ||||
| } *island_center = NULL; | } *island_center = NULL; | ||||
| int count = 0, countsel = 0; | int count = 0, countsel = 0; | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm); | ||||
| if (!ED_space_image_show_uvedit(sima, tc->obedit)) { | if (!ED_space_image_show_uvedit(sima, tc->obedit)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* count */ | /* count */ | ||||
| if (is_island_center) { | if (is_island_center) { | ||||
| /* create element map with island information */ | /* create element map with island information */ | ||||
| Show All 13 Lines | BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_elem_flag_enable(efa, BM_ELEM_TAG); | BM_elem_flag_enable(efa, BM_ELEM_TAG); | ||||
| BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | ||||
| /* Make sure that the loop element flag is cleared for when we use it in | /* Make sure that the loop element flag is cleared for when we use it in | ||||
| * uv_set_connectivity_distance later. */ | * uv_set_connectivity_distance later. */ | ||||
| BM_elem_flag_disable(l, BM_ELEM_TAG); | BM_elem_flag_disable(l, BM_ELEM_TAG); | ||||
| if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { | if (uvedit_uv_select_test(scene, l, offsets)) { | ||||
| countsel++; | countsel++; | ||||
| if (island_center) { | if (island_center) { | ||||
| UvElement *element = BM_uv_element_get(elementmap, efa, l); | UvElement *element = BM_uv_element_get(elementmap, efa, l); | ||||
| if (element->flag == false) { | if (element->flag == false) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv); | ||||
| add_v2_v2(island_center[element->island].co, luv->uv); | add_v2_v2(island_center[element->island].co, luv); | ||||
| island_center[element->island].co_num++; | island_center[element->island].co_num++; | ||||
| element->flag = true; | element->flag = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (is_prop_edit) { | if (is_prop_edit) { | ||||
| count++; | count++; | ||||
| Show All 38 Lines | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | ||||
| BMLoop *l; | BMLoop *l; | ||||
| if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) { | if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | ||||
| const bool selected = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); | const bool selected = uvedit_uv_select_test(scene, l, offsets); | ||||
| MLoopUV *luv; | float(*luv)[2]; | ||||
| const float *center = NULL; | const float *center = NULL; | ||||
| float prop_distance = FLT_MAX; | float prop_distance = FLT_MAX; | ||||
| if (!is_prop_edit && !selected) { | if (!is_prop_edit && !selected) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (is_prop_connected) { | if (is_prop_connected) { | ||||
| const int idx = BM_elem_index_get(l); | const int idx = BM_elem_index_get(l); | ||||
| prop_distance = prop_dists[idx]; | prop_distance = prop_dists[idx]; | ||||
| } | } | ||||
| if (is_island_center) { | if (is_island_center) { | ||||
| UvElement *element = BM_uv_element_get(elementmap, efa, l); | UvElement *element = BM_uv_element_get(elementmap, efa, l); | ||||
| if (element) { | if (element) { | ||||
| center = island_center[element->island].co; | center = island_center[element->island].co; | ||||
| } | } | ||||
| } | } | ||||
| luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | luv = (float(*)[2])BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv); | ||||
| UVsToTransData(t->aspect, td++, td2d++, luv->uv, center, prop_distance, selected); | UVsToTransData(t->aspect, td++, td2d++, *luv, center, prop_distance, selected); | ||||
| } | } | ||||
| } | } | ||||
| if (sima->flag & SI_LIVE_UNWRAP) { | if (sima->flag & SI_LIVE_UNWRAP) { | ||||
| ED_uvedit_live_unwrap_begin(t->scene, tc->obedit); | ED_uvedit_live_unwrap_begin(t->scene, tc->obedit); | ||||
| } | } | ||||
| finally: | finally: | ||||
| ▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines | |||||