fix [#30972] Editmesh split by materials not working.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 16 Apr 2012 13:49:04 +0000 (13:49 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 16 Apr 2012 13:49:04 +0000 (13:49 +0000)
release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/mesh/editmesh_tools.c

index 20f5b471784c208e4689b6ce50d6407992b76487..6c152c7cd435e214ba9ec38b0a37551523e13d9a 100644 (file)
@@ -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")
 
index 5b6811fcc5cba40f868fcd4d1857d0c661e3157f..b8ab538b60e57c145cbfb2d4b8715fde7ed04bb4 100644 (file)
@@ -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