Sculpt: Create Face Set by Edit Mode Selection
authorPablo Dobarro <pablodp606@gmail.com>
Sat, 21 Mar 2020 23:29:19 +0000 (00:29 +0100)
committerPablo Dobarro <pablodp606@gmail.com>
Thu, 26 Mar 2020 15:24:21 +0000 (16:24 +0100)
This implements a new mode in the Face Sets Create operator to create a
new face sets from the faces selection in edit mode. This can be used
when the user considers that the edit mode tools are more convenient for
a more precise control or a certain type of selection, like creating a
face set from a face loop.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D7211

release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/sculpt_paint/sculpt.c

index db128c14cf973c116cee2323194b6dd8b91e6dc8..cb5f02b03fd82f4c2749c58b90634b61a99dd22f 100644 (file)
@@ -3134,6 +3134,9 @@ class VIEW3D_MT_face_sets(Menu):
 
         op = layout.operator("sculpt.face_sets_create", text='Face Set From Visible')
         op.mode = 'VISIBLE'
+        
+        op = layout.operator("sculpt.face_sets_create", text='Face Set From Edit Mode Selection')
+        op.mode = 'SELECTION'
 
         layout.separator()
         
index f6ca36668bcc954303ab63a0a6fc232d3c253a6e..c7b15d0c096cf3075e79e3dbea617478d80853b4 100644 (file)
@@ -11067,6 +11067,7 @@ typedef enum eSculptFaceGroupsCreateModes {
   SCULPT_FACE_SET_MASKED = 0,
   SCULPT_FACE_SET_VISIBLE = 1,
   SCULPT_FACE_SET_ALL = 2,
+  SCULPT_FACE_SET_SELECTION = 3,
 } eSculptFaceGroupsCreateModes;
 
 static EnumPropertyItem prop_sculpt_face_set_create_types[] = {
@@ -11091,6 +11092,13 @@ static EnumPropertyItem prop_sculpt_face_set_create_types[] = {
         "Face Set Full Mesh",
         "Create an unique Face Set with all faces in the sculpt",
     },
+    {
+        SCULPT_FACE_SET_SELECTION,
+        "SELECTION",
+        0,
+        "Face Set From Edit Mode Selection",
+        "Create an Face Set corresponding to the Edit Mode face selection",
+    },
     {0, NULL, 0, NULL, NULL},
 };
 
@@ -11149,6 +11157,31 @@ static int sculpt_face_set_create_invoke(bContext *C, wmOperator *op, const wmEv
     }
   }
 
+  if (mode == SCULPT_FACE_SET_SELECTION) {
+    Mesh *mesh = ob->data;
+    BMesh *bm;
+    const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(mesh);
+    bm = BM_mesh_create(&allocsize,
+                        &((struct BMeshCreateParams){
+                            .use_toolflags = true,
+                        }));
+
+    BM_mesh_bm_from_me(bm,
+                       mesh,
+                       (&(struct BMeshFromMeshParams){
+                           .calc_face_normal = true,
+                       }));
+
+    BMIter iter;
+    BMFace *f;
+    BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+      if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+        ss->face_sets[BM_elem_index_get(f)] = next_face_set;
+      }
+    }
+    BM_mesh_free(bm);
+  }
+
   for (int i = 0; i < totnode; i++) {
     BKE_pbvh_node_mark_redraw(nodes[i]);
   }