[Bf-blender-cvs] [87ae49c78e6] sculpt-dev: Sculpt Expand: Expose geodesic and topology recursions

Pablo Dobarro noreply at git.blender.org
Wed Jan 20 18:56:55 CET 2021


Commit: 87ae49c78e66375a307b9915a80103f0145365af
Author: Pablo Dobarro
Date:   Tue Jan 19 00:14:10 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rB87ae49c78e66375a307b9915a80103f0145365af

Sculpt Expand: Expose geodesic and topology recursions

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

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

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 83619becf86..b8f1aaefb6a 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5535,7 +5535,8 @@ def km_sculpt_expand_modal(_params):
         ("INVERT", {"type": 'F', "value": 'PRESS', "any": True, "repeat" : False}, None),
         ("PRESERVE", {"type": 'E', "value": 'PRESS', "any": True, "repeat" : False}, None),
         ("GRADIENT", {"type": 'G', "value": 'PRESS', "any": True, "repeat" : False}, None),
-        ("RECURSION_STEP", {"type": 'R', "value": 'PRESS', "any": True, "repeat" : False}, None),
+        ("RECURSION_STEP_GEODESIC", {"type": 'R', "value": 'PRESS', "any": True, "repeat" : False}, None),
+        ("RECURSION_STEP_TOPOLOGY", {"type": 'R', "value": 'PRESS', "alt" : True ,"any": True, "repeat" : False}, None),
         ("MOVE_TOGGLE", {"type": 'SPACE', "value": 'ANY', "any": True, "repeat" : False}, None),
         ("FALLOFF_GEODESICS", {"type": 'ONE', "value": 'PRESS', "any": True, "repeat" : False}, None),
         ("FALLOFF_TOPOLOGY", {"type": 'TWO', "value": 'PRESS', "any": True, "repeat" : False}, None),
diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.c b/source/blender/editors/sculpt_paint/sculpt_expand.c
index 50334a5a681..76d9b7d3775 100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@ -82,7 +82,8 @@ enum {
   SCULPT_EXPAND_MODAL_PRESERVE_TOGGLE,
   SCULPT_EXPAND_MODAL_GRADIENT_TOGGLE,
   SCULPT_EXPAND_MODAL_FALLOFF_CYCLE,
-  SCULPT_EXPAND_MODAL_RECURSION_STEP,
+  SCULPT_EXPAND_MODAL_RECURSION_STEP_GEODESIC,
+  SCULPT_EXPAND_MODAL_RECURSION_STEP_TOPOLOGY,
   SCULPT_EXPAND_MODAL_MOVE_TOGGLE,
   SCULPT_EXPAND_MODAL_FALLOFF_GEODESICS,
   SCULPT_EXPAND_MODAL_FALLOFF_TOPOLOGY,
@@ -110,21 +111,22 @@ static EnumPropertyItem prop_sculpt_expand_target_type_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+#define SCULPT_EXPAND_LOOP_THRESHOLD 0.00001f
 
 static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache, const int i)
 {
   bool enabled = false;
 
-
   if (expand_cache->snap) {
     const int face_set = SCULPT_vertex_face_set_get(ss, i);
     enabled = BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
   }
   else {
-  const float loop_len = (expand_cache->max_falloff_factor / expand_cache->loop_count) + 0.0001f;
+    const float loop_len = (expand_cache->max_falloff_factor / expand_cache->loop_count) +
+                           SCULPT_EXPAND_LOOP_THRESHOLD;
 
-  const float active_factor = fmod(expand_cache->active_factor, loop_len);
-  const float falloff_factor = fmod(expand_cache->falloff_factor[i], loop_len);
+    const float active_factor = fmod(expand_cache->active_factor, loop_len);
+    const float falloff_factor = fmod(expand_cache->falloff_factor[i], loop_len);
 
     enabled = falloff_factor < active_factor;
   }
@@ -143,13 +145,17 @@ static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_
     enabled = BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
   }
   else {
-    enabled = expand_cache->face_falloff_factor[f] <= expand_cache->active_factor;
+    const float loop_len = (expand_cache->max_face_falloff_factor / expand_cache->loop_count) +
+                           SCULPT_EXPAND_LOOP_THRESHOLD;
+    const float active_factor = fmod(expand_cache->active_factor, loop_len);
+    const float falloff_factor = fmod(expand_cache->face_falloff_factor[f], loop_len);
+    enabled = falloff_factor < active_factor;
   }
 
   if (expand_cache->falloff_factor_type == SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET) {
-      if (ss->face_sets[f] == expand_cache->initial_active_face_set) {
-          enabled = false;
-      }
+    if (ss->face_sets[f] == expand_cache->initial_active_face_set) {
+      enabled = false;
+    }
   }
 
   if (expand_cache->invert) {
@@ -165,13 +171,13 @@ static float sculpt_expand_gradient_falloff_get(ExpandCache *expand_cache, const
     return 1.0f;
   }
 
-  const float loop_len = (expand_cache->max_falloff_factor / expand_cache->loop_count) + 0.0001f;
+  const float loop_len = (expand_cache->max_falloff_factor / expand_cache->loop_count) +
+                         SCULPT_EXPAND_LOOP_THRESHOLD;
   const float active_factor = fmod(expand_cache->active_factor, loop_len);
   const float falloff_factor = fmod(expand_cache->falloff_factor[i], loop_len);
 
   if (expand_cache->invert) {
-    return (falloff_factor - active_factor) /
-           (loop_len - active_factor);
+    return (falloff_factor - active_factor) / (loop_len - active_factor);
   }
 
   return 1.0f - (falloff_factor / active_factor);
@@ -448,10 +454,10 @@ static BLI_bitmap *sculpt_expand_bitmap_from_enabled(SculptSession *ss, ExpandCa
   return enabled_vertices;
 }
 
-
 static void sculpt_expand_geodesics_from_state_boundary(Object *ob,
-                                              ExpandCache *expand_cache,
-                                                        BLI_bitmap *enabled_vertices) {
+                                                        ExpandCache *expand_cache,
+                                                        BLI_bitmap *enabled_vertices)
+{
   SculptSession *ss = ob->sculpt;
   GSet *initial_vertices = BLI_gset_int_new("initial_vertices");
   const int totvert = SCULPT_vertex_count_get(ss);
@@ -479,8 +485,9 @@ static void sculpt_expand_geodesics_from_state_boundary(Object *ob,
 }
 
 static void sculpt_expand_topology_from_state_boundary(Object *ob,
-                                              ExpandCache *expand_cache,
-                                                        BLI_bitmap *enabled_vertices) {
+                                                       ExpandCache *expand_cache,
+                                                       BLI_bitmap *enabled_vertices)
+{
   SculptSession *ss = ob->sculpt;
   const int totvert = SCULPT_vertex_count_get(ss);
   SculptFloodFill flood;
@@ -518,20 +525,12 @@ static void sculpt_expand_from_state_boundary(Object *ob,
                                               ExpandCache *expand_cache,
                                               BLI_bitmap *enabled_vertices)
 {
-    switch (expand_cache->recursion_type) {
-    case SCULPT_EXPAND_RECURSION_GEODESICS:
-        sculpt_expand_geodesics_from_state_boundary(ob, expand_cache, enabled_vertices);
-        break;
-    case SCULPT_EXPAND_RECURSION_TOPOLOGY:
-        sculpt_expand_topology_from_state_boundary(ob, expand_cache, enabled_vertices);
-        break;
-    }
 }
 
 static void sculpt_expand_initialize_from_face_set_boundary(Object *ob,
-                                                             ExpandCache *expand_cache,
-                                                             const int active_face_set,
-                                                             const bool internal_falloff)
+                                                            ExpandCache *expand_cache,
+                                                            const int active_face_set,
+                                                            const bool internal_falloff)
 {
   SculptSession *ss = ob->sculpt;
   const int totvert = SCULPT_vertex_count_get(ss);
@@ -1018,13 +1017,24 @@ static void sculpt_expand_finish(bContext *C)
   ED_workspace_status_text(C, NULL);
 }
 
-static void sculpt_expand_resursion_step_add(Object *ob, ExpandCache *expand_cache)
+static void sculpt_expand_resursion_step_add(Object *ob,
+                                             ExpandCache *expand_cache,
+                                             const eSculptExpandRecursionType recursion_type)
 {
   SculptSession *ss = ob->sculpt;
   const int totvert = SCULPT_vertex_count_get(ss);
   BLI_bitmap *enabled_vertices = sculpt_expand_bitmap_from_enabled(ss, expand_cache);
   sculpt_expand_from_state_boundary(ob, expand_cache, enabled_vertices);
 
+  switch (recursion_type) {
+    case SCULPT_EXPAND_RECURSION_GEODESICS:
+      sculpt_expand_geodesics_from_state_boundary(ob, expand_cache, enabled_vertices);
+      break;
+    case SCULPT_EXPAND_RECURSION_TOPOLOGY:
+      sculpt_expand_topology_from_state_boundary(ob, expand_cache, enabled_vertices);
+      break;
+  }
+
   sculpt_expand_update_max_falloff_factor(ss, expand_cache);
   if (expand_cache->target == SCULPT_EXPAND_TARGET_FACE_SETS) {
     sculpt_expand_mesh_face_falloff_from_vertex_falloff(ob->data, expand_cache);
@@ -1130,8 +1140,12 @@ static int sculpt_expand_modal(bContext *C, wmOperator *UNUSED(op), const wmEven
         }
         break;
       }
-      case SCULPT_EXPAND_MODAL_RECURSION_STEP: {
-        sculpt_expand_resursion_step_add(ob, expand_cache);
+      case SCULPT_EXPAND_MODAL_RECURSION_STEP_GEODESIC: {
+        sculpt_expand_resursion_step_add(ob, expand_cache, SCULPT_EXPAND_RECURSION_GEODESICS);
+        break;
+      }
+      case SCULPT_EXPAND_MODAL_RECURSION_STEP_TOPOLOGY: {
+        sculpt_expand_resursion_step_add(ob, expand_cache, SCULPT_EXPAND_RECURSION_TOPOLOGY);
         break;
       }
       case SCULPT_EXPAND_MODAL_CONFIRM: {
@@ -1304,7 +1318,6 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
   BKE_pbvh_search_gather(
       ss->pbvh, NULL, NULL, &ss->expand_cache->nodes, &ss->expand_cache->totnode);
 
-
   /* Store initial state. */
   sculpt_expand_initial_state_store(ob, ss->expand_cache);
 
@@ -1317,7 +1330,7 @@ static int sculpt_expand_invoke(bContext *C, wmOperator *op, const wmEvent *even
   }
 
   /* Initialize the factors. */
-  eSculptExpandFalloffType falloff_type = SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET;
+  eSculptExpandFalloffType falloff_type = SCULPT_EXPAND_FALLOFF_GEODESICS;
   if (SCULPT_vertex_is_boundary(ss, ss->expand_cache->initial_active_vertex)) {
     falloff_type = SCULPT_EXPAND_FALLOFF_BOUNDARY_TOPOLOGY;
   }
@@ -1347,10 +1360,15 @@ void sculpt_expand_modal_keymap(wmKeyConfig *keyconf)
       {SCULPT_EXPAND_MODAL_INVERT, "INVERT", 0, "Invert"

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list