Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / mesh / editmesh_tools.c
index a055ee4..5c6b6da 100644 (file)
@@ -131,7 +131,7 @@ static int edbm_subdivide_exec(bContext *C, wmOperator *op)
                EDBM_update_generic(em, true, true);
        }
 
-       MEM_SAFE_FREE(objects);
+       MEM_freeN(objects);
 
        return OPERATOR_FINISHED;
 }
@@ -366,21 +366,22 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
        ED_view3d_init_mats_rv3d(obedit, ar->regiondata);
 
        struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
-               CTX_data_main(C), CTX_data_scene(C), CTX_data_depsgraph(C), 0,
+               CTX_data_scene(C), CTX_data_depsgraph(C), 0,
                ar, CTX_wm_view3d(C));
 
        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
                        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_transform_snap_object_project_view3d_mixed(
+                               if (ED_transform_snap_object_project_view3d(
                                        snap_context,
-                                       SCE_SELECT_FACE,
+                                       SCE_SNAP_MODE_FACE,
                                        &(const struct SnapObjectParams){
                                            .snap_select = SNAP_NOT_ACTIVE,
                                            .use_object_edit_cage = false,
+                                           .use_occlusion_test = true,
                                        },
-                                       mval, NULL, true,
+                                       mval, NULL,
                                        co_proj, NULL))
                                {
                                        mul_v3_m4v3(eve->co, obedit->imat, co_proj);
@@ -437,7 +438,7 @@ static int edbm_delete_exec(bContext *C, wmOperator *op)
                                break;
                        case MESH_DELETE_EDGE: /* Erase Edges */
                                if (!(em->bm->totedgesel &&
-                                     EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_FACES)))
+                                     EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)))
                                {
                                        continue;
                                }
@@ -477,7 +478,7 @@ static int edbm_delete_exec(bContext *C, wmOperator *op)
                EDBM_update_generic(em, true, true);
        }
 
-       MEM_SAFE_FREE(objects);
+       MEM_freeN(objects);
 
        return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }
@@ -602,7 +603,7 @@ static int edbm_delete_loose_exec(bContext *C, wmOperator *op)
 
        edbm_report_delete_info(op->reports, totelem_old, totelem_new);
 
-       MEM_SAFE_FREE(objects);
+       MEM_freeN(objects);
 
        return OPERATOR_FINISHED;
 }
@@ -857,70 +858,83 @@ static void edbm_add_edge_face_exec__tricky_finalize_sel(BMesh *bm, BMElem *ele_
 
 static int edbm_add_edge_face_exec(bContext *C, wmOperator *op)
 {
-       BMOperator bmop;
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
-       const bool use_smooth = edbm_add_edge_face__smooth_get(em->bm);
-       const int totedge_orig = em->bm->totedge;
-       const int totface_orig = em->bm->totface;
        /* when this is used to dissolve we could avoid this, but checking isnt too slow */
 
-#ifdef USE_FACE_CREATE_SEL_EXTEND
-       BMElem *ele_desel;
-       BMFace *ele_desel_face;
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
-       /* be extra clever, figure out if a partial selection should be extended so we can create geometry
-        * with single vert or single edge selection */
-       ele_desel = edbm_add_edge_face_exec__tricky_extend_sel(em->bm);
-#endif
+               if ((em->bm->totvertsel == 0) &&
+                   (em->bm->totedgesel == 0) &&
+                   (em->bm->totvertsel == 0))
+               {
+                       continue;
+               }
 
-       if (!EDBM_op_init(
-                   em, &bmop, op,
-                   "contextual_create geom=%hfev mat_nr=%i use_smooth=%b",
-                   BM_ELEM_SELECT, em->mat_nr, use_smooth))
-       {
-               return OPERATOR_CANCELLED;
-       }
+               bool use_smooth = edbm_add_edge_face__smooth_get(em->bm);
+               int totedge_orig = em->bm->totedge;
+               int totface_orig = em->bm->totface;
 
-       BMO_op_exec(em->bm, &bmop);
+               BMOperator bmop;
+#ifdef USE_FACE_CREATE_SEL_EXTEND
+               BMElem *ele_desel;
+               BMFace *ele_desel_face;
 
-       /* cancel if nothing was done */
-       if ((totedge_orig == em->bm->totedge) &&
-           (totface_orig == em->bm->totface))
-       {
-               EDBM_op_finish(em, &bmop, op, true);
-               return OPERATOR_CANCELLED;
-       }
+               /* be extra clever, figure out if a partial selection should be extended so we can create geometry
+                * with single vert or single edge selection */
+               ele_desel = edbm_add_edge_face_exec__tricky_extend_sel(em->bm);
+#endif
+               if (!EDBM_op_init(
+                           em, &bmop, op,
+                           "contextual_create geom=%hfev mat_nr=%i use_smooth=%b",
+                           BM_ELEM_SELECT, em->mat_nr, use_smooth))
+               {
+                       continue;
+               }
 
+               BMO_op_exec(em->bm, &bmop);
+
+               /* cancel if nothing was done */
+               if ((totedge_orig == em->bm->totedge) &&
+                   (totface_orig == em->bm->totface))
+               {
+                       EDBM_op_finish(em, &bmop, op, true);
+                       continue;
+               }
 #ifdef USE_FACE_CREATE_SEL_EXTEND
-       /* normally we would want to leave the new geometry selected,
-        * but being able to press F many times to add geometry is too useful! */
-       if (ele_desel &&
-           (BMO_slot_buffer_count(bmop.slots_out, "faces.out") == 1) &&
-           (ele_desel_face = BMO_slot_buffer_get_first(bmop.slots_out, "faces.out")))
-       {
-               edbm_add_edge_face_exec__tricky_finalize_sel(em->bm, ele_desel, ele_desel_face);
-       }
-       else
+               /* normally we would want to leave the new geometry selected,
+                * but being able to press F many times to add geometry is too useful! */
+               if (ele_desel &&
+                   (BMO_slot_buffer_count(bmop.slots_out, "faces.out") == 1) &&
+                   (ele_desel_face = BMO_slot_buffer_get_first(bmop.slots_out, "faces.out")))
+               {
+                       edbm_add_edge_face_exec__tricky_finalize_sel(em->bm, ele_desel, ele_desel_face);
+               }
+               else
 #endif
-       {
-               /* Newly created faces may include existing hidden edges,
-                * copying face data from surrounding, may have copied hidden face flag too.
-                *
-                * Important that faces use flushing since 'edges.out' wont include hidden edges that already existed.
-                */
-               BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_HIDDEN, true);
-               BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_HIDDEN, false);
+               {
+                       /* Newly created faces may include existing hidden edges,
+                        * copying face data from surrounding, may have copied hidden face flag too.
+                        *
+                        * Important that faces use flushing since 'edges.out' wont include hidden edges that already existed.
+                        */
+                       BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_HIDDEN, true);
+                       BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_HIDDEN, false);
 
-               BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
-               BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true);
-       }
+                       BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
+                       BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true);
+               }
 
-       if (!EDBM_op_finish(em, &bmop, op, true)) {
-               return OPERATOR_CANCELLED;
-       }
+               if (!EDBM_op_finish(em, &bmop, op, true)) {
+                       continue;
+               }
 
-       EDBM_update_generic(em, true, true);
+               EDBM_update_generic(em, true, true);
+       }
+       MEM_freeN(objects);
 
        return OPERATOR_FINISHED;
 }
@@ -1094,93 +1108,97 @@ void MESH_OT_mark_sharp(wmOperatorType *ot)
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
-static int edbm_vert_connect_exec(bContext *C, wmOperator *op)
+static bool edbm_connect_vert_pair(BMEditMesh *em, wmOperator *op)
 {
-       ViewLayer *view_layer = CTX_data_view_layer(C);
-       uint objects_len = 0;
-       uint failed_objects_len = 0;
-       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
-       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
-               Object *obedit = objects[ob_index];
-               BMEditMesh *em = BKE_editmesh_from_object(obedit);
-               BMesh *bm = em->bm;
-               BMOperator bmop;
-               bool is_pair = (bm->totvertsel == 2);
-               int len = 0;
-               bool check_degenerate = true;
-               const int verts_len = bm->totvertsel;
-               BMVert **verts;
-               bool checks_succeded = true;
-
-               if (!is_pair) {
-                       continue;
-               }
+       BMesh *bm = em->bm;
+       BMOperator bmop;
+       const int verts_len = bm->totvertsel;
+       bool is_pair = (verts_len == 2);
+       int len = 0;
+       bool check_degenerate = true;
 
-               verts = MEM_mallocN(sizeof(*verts) * verts_len, __func__);
-               {
-                       BMIter iter;
-                       BMVert *v;
-                       int i = 0;
+       BMVert **verts;
+       bool checks_succeded = true;
 
-                       BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
-                               if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
-                                       verts[i++] = v;
-                               }
-                       }
+       /* sanity check */
+       if (!is_pair) {
+               return false;
+       }
 
-                       if (is_pair) {
-                               if (BM_vert_pair_share_face_check_cb(
-                                       verts[0], verts[1],
-                                       BM_elem_cb_check_hflag_disabled_simple(BMFace *, BM_ELEM_HIDDEN)))
-                               {
-                                       check_degenerate = false;
-                                       is_pair = false;
-                               }
+       verts = MEM_mallocN(sizeof(*verts) * verts_len, __func__);
+       {
+               BMIter iter;
+               BMVert *v;
+               int i = 0;
+
+               BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
+                       if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
+                               verts[i++] = v;
                        }
                }
-               
-               if (is_pair) {
-                       if (!EDBM_op_init(
-                               em, &bmop, op,
-                               "connect_vert_pair verts=%eb verts_exclude=%hv faces_exclude=%hf",
-                               verts, verts_len, BM_ELEM_HIDDEN, BM_ELEM_HIDDEN))
-                       {
-                               checks_succeded = false;
-                       }
+
+               if (BM_vert_pair_share_face_check_cb(
+                           verts[0], verts[1],
+                           BM_elem_cb_check_hflag_disabled_simple(BMFace *, BM_ELEM_HIDDEN)))
+               {
+                       check_degenerate = false;
+                       is_pair = false;
                }
-               else {
-                       if (!EDBM_op_init(
-                               em, &bmop, op,
-                               "connect_verts verts=%eb faces_exclude=%hf check_degenerate=%b",
-                               verts, verts_len, BM_ELEM_HIDDEN, check_degenerate))
-                       {
-                               checks_succeded = false;
-                       }
+       }
+
+       if (is_pair) {
+               if (!EDBM_op_init(
+                           em, &bmop, op,
+                           "connect_vert_pair verts=%eb verts_exclude=%hv faces_exclude=%hf",
+                           verts, verts_len, BM_ELEM_HIDDEN, BM_ELEM_HIDDEN))
+               {
+                       checks_succeded = false;
                }
-               if (checks_succeded)
+       }
+       else {
+               if (!EDBM_op_init(
+                           em, &bmop, op,
+                           "connect_verts verts=%eb faces_exclude=%hf check_degenerate=%b",
+                           verts, verts_len, BM_ELEM_HIDDEN, check_degenerate))
                {
-                       BMO_op_exec(bm, &bmop);
-                       len = BMO_slot_get(bmop.slots_out, "edges.out")->len;
+                       checks_succeded = false;
+               }
+       }
+       if (checks_succeded) {
+               BMO_op_exec(bm, &bmop);
+               len = BMO_slot_get(bmop.slots_out, "edges.out")->len;
 
-                       if (len) {
-                               if (is_pair) {
-                                       /* new verts have been added, we have to select the edges, not just flush */
-                                       BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true);
-                               }
-                       }
+               if (len && is_pair) {
+                       /* new verts have been added, we have to select the edges, not just flush */
+                       BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true);
+               }
 
-                       if (!EDBM_op_finish(em, &bmop, op, true)) {
-                               len = 0;
-                       }
-                       else {
-                               EDBM_selectmode_flush(em);  /* so newly created edges get the selection state from the vertex */
+               if (!EDBM_op_finish(em, &bmop, op, true)) {
+                       len = 0;
+               }
+               else {
+                       EDBM_selectmode_flush(em);  /* so newly created edges get the selection state from the vertex */
 
-                               EDBM_update_generic(em, true, true);
-                       }
+                       EDBM_update_generic(em, true, true);
                }
-               MEM_freeN(verts);
-               if (len == 0)
-               {
+       }
+       MEM_freeN(verts);
+
+       return len;
+}
+
+static int edbm_vert_connect_exec(bContext *C, wmOperator *op)
+{
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       uint failed_objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
+
+               if (!edbm_connect_vert_pair(em, op)) {
                        failed_objects_len++;
                }
        }
@@ -1424,43 +1442,66 @@ static bool bm_vert_connect_select_history_edge_to_vert_path(BMesh *bm, ListBase
 
 static int edbm_vert_connect_path_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
-       BMesh *bm = em->bm;
-       bool is_pair = (em->bm->totvertsel == 2);
-       ListBase selected_orig = {NULL, NULL};
-       int retval;
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       uint failed_selection_order_len = 0;
+       uint failed_connect_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
 
-       /* when there is only 2 vertices, we can ignore selection order */
-       if (is_pair) {
-               return edbm_vert_connect_exec(C, op);
-       }
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
+               BMesh *bm = em->bm;
+               const bool is_pair = (em->bm->totvertsel == 2);
+               ListBase selected_orig = {NULL, NULL};
 
-       if (bm->selected.first) {
-               BMEditSelection *ese = bm->selected.first;
-               if (ese->htype == BM_EDGE) {
-                       if (bm_vert_connect_select_history_edge_to_vert_path(bm, &selected_orig)) {
-                               SWAP(ListBase, bm->selected, selected_orig);
+               if (bm->totvertsel == 0) {
+                       continue;
+               }
+
+               /* when there is only 2 vertices, we can ignore selection order */
+               if (is_pair) {
+                       if (!edbm_connect_vert_pair(em, op)) {
+                               failed_connect_len++;
                        }
+                       continue;
                }
-       }
 
-       if (bm_vert_connect_select_history(bm)) {
-               EDBM_selectmode_flush(em);
-               EDBM_update_generic(em, true, true);
-               retval = OPERATOR_FINISHED;
+               if (bm->selected.first) {
+                       BMEditSelection *ese = bm->selected.first;
+                       if (ese->htype == BM_EDGE) {
+                               if (bm_vert_connect_select_history_edge_to_vert_path(bm, &selected_orig)) {
+                                       SWAP(ListBase, bm->selected, selected_orig);
+                               }
+                       }
+               }
+
+               if (bm_vert_connect_select_history(bm)) {
+                       EDBM_selectmode_flush(em);
+                       EDBM_update_generic(em, true, true);
+               }
+               else {
+                       failed_selection_order_len++;
+               }
+
+               if (!BLI_listbase_is_empty(&selected_orig)) {
+                       BM_select_history_clear(bm);
+                       bm->selected = selected_orig;
+               }
        }
-       else {
+
+       MEM_freeN(objects);
+
+       if (failed_selection_order_len == objects_len) {
                BKE_report(op->reports, RPT_ERROR, "Invalid selection order");
-               retval = OPERATOR_CANCELLED;
+               return OPERATOR_CANCELLED;
        }
-
-       if (!BLI_listbase_is_empty(&selected_orig)) {
-               BM_select_history_clear(bm);
-               bm->selected = selected_orig;
+       else if (failed_connect_len == objects_len) {
+               BKE_report(op->reports, RPT_ERROR, "Could not connect vertices");
+               return OPERATOR_CANCELLED;
        }
 
-       return retval;
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_vert_connect_path(wmOperatorType *ot)
@@ -1480,20 +1521,29 @@ void MESH_OT_vert_connect_path(wmOperatorType *ot)
 
 static int edbm_vert_connect_concave_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
-       if (!EDBM_op_call_and_selectf(
-                    em, op,
-                    "faces.out", true,
-                    "connect_verts_concave faces=%hf",
-                    BM_ELEM_SELECT))
-       {
-               return OPERATOR_CANCELLED;
-       }
+               if (em->bm->totfacesel == 0) {
+                       continue;
+               }
 
+               if (!EDBM_op_call_and_selectf(
+                            em, op,
+                            "faces.out", true,
+                            "connect_verts_concave faces=%hf",
+                            BM_ELEM_SELECT))
+               {
+                       continue;
+               }
+               EDBM_update_generic(em, true, true);
+       }
 
-       EDBM_update_generic(em, true, true);
+       MEM_freeN(objects);
        return OPERATOR_FINISHED;
 }
 
@@ -1520,22 +1570,32 @@ void MESH_OT_vert_connect_concave(wmOperatorType *ot)
 
 static int edbm_vert_connect_nonplaner_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
-
+       ViewLayer *view_layer = CTX_data_view_layer(C);
        const float angle_limit = RNA_float_get(op->ptr, "angle_limit");
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
 
-       if (!EDBM_op_call_and_selectf(
-                    em, op,
-                    "faces.out", true,
-                    "connect_verts_nonplanar faces=%hf angle_limit=%f",
-                    BM_ELEM_SELECT, angle_limit))
-       {
-               return OPERATOR_CANCELLED;
-       }
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
+               if (em->bm->totfacesel == 0) {
+                       continue;
+               }
+
+               if (!EDBM_op_call_and_selectf(
+                           em, op,
+                           "faces.out", true,
+                           "connect_verts_nonplanar faces=%hf angle_limit=%f",
+                           BM_ELEM_SELECT, angle_limit))
+               {
+                       continue;
+               }
+
+               EDBM_update_generic(em, true, true);
+       }
+       MEM_freeN(objects);
 
-       EDBM_update_generic(em, true, true);
        return OPERATOR_FINISHED;
 }
 
@@ -2019,19 +2079,28 @@ void MESH_OT_reveal(wmOperatorType *ot)
 
 static int edbm_normals_make_consistent_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
 
-       /* doflip has to do with bmesh_rationalize_normals, it's an internal
-        * thing */
-       if (!EDBM_op_callf(em, op, "recalc_face_normals faces=%hf", BM_ELEM_SELECT))
-               return OPERATOR_CANCELLED;
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
-       if (RNA_boolean_get(op->ptr, "inside")) {
-               EDBM_op_callf(em, op, "reverse_faces faces=%hf flip_multires=%b", BM_ELEM_SELECT, true);
-       }
+               if (em->bm->totfacesel == 0) {
+                       continue;
+               }
 
-       EDBM_update_generic(em, true, false);
+               if (!EDBM_op_callf(em, op, "recalc_face_normals faces=%hf", BM_ELEM_SELECT)) {
+                       continue;
+               }
+               if (RNA_boolean_get(op->ptr, "inside")) {
+                       EDBM_op_callf(em, op, "reverse_faces faces=%hf flip_multires=%b", BM_ELEM_SELECT, true);
+               }
+
+               EDBM_update_generic(em, true, false);
+       }
+       MEM_freeN(objects);
 
        return OPERATOR_FINISHED;
 }
@@ -2243,7 +2312,7 @@ void MESH_OT_vertices_smooth_laplacian(wmOperatorType *ot)
 
        RNA_def_int(ot->srna, "repeat", 1, 1, 1000,
                    "Number of iterations to smooth the mesh", "", 1, 200);
-       RNA_def_float(ot->srna, "lambda_factor", 5e-5f, 1e-7f, 1000.0f,
+       RNA_def_float(ot->srna, "lambda_factor", 1.0f, 1e-7f, 1000.0f,
                      "Lambda factor", "", 1e-7f, 1000.0f);
        RNA_def_float(ot->srna, "lambda_border", 5e-5f, 1e-7f, 1000.0f,
                      "Lambda factor in border", "", 1e-7f, 1000.0f);
@@ -2665,44 +2734,60 @@ static int edbm_merge_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
        const int type = RNA_enum_get(op->ptr, "type");
        const bool uvs = RNA_boolean_get(op->ptr, "uvs");
-       bool ok = false;
 
-       switch (type) {
-               case MESH_MERGE_CENTER:
-                       ok = merge_target(em, scene, v3d, obedit, false, uvs, op);
-                       break;
-               case MESH_MERGE_CURSOR:
-                       ok = merge_target(em, scene, v3d, obedit, true, uvs, op);
-                       break;
-               case MESH_MERGE_LAST:
-                       ok = merge_firstlast(em, false, uvs, op);
-                       break;
-               case MESH_MERGE_FIRST:
-                       ok = merge_firstlast(em, true, uvs, op);
-                       break;
-               case MESH_MERGE_COLLAPSE:
-                       ok = EDBM_op_callf(em, op, "collapse edges=%he uvs=%b", BM_ELEM_SELECT, uvs);
-                       break;
-               default:
-                       BLI_assert(0);
-                       break;
-       }
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
-       if (!ok) {
-               return OPERATOR_CANCELLED;
-       }
+               if (em->bm->totvertsel == 0) {
+                       continue;
+               }
 
-       EDBM_update_generic(em, true, true);
+               bool ok = false;
+               switch (type) {
+                       case MESH_MERGE_CENTER:
+                               ok = merge_target(em, scene, v3d, obedit, false, uvs, op);
+                               break;
+                       case MESH_MERGE_CURSOR:
+                               ok = merge_target(em, scene, v3d, obedit, true, uvs, op);
+                               break;
+                       case MESH_MERGE_LAST:
+                               ok = merge_firstlast(em, false, uvs, op);
+                               break;
+                       case MESH_MERGE_FIRST:
+                               ok = merge_firstlast(em, true, uvs, op);
+                               break;
+                       case MESH_MERGE_COLLAPSE:
+                               ok = EDBM_op_callf(em, op, "collapse edges=%he uvs=%b", BM_ELEM_SELECT, uvs);
+                               break;
+                       default:
+                               BLI_assert(0);
+                               break;
+               }
 
-       /* once collapsed, we can't have edge/face selection */
-       if ((em->selectmode & SCE_SELECT_VERTEX) == 0) {
-               EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+               if (!ok) {
+                       continue;
+               }
+
+               EDBM_update_generic(em, true, true);
+
+               /* once collapsed, we can't have edge/face selection */
+               if ((em->selectmode & SCE_SELECT_VERTEX) == 0) {
+                       EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+               }
+               /* Only active object supported, see comment below. */
+               if (ELEM(type, MESH_MERGE_FIRST, MESH_MERGE_LAST)) {
+                       break;
+               }
        }
 
+       MEM_freeN(objects);
+
        return OPERATOR_FINISHED;
 }
 
@@ -2728,6 +2813,10 @@ static const EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *UNUSED(
        if (obedit && obedit->type == OB_MESH) {
                BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
+               /* Only active object supported:
+                * In practice it doesn't make sense to run this operation on non-active meshes
+                * since selecting will activate - we could have own code-path for these but it's a hassle
+                * for now just apply to the active (first) object. */
                if (em->selectmode & SCE_SELECT_VERTEX) {
                        if (em->bm->selected.first && em->bm->selected.last &&
                            ((BMEditSelection *)em->bm->selected.first)->htype == BM_VERT &&
@@ -3535,7 +3624,7 @@ static Base *mesh_separate_tagged(Main *bmain, Scene *scene, ViewLayer *view_lay
 
        base_new = ED_object_add_duplicate(bmain, scene, view_layer, base_old, USER_DUP_MESH);
        /* DAG_relations_tag_update(bmain); */ /* normally would call directly after but in this case delay recalc */
-       assign_matarar(base_new->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */
+       assign_matarar(bmain, base_new->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */
 
        ED_object_base_select(base_new, BA_SELECT);
 
@@ -3795,8 +3884,8 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
 
                        if (type == 0) {
                                if ((em->bm->totvertsel == 0) &&
-                                       (em->bm->totedgesel == 0) &&
-                                       (em->bm->totfacesel == 0))
+                                   (em->bm->totedgesel == 0) &&
+                                   (em->bm->totfacesel == 0))
                                {
                                        /* when all objects has no selection */
                                        if (++empty_selection_len == bases_len) {
@@ -3926,45 +4015,64 @@ void MESH_OT_separate(wmOperatorType *ot)
 
 static int edbm_fill_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
        const bool use_beauty = RNA_boolean_get(op->ptr, "use_beauty");
-       BMOperator bmop;
-       const int totface_orig = em->bm->totface;
-       int ret;
 
-       if (em->bm->totedgesel == 0) {
-               BKE_report(op->reports, RPT_WARNING, "No edges selected");
-               return OPERATOR_CANCELLED;
-       }
+       bool has_selected_edges = false, has_faces_filled = false;
 
-       if (!EDBM_op_init(em, &bmop, op,
-                         "triangle_fill edges=%he use_beauty=%b",
-                         BM_ELEM_SELECT, use_beauty))
-       {
-               return OPERATOR_CANCELLED;
-       }
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
-       BMO_op_exec(em->bm, &bmop);
+               const int totface_orig = em->bm->totface;
+
+               if (em->bm->totedgesel == 0) {
+                       continue;
+               }
+               has_selected_edges = true;
+
+               BMOperator bmop;
+               if (!EDBM_op_init(
+                           em, &bmop, op,
+                           "triangle_fill edges=%he use_beauty=%b",
+                           BM_ELEM_SELECT, use_beauty))
+               {
+                       continue;
+               }
+
+               BMO_op_exec(em->bm, &bmop);
+
+               /* cancel if nothing was done */
+               if (totface_orig == em->bm->totface) {
+                       EDBM_op_finish(em, &bmop, op, true);
+                       continue;
+               }
+               has_faces_filled = true;
 
-       if (totface_orig != em->bm->totface) {
                /* select new geometry */
                BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_FACE | BM_EDGE, BM_ELEM_SELECT, true);
 
-               EDBM_update_generic(em, true, true);
+               if (!EDBM_op_finish(em, &bmop, op, true)) {
+                       continue;
+               }
 
-               ret = OPERATOR_FINISHED;
+               EDBM_update_generic(em, true, true);
        }
-       else {
-               BKE_report(op->reports, RPT_WARNING, "No faces filled");
-               ret = OPERATOR_CANCELLED;
+       MEM_freeN(objects);
+
+       if (!has_selected_edges) {
+               BKE_report(op->reports, RPT_ERROR, "No edges selected");
+               return OPERATOR_CANCELLED;
        }
 
-       if (!EDBM_op_finish(em, &bmop, op, true)) {
-               ret = OPERATOR_CANCELLED;
+       if (!has_faces_filled) {
+               BKE_report(op->reports, RPT_WARNING, "No faces filled");
+               return OPERATOR_CANCELLED;
        }
 
-       return ret;
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_fill(wmOperatorType *ot)
@@ -4189,10 +4297,10 @@ static int edbm_fill_grid_exec(bContext *C, wmOperator *op)
 
                BMOperator bmop;
                if (!EDBM_op_init(
-                       em, &bmop, op,
-                       "grid_fill edges=%he mat_nr=%i use_smooth=%b use_interp_simple=%b",
-                       use_prepare ? BM_ELEM_TAG : BM_ELEM_SELECT,
-                       em->mat_nr, use_smooth, use_interp_simple))
+                           em, &bmop, op,
+                           "grid_fill edges=%he mat_nr=%i use_smooth=%b use_interp_simple=%b",
+                           use_prepare ? BM_ELEM_TAG : BM_ELEM_SELECT,
+                           em->mat_nr, use_smooth, use_interp_simple))
                {
                        continue;
                }
@@ -4207,7 +4315,7 @@ static int edbm_fill_grid_exec(bContext *C, wmOperator *op)
 
                /* cancel if nothing was done */
                if ((totedge_orig == em->bm->totedge) &&
-                       (totface_orig == em->bm->totface))
+                   (totface_orig == em->bm->totface))
                {
                        EDBM_op_finish(em, &bmop, op, true);
                        continue;
@@ -4606,6 +4714,7 @@ static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op)
 
                EDBM_update_generic(em, true, true);
        }
+       MEM_freeN(objects);
 
        return OPERATOR_FINISHED;
 }
@@ -5201,7 +5310,7 @@ static int edbm_dissolve_degenerate_exec(bContext *C, wmOperator *op)
        } /* objects */
 
        const float thresh = RNA_float_get(op->ptr, "threshold");
-       
+
        for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
                Object *obedit = objects[ob_index];
                BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -5338,11 +5447,12 @@ static int edbm_split_exec(bContext *C, wmOperator *op)
        for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
                Object *obedit = objects[ob_index];
                BMEditMesh *em = BKE_editmesh_from_object(obedit);
-
-               if (em->bm->totfacesel == 0) {
+               if ((em->bm->totvertsel == 0) &&
+                   (em->bm->totedgesel == 0) &&
+                   (em->bm->totfacesel == 0))
+               {
                        continue;
                }
-
                BMOperator bmop;
                EDBM_op_init(em, &bmop, op, "split geom=%hvef use_only_faces=%b", BM_ELEM_SELECT, false);
                BMO_op_exec(em->bm, &bmop);
@@ -6314,73 +6424,89 @@ void MESH_OT_offset_edge_loops(wmOperatorType *ot)
 #ifdef WITH_BULLET
 static int edbm_convex_hull_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(obedit);
-       BMOperator bmop;
+       const bool use_existing_faces = RNA_boolean_get(op->ptr, "use_existing_faces");
+       const bool delete_unused = RNA_boolean_get(op->ptr, "delete_unused");
+       const bool make_holes = RNA_boolean_get(op->ptr, "make_holes");
+       const bool join_triangles = RNA_boolean_get(op->ptr, "join_triangles");
 
-       EDBM_op_init(
-               em, &bmop, op, "convex_hull input=%hvef "
-               "use_existing_faces=%b",
-               BM_ELEM_SELECT,
-               RNA_boolean_get(op->ptr, "use_existing_faces"));
-       BMO_op_exec(em->bm, &bmop);
+       float angle_face_threshold = RNA_float_get(op->ptr, "face_threshold");
+       float angle_shape_threshold = RNA_float_get(op->ptr, "shape_threshold");
 
-       /* Hull fails if input is coplanar */
-       if (BMO_error_occurred(em->bm)) {
-               EDBM_op_finish(em, &bmop, op, true);
-               return OPERATOR_CANCELLED;
-       }
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *obedit = objects[ob_index];
+               BMEditMesh *em = BKE_editmesh_from_object(obedit);
 
-       BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_FACE, BM_ELEM_SELECT, true);
+               if (em->bm->totvertsel == 0) {
+                       continue;
+               }
 
-       /* Delete unused vertices, edges, and faces */
-       if (RNA_boolean_get(op->ptr, "delete_unused")) {
-               if (!EDBM_op_callf(
-                           em, op, "delete geom=%S context=%i",
-                           &bmop, "geom_unused.out", DEL_ONLYTAGGED))
-               {
+               BMOperator bmop;
+
+               EDBM_op_init(
+                       em, &bmop, op, "convex_hull input=%hvef "
+                       "use_existing_faces=%b",
+                       BM_ELEM_SELECT,
+                       use_existing_faces);
+               BMO_op_exec(em->bm, &bmop);
+
+               /* Hull fails if input is coplanar */
+               if (BMO_error_occurred(em->bm)) {
                        EDBM_op_finish(em, &bmop, op, true);
-                       return OPERATOR_CANCELLED;
+                       continue;
                }
-       }
 
-       /* Delete hole edges/faces */
-       if (RNA_boolean_get(op->ptr, "make_holes")) {
-               if (!EDBM_op_callf(
-                           em, op, "delete geom=%S context=%i",
-                           &bmop, "geom_holes.out", DEL_ONLYTAGGED))
-               {
-                       EDBM_op_finish(em, &bmop, op, true);
-                       return OPERATOR_CANCELLED;
+               BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_FACE, BM_ELEM_SELECT, true);
+
+               /* Delete unused vertices, edges, and faces */
+               if (delete_unused) {
+                       if (!EDBM_op_callf(
+                                   em, op, "delete geom=%S context=%i",
+                                   &bmop, "geom_unused.out", DEL_ONLYTAGGED))
+                       {
+                               EDBM_op_finish(em, &bmop, op, true);
+                               continue;
+                       }
+               }
+
+               /* Delete hole edges/faces */
+               if (make_holes) {
+                       if (!EDBM_op_callf(
+                                   em, op, "delete geom=%S context=%i",
+                                   &bmop, "geom_holes.out", DEL_ONLYTAGGED))
+                       {
+                               EDBM_op_finish(em, &bmop, op, true);
+                               continue;
+                       }
                }
-       }
 
-       /* Merge adjacent triangles */
-       if (RNA_boolean_get(op->ptr, "join_triangles")) {
-               float angle_face_threshold = RNA_float_get(op->ptr, "face_threshold");
-               float angle_shape_threshold = RNA_float_get(op->ptr, "shape_threshold");
+               /* Merge adjacent triangles */
+               if (join_triangles) {
+                       if (!EDBM_op_call_and_selectf(
+                               em, op,
+                               "faces.out", true,
+                               "join_triangles faces=%S "
+                               "angle_face_threshold=%f angle_shape_threshold=%f",
+                               &bmop, "geom.out",
+                               angle_face_threshold, angle_shape_threshold))
+                       {
+                               EDBM_op_finish(em, &bmop, op, true);
+                               continue;
+                       }
+               }
 
-               if (!EDBM_op_call_and_selectf(
-                       em, op,
-                       "faces.out", true,
-                       "join_triangles faces=%S "
-                       "angle_face_threshold=%f angle_shape_threshold=%f",
-                       &bmop, "geom.out",
-                       angle_face_threshold, angle_shape_threshold))
-               {
-                       EDBM_op_finish(em, &bmop, op, true);
-                       return OPERATOR_CANCELLED;
+               if (!EDBM_op_finish(em, &bmop, op, true)) {
+                       continue;
                }
-       }
 
-       if (!EDBM_op_finish(em, &bmop, op, true)) {
-               return OPERATOR_CANCELLED;
-       }
-       else {
                EDBM_update_generic(em, true, true);
                EDBM_selectmode_flush(em);
-               return OPERATOR_FINISHED;
        }
+
+       MEM_freeN(objects);
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_convex_hull(wmOperatorType *ot)