diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-16 17:49:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-16 17:49:04 +0400 |
commit | 37a79f47272ddd0cf5702ae0a73c2c39ef192ad4 (patch) | |
tree | 263daa7ececbc61c6938ee6c7bd1e885b9441055 | |
parent | c509f687ca1b8ae58d0286afde49e59ea5556551 (diff) |
fix [#30972] Editmesh split by materials not working.
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 51 |
2 files changed, 37 insertions, 16 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 20f5b471784..6c152c7cd43 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -1680,7 +1680,7 @@ class VIEW3D_MT_edit_mesh_vertices(Menu): layout.operator("mesh.merge") layout.operator("mesh.rip_move") layout.operator("mesh.split") - layout.operator("mesh.separate") + layout.operator_menu_enum("mesh.separate", "type") layout.operator("mesh.vert_connect") layout.operator("mesh.vert_slide") diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 5b6811fcc5c..b8ab538b60e 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -3131,7 +3131,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO BMesh *bm_new; if (!em) - return OPERATOR_CANCELLED; + return FALSE; bm_new = BM_mesh_create(&bm_mesh_allocsize_default); CustomData_copy(&em->bm->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0); @@ -3182,13 +3182,41 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO BM_mesh_free(bm_new); ((Mesh *)basenew->object->data)->edit_btmesh = NULL; - return 1; + return TRUE; } -//BMESH_TODO -static int mesh_separate_material(Main *UNUSED(bmain), Scene *UNUSED(scene), Base *UNUSED(editbase), wmOperator *UNUSED(wmop)) +static int mesh_separate_material(Main *bmain, Scene *scene, Base *editbase, wmOperator *wmop) { - return 0; + BMFace *f_cmp, *f; + BMIter iter; + int result = FALSE; + Object *obedit = editbase->object; + BMEditMesh *em = BMEdit_FromObject(obedit); + BMesh *bm = em->bm; + + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + + while ((f_cmp = BM_iter_at_index(bm, BM_FACES_OF_MESH, NULL, 0))) { + const short mat_nr = f_cmp->mat_nr; + int tot = 0; + + BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { + if (f->mat_nr == mat_nr) { + BM_face_select_set(bm, f, TRUE); + tot++; + } + } + + /* leave the current object with some materials */ + if (tot == bm->totface) { + break; + } + + /* Move selection into a separate object */ + result |= mesh_separate_selected(bmain, scene, editbase, wmop); + } + + return result; } static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOperator *wmop) @@ -3199,21 +3227,14 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOper BMVert *v_seed; BMWalker walker; BMIter iter; - int result = 0; + int result = FALSE; Object *obedit = editbase->object; - Mesh *me = obedit->data; - BMEditMesh *em = me->edit_btmesh; + BMEditMesh *em = BMEdit_FromObject(obedit); BMesh *bm = em->bm; int max_iter = bm->totvert; /* Clear all selected vertices */ - BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { - BM_elem_select_set(bm, v, FALSE); - } - - /* Flush the selection to clear edge/face selections to match - * selected vertices */ - EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); + EDBM_flag_disable_all(em, BM_ELEM_SELECT); /* A "while (true)" loop should work here as each iteration should * select and remove at least one vertex and when all vertices |