Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/mesh/editmesh_tools.c
| Show First 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| Object *obedit = em->ob; | Object *obedit = em->ob; | ||||
| BMIter iter; | BMIter iter; | ||||
| BMVert *eve; | BMVert *eve; | ||||
| ED_view3d_init_mats_rv3d(obedit, ar->regiondata); | ED_view3d_init_mats_rv3d(obedit, ar->regiondata); | ||||
| struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( | struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( | ||||
| CTX_data_main(C), CTX_data_scene(C), CTX_data_scene_layer(C), CTX_data_engine(C), 0, | CTX_data_main(C), CTX_data_scene(C), CTX_data_view_layer(C), CTX_data_engine(C), 0, | ||||
| ar, CTX_wm_view3d(C)); | ar, CTX_wm_view3d(C)); | ||||
| BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | ||||
| if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | ||||
| float mval[2], co_proj[3]; | float mval[2], co_proj[3]; | ||||
| if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { | if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { | ||||
| if (ED_transform_snap_object_project_view3d_mixed( | if (ED_transform_snap_object_project_view3d_mixed( | ||||
| snap_context, | snap_context, | ||||
| ▲ Show 20 Lines • Show All 2,691 Lines • ▼ Show 20 Lines | |||||
| /* *************** Operator: separate parts *************/ | /* *************** Operator: separate parts *************/ | ||||
| enum { | enum { | ||||
| MESH_SEPARATE_SELECTED = 0, | MESH_SEPARATE_SELECTED = 0, | ||||
| MESH_SEPARATE_MATERIAL = 1, | MESH_SEPARATE_MATERIAL = 1, | ||||
| MESH_SEPARATE_LOOSE = 2, | MESH_SEPARATE_LOOSE = 2, | ||||
| }; | }; | ||||
| static Base *mesh_separate_tagged(Main *bmain, Scene *scene, SceneLayer *sl, Base *base_old, BMesh *bm_old) | static Base *mesh_separate_tagged(Main *bmain, Scene *scene, ViewLayer *sl, Base *base_old, BMesh *bm_old) | ||||
| { | { | ||||
| Base *base_new; | Base *base_new; | ||||
| Object *obedit = base_old->object; | Object *obedit = base_old->object; | ||||
| BMesh *bm_new; | BMesh *bm_new; | ||||
| bm_new = BM_mesh_create( | bm_new = BM_mesh_create( | ||||
| &bm_mesh_allocsize_default, | &bm_mesh_allocsize_default, | ||||
| &((struct BMeshCreateParams){.use_toolflags = true,})); | &((struct BMeshCreateParams){.use_toolflags = true,})); | ||||
| Show All 30 Lines | static Base *mesh_separate_tagged(Main *bmain, Scene *scene, ViewLayer *sl, Base *base_old, BMesh *bm_old) | ||||
| BM_mesh_bm_to_me(bm_new, base_new->object->data, (&(struct BMeshToMeshParams){0})); | BM_mesh_bm_to_me(bm_new, base_new->object->data, (&(struct BMeshToMeshParams){0})); | ||||
| BM_mesh_free(bm_new); | BM_mesh_free(bm_new); | ||||
| ((Mesh *)base_new->object->data)->edit_btmesh = NULL; | ((Mesh *)base_new->object->data)->edit_btmesh = NULL; | ||||
| return base_new; | return base_new; | ||||
| } | } | ||||
| static bool mesh_separate_selected(Main *bmain, Scene *scene, SceneLayer *sl, Base *base_old, BMesh *bm_old) | static bool mesh_separate_selected(Main *bmain, Scene *scene, ViewLayer *sl, Base *base_old, BMesh *bm_old) | ||||
| { | { | ||||
| /* we may have tags from previous operators */ | /* we may have tags from previous operators */ | ||||
| BM_mesh_elem_hflag_disable_all(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, false); | BM_mesh_elem_hflag_disable_all(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, false); | ||||
| /* sel -> tag */ | /* sel -> tag */ | ||||
| BM_mesh_elem_hflag_enable_test(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, true, false, BM_ELEM_SELECT); | BM_mesh_elem_hflag_enable_test(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, true, false, BM_ELEM_SELECT); | ||||
| return (mesh_separate_tagged(bmain, scene, sl, base_old, bm_old) != NULL); | return (mesh_separate_tagged(bmain, scene, sl, base_old, bm_old) != NULL); | ||||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | static void mesh_separate_material_assign_mat_nr(Main *bmain, Object *ob, const short mat_nr) | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_material_clear_id(bmain, obdata, true); | BKE_material_clear_id(bmain, obdata, true); | ||||
| BKE_material_resize_object(bmain, ob, 0, true); | BKE_material_resize_object(bmain, ob, 0, true); | ||||
| BKE_material_resize_id(bmain, obdata, 0, true); | BKE_material_resize_id(bmain, obdata, 0, true); | ||||
| } | } | ||||
| } | } | ||||
| static bool mesh_separate_material(Main *bmain, Scene *scene, SceneLayer *sl, Base *base_old, BMesh *bm_old) | static bool mesh_separate_material(Main *bmain, Scene *scene, ViewLayer *sl, Base *base_old, BMesh *bm_old) | ||||
| { | { | ||||
| BMFace *f_cmp, *f; | BMFace *f_cmp, *f; | ||||
| BMIter iter; | BMIter iter; | ||||
| bool result = false; | bool result = false; | ||||
| while ((f_cmp = BM_iter_at_index(bm_old, BM_FACES_OF_MESH, NULL, 0))) { | while ((f_cmp = BM_iter_at_index(bm_old, BM_FACES_OF_MESH, NULL, 0))) { | ||||
| Base *base_new; | Base *base_new; | ||||
| const short mat_nr = f_cmp->mat_nr; | const short mat_nr = f_cmp->mat_nr; | ||||
| Show All 35 Lines | while ((f_cmp = BM_iter_at_index(bm_old, BM_FACES_OF_MESH, NULL, 0))) { | ||||
| } | } | ||||
| result |= (base_new != NULL); | result |= (base_new != NULL); | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| static bool mesh_separate_loose(Main *bmain, Scene *scene, SceneLayer *sl, Base *base_old, BMesh *bm_old) | static bool mesh_separate_loose(Main *bmain, Scene *scene, ViewLayer *sl, Base *base_old, BMesh *bm_old) | ||||
| { | { | ||||
| int i; | int i; | ||||
| BMEdge *e; | BMEdge *e; | ||||
| BMVert *v_seed; | BMVert *v_seed; | ||||
| BMWalker walker; | BMWalker walker; | ||||
| bool result = false; | bool result = false; | ||||
| int max_iter = bm_old->totvert; | int max_iter = bm_old->totvert; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static bool mesh_separate_loose(Main *bmain, Scene *scene, ViewLayer *sl, Base *base_old, BMesh *bm_old) | ||||
| return result; | return result; | ||||
| } | } | ||||
| static int edbm_separate_exec(bContext *C, wmOperator *op) | static int edbm_separate_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| const int type = RNA_enum_get(op->ptr, "type"); | const int type = RNA_enum_get(op->ptr, "type"); | ||||
| int retval = 0; | int retval = 0; | ||||
| if (ED_operator_editmesh(C)) { | if (ED_operator_editmesh(C)) { | ||||
| Base *base = CTX_data_active_base(C); | Base *base = CTX_data_active_base(C); | ||||
| BMEditMesh *em = BKE_editmesh_from_object(base->object); | BMEditMesh *em = BKE_editmesh_from_object(base->object); | ||||
| if (type == 0) { | if (type == 0) { | ||||
| ▲ Show 20 Lines • Show All 2,690 Lines • Show Last 20 Lines | |||||