Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/uvedit/uvedit_ops.c
| Context not available. | |||||
| #include "BLI_alloca.h" | #include "BLI_alloca.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_lasso.h" | #include "BLI_lasso.h" | ||||
| #include "BLI_linklist.h" | |||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_array.h" | #include "BLI_array.h" | ||||
| Context not available. | |||||
| ot->exec = uv_weld_exec; | ot->exec = uv_weld_exec; | ||||
| ot->poll = ED_operator_uvedit; | ot->poll = ED_operator_uvedit; | ||||
| } | } | ||||
| /* ******************** unstitch operator **************** */ | |||||
| static int uv_unstitch_exec(bContext *C, wmOperator *UNUSED(op)) | |||||
| { | |||||
| Object *obedit = CTX_data_edit_object(C); | |||||
| Mesh *me = (Mesh *)obedit->data; | |||||
| BMEditMesh *em = me->edit_btmesh; | |||||
| SpaceImage *sima = CTX_wm_space_image(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| BMFace *efa; | |||||
| BMIter iter,liter; | |||||
| BMLoop *loop; | |||||
| MLoopUV *luv, *luviter; | |||||
| MLoopUV *prevluv, *nextluv; | |||||
| LinkNode *unique_UV_LL = NULL; | |||||
| LinkNode *nonunique_UV_LL = NULL; | |||||
| bool new; | |||||
| int offset=1; | |||||
| const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | |||||
| BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | |||||
| BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) { | |||||
| new = true; | |||||
| if (uvedit_edge_select_test(scene, loop, cd_loop_uv_offset)) { | |||||
| /* Marking the new seam on the model*/ | |||||
| BM_elem_flag_enable(loop->e, BM_ELEM_SEAM); | |||||
| } | |||||
| /* Update UVs */ | |||||
| /* Is the UV element in the rip? */ | |||||
| bool edge; | |||||
| luv = BM_ELEM_CD_GET_VOID_P(loop, cd_loop_uv_offset); | |||||
| edge= (luv->flag & MLOOPUV_VERTSEL); | |||||
| if(loop->prev && loop->next){ | |||||
| prevluv = BM_ELEM_CD_GET_VOID_P(loop->prev, cd_loop_uv_offset); | |||||
| nextluv = BM_ELEM_CD_GET_VOID_P(loop->next, cd_loop_uv_offset); | |||||
| edge = edge && ((prevluv->flag & MLOOPUV_VERTSEL)||(nextluv->flag & MLOOPUV_VERTSEL)); | |||||
| } | |||||
| else if(loop->prev){ | |||||
| prevluv = BM_ELEM_CD_GET_VOID_P(loop->prev, cd_loop_uv_offset); | |||||
| edge = edge && (prevluv->flag & MLOOPUV_VERTSEL); | |||||
| }else{ | |||||
| nextluv = BM_ELEM_CD_GET_VOID_P(loop->next, cd_loop_uv_offset); | |||||
| edge = edge && (nextluv->flag & MLOOPUV_VERTSEL); | |||||
| } | |||||
| if (edge){ | |||||
| /* Check if UV is unique. */ | |||||
| LinkNode *item = unique_UV_LL; | |||||
| while (item && new) { | |||||
| luviter = item->link; | |||||
| if (compare_v2v2(luviter->uv, luv->uv, 0.0f)) | |||||
| new = false; | |||||
| item = item->next; | |||||
| } | |||||
| if (new) { | |||||
| BLI_linklist_prepend(&unique_UV_LL, luv); | |||||
| } | |||||
| else { | |||||
| BLI_linklist_prepend(&nonunique_UV_LL, luv); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| /* Unselect nonunique Uvs. Also, Change all Uv's positions slightly so that they do not occupy the | |||||
| * same space. */ | |||||
| LinkNode *item; | |||||
| for (item = nonunique_UV_LL; item; item = item->next) { | |||||
| luviter = item->link; | |||||
| luviter->flag &= ~MLOOPUV_VERTSEL; | |||||
| offset++; | |||||
| //luviter->uv[0] -= 0.001*offset; | |||||
| } | |||||
| for (item = unique_UV_LL; item; item = item->next) { | |||||
| luviter = item->link; | |||||
| offset++; | |||||
| luviter->uv[0] -= 0.001*offset; | |||||
| } | |||||
| BLI_linklist_free(unique_UV_LL, NULL); | |||||
| BLI_linklist_free(nonunique_UV_LL, NULL); | |||||
| me->drawflag |= ME_DRAWSEAMS; | |||||
| uvedit_live_unwrap_update(sima, scene, obedit); | |||||
| DAG_id_tag_update(obedit->data, 0); | |||||
| WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void UV_OT_unstitch(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Unstitch"; | |||||
| ot->description = "Unstitch selected UV vertices"; | |||||
| ot->idname = "UV_OT_unstitch"; | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| /* api callbacks */ | |||||
| ot->exec = uv_unstitch_exec; | |||||
| ot->poll = ED_operator_uvedit; | |||||
| } | |||||
| /* ******************** (de)select all operator **************** */ | /* ******************** (de)select all operator **************** */ | ||||
| Context not available. | |||||
| WM_operatortype_append(UV_OT_seams_from_islands); | WM_operatortype_append(UV_OT_seams_from_islands); | ||||
| WM_operatortype_append(UV_OT_mark_seam); | WM_operatortype_append(UV_OT_mark_seam); | ||||
| WM_operatortype_append(UV_OT_weld); | WM_operatortype_append(UV_OT_weld); | ||||
| WM_operatortype_append(UV_OT_unstitch); | |||||
| WM_operatortype_append(UV_OT_remove_doubles); | WM_operatortype_append(UV_OT_remove_doubles); | ||||
| WM_operatortype_append(UV_OT_pin); | WM_operatortype_append(UV_OT_pin); | ||||
| Context not available. | |||||
| WM_keymap_add_item(keymap, "UV_OT_select_pinned", PKEY, KM_PRESS, KM_SHIFT, 0); | WM_keymap_add_item(keymap, "UV_OT_select_pinned", PKEY, KM_PRESS, KM_SHIFT, 0); | ||||
| WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_weldalign", WKEY, KM_PRESS, 0, 0); | WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_weldalign", WKEY, KM_PRESS, 0, 0); | ||||
| /* uv operations */ | /* uv operations */ | ||||
| WM_keymap_add_item(keymap, "UV_OT_stitch", VKEY, KM_PRESS, 0, 0); | WM_keymap_add_item(keymap, "UV_OT_stitch", VKEY, KM_PRESS, 0, 0); | ||||
| WM_keymap_add_item(keymap, "UV_OT_unstitch", UKEY, KM_PRESS, 0, 0); | |||||
| kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0); | kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, 0, 0); | ||||
| RNA_boolean_set(kmi->ptr, "clear", false); | RNA_boolean_set(kmi->ptr, "clear", false); | ||||
| kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, KM_ALT, 0); | kmi = WM_keymap_add_item(keymap, "UV_OT_pin", PKEY, KM_PRESS, KM_ALT, 0); | ||||
| Context not available. | |||||