[Bf-blender-cvs] [abf7518cbf5] sculpt-dev: Sculpt expand modal keymap

Pablo Dobarro noreply at git.blender.org
Fri Jan 15 22:24:26 CET 2021


Commit: abf7518cbf52e24c46e45de245e2017e5eb1fbd8
Author: Pablo Dobarro
Date:   Fri Jan 15 22:24:12 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rBabf7518cbf52e24c46e45de245e2017e5eb1fbd8

Sculpt expand modal keymap

===================================================================

M	release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/editors/sculpt_paint/sculpt_expand.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h

===================================================================

diff --git a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
index f92a478fb66..00ec00cb2ea 100644
--- a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
+++ b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
@@ -114,6 +114,7 @@ _km_hierarchy = [
         ('Custom Normals Modal Map', 'EMPTY', 'WINDOW', []),
         ('Bevel Modal Map', 'EMPTY', 'WINDOW', []),
         ('Paint Stroke Modal', 'EMPTY', 'WINDOW', []),
+        ('Sculpt Expand Modal', 'EMPTY', 'WINDOW', []),
         ('Paint Curve', 'EMPTY', 'WINDOW', []),
 
         ('Object Non-modal', 'EMPTY', 'WINDOW', []),  # mode change
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 4515df8bf14..6b1ed55fe49 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5520,6 +5520,22 @@ def km_paint_stroke_modal(_params):
 
     return keymap
 
+def km_sculpt_expand_modal(_params):
+    items = []
+    keymap = (
+        "Sculpt Expand Modal",
+        {"space_type": 'EMPTY', "region_type": 'WINDOW', "modal": True},
+        {"items": items},
+    )
+
+    items.extend([
+        ("CANCEL", {"type": 'ESC', "value": 'PRESS', "any": True}, None),
+        ("CANCEL", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}, None),
+        ("CONFIRM", {"type": 'LEFTMOUSE', "value": 'PRESS', "any": True}, None),
+        ("INVERT", {"type": 'F', "value": 'PRESS', "any": True, "repeat" : False}, None),
+    ])
+    return keymap
+
 
 # Fallback for gizmos that don't have custom a custom key-map.
 def km_generic_gizmo(_params):
@@ -7034,6 +7050,7 @@ def generate_keymaps(params=None):
         km_view3d_zoom_modal(params),
         km_view3d_dolly_modal(params),
         km_paint_stroke_modal(params),
+        km_sculpt_expand_modal(params),
 
         # Gizmos.
         km_generic_gizmo(params),
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index f4586fa130d..e1dc8fa30b9 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -1393,4 +1393,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
   /* paint stroke */
   keymap = paint_stroke_modal_keymap(keyconf);
   WM_modalkeymap_assign(keymap, "SCULPT_OT_brush_stroke");
+
+  /* sculpt expand. */
+  sculpt_expand_modal_keymap(keyconf);
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 37b472ded30..d164b203280 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -70,6 +70,12 @@
 
 #define SCULPT_EXPAND_VERTEX_NONE -1
 
+enum {
+  SCULPT_EXPAND_MODAL_CONFIRM = 1,
+  SCULPT_EXPAND_MODAL_CANCEL,
+  SCULPT_EXPAND_MODAL_INVERT,
+};
+
 static EnumPropertyItem prop_sculpt_expand_faloff_type_items[] = {
     {SCULPT_EXPAND_FALLOFF_GEODESICS, "GEODESICS", 0, "Surface", ""},
     {SCULPT_EXPAND_FALLOFF_TOPOLOGY, "TOPOLOGY", 0, "Topology", ""},
@@ -333,7 +339,7 @@ static void sculpt_expand_falloff_factors_from_vertex_and_symm_create(
   sculpt_expand_update_max_falloff_factor(ss, expand_cache);
 }
 
-void sculpt_expand_cache_free(ExpandCache *expand_cache)
+static void sculpt_expand_cache_free(ExpandCache *expand_cache)
 {
   MEM_SAFE_FREE(expand_cache->nodes);
   MEM_SAFE_FREE(expand_cache->falloff_factor);
@@ -513,6 +519,17 @@ static int sculpt_expand_modal(bContext *C, wmOperator *op, const wmEvent *event
   Object *ob = CTX_data_active_object(C);
   SculptSession *ss = ob->sculpt;
 
+  ExpandCache *expand_cache = ss->expand_cache;
+  if (event->type == EVT_MODAL_MAP) {
+    printf("MODAL KEYMAP\n");
+    switch (event->val) {
+      case SCULPT_EXPAND_MODAL_INVERT: {
+        expand_cache->invert = !expand_cache->invert;
+        break;
+      }
+    }
+  }
+
   const int target_expand_vertex = sculpt_expand_target_vertex_update_and_get(C, ob, event);
   sculpt_expand_update_for_vertex(C, ob, target_expand_vertex);
 
@@ -529,6 +546,11 @@ static int sculpt_expand_modal(bContext *C, wmOperator *op, const wmEvent *event
   return OPERATOR_RUNNING_MODAL;
 }
 
+static void sculpt_expand_cache_initial_config_set(ExpandCache *expand_cache, wmOperator *op)
+{
+  expand_cache->invert = RNA_boolean_get(op->ptr, "invert");
+}
+
 static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
   Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
@@ -545,6 +567,9 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
   /* Create the Expand Cache. */
   ss->expand_cache = MEM_callocN(sizeof(ExpandCache), "expand cache");
 
+  /* Configure the cache with the operator properties. */
+  sculpt_expand_cache_initial_config_set(ss->expand_cache, op);
+
   /* Set the initial element for expand. */
   int initial_vertex = sculpt_expand_target_vertex_update_and_get(C, ob, event);
   if (initial_vertex == SCULPT_EXPAND_VERTEX_NONE) {
@@ -562,10 +587,9 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
   sculpt_expand_initial_state_store(ob, ss->expand_cache);
 
   /* Initialize the factors. */
-
   eSculptExpandFalloffType falloff_type = SCULPT_EXPAND_FALLOFF_GEODESICS;
   if (SCULPT_vertex_is_boundary(ss, initial_vertex)) {
-      falloff_type = SCULPT_EXPAND_FALLOFF_BOUNDARY_TOPOLOGY;
+    falloff_type = SCULPT_EXPAND_FALLOFF_BOUNDARY_TOPOLOGY;
   }
 
   sculpt_expand_falloff_factors_from_vertex_and_symm_create(
@@ -583,6 +607,30 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
   return OPERATOR_RUNNING_MODAL;
 }
 
+void sculpt_expand_modal_keymap(wmKeyConfig *keyconf)
+{
+
+  static const EnumPropertyItem modal_items[] = {
+      {SCULPT_EXPAND_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
+      {SCULPT_EXPAND_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
+      {SCULPT_EXPAND_MODAL_INVERT, "INVERT", 0, "Invert", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  static const char *name = "Sculpt Expand Modal";
+  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, name);
+
+  /* this function is called for each spacetype, only needs to add map once */
+  if (keymap && keymap->modal_items) {
+    return;
+  }
+
+  keymap = WM_modalkeymap_ensure(keyconf, name, modal_items);
+
+  /* assign map to operators */
+  WM_modalkeymap_assign(keymap, "SCULPT_OT_expand");
+}
+
 void SCULPT_OT_expand(wmOperatorType *ot)
 {
   /* Identifiers. */
@@ -597,4 +645,6 @@ void SCULPT_OT_expand(wmOperatorType *ot)
   ot->poll = SCULPT_mode_poll;
 
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+  ot->prop = RNA_def_boolean(
+      ot->srna, "invert", true, "Invert", "Invert the expand active elements");
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 0c2b4d5f53a..5d045e1dd5c 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1183,7 +1183,6 @@ typedef struct ExpandCache {
   float *initial_mask;
   int *initial_face_sets;
 
-
 } ExpandCache;
 
 typedef struct FilterCache {
@@ -1316,6 +1315,7 @@ void SCULPT_OT_mask_expand(struct wmOperatorType *ot);
 
 /* Expand. */
 void SCULPT_OT_expand(struct wmOperatorType *ot);
+void sculpt_expand_modal_keymap(struct wmKeyConfig *keyconf);
 
 /* Detail size. */
 void SCULPT_OT_detail_flood_fill(struct wmOperatorType *ot);



More information about the Bf-blender-cvs mailing list