[Bf-blender-cvs] [42c0bd2e90a] sculpt-mode-features: Mask filter: add mask filter tool with iterations

Pablo Dobarro noreply at git.blender.org
Tue May 21 00:30:07 CEST 2019


Commit: 42c0bd2e90a4f4a21152495ba2742eb33629ade4
Author: Pablo Dobarro
Date:   Tue May 21 00:29:46 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB42c0bd2e90a4f4a21152495ba2742eb33629ade4

Mask filter: add mask filter tool with iterations

Now it is possible to test the operator without editing the keymap.
By changing the iterations of the filter it should be possible to avoid
adding an unnecessary amount of undo steps when working with high poly
meshes.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index fbf5ff9f823..819269ff129 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5854,6 +5854,17 @@ def km_3d_view_tool_sculpt_mesh_filter(params):
     )
 
 
+def km_3d_view_tool_sculpt_mask_filter(params):
+    return (
+        "3D View Tool: Sculpt, Mask Filter",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("sculpt.mask_filter", {"type": params.tool_mouse, "value": 'PRESS'},
+             None)
+        ]},
+    )
+
+
 def km_3d_view_tool_paint_weight_sample_weight(params):
     return (
         "3D View Tool: Paint Weight, Sample Weight",
@@ -6295,6 +6306,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_sculpt_box_hide(params),
         km_3d_view_tool_sculpt_box_mask(params),
         km_3d_view_tool_sculpt_mesh_filter(params),
+        km_3d_view_tool_sculpt_mask_filter(params),
         km_3d_view_tool_paint_weight_sample_weight(params),
         km_3d_view_tool_paint_weight_sample_vertex_group(params),
         km_3d_view_tool_paint_weight_gradient(params),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 63850a63ad4..02353cd9991 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -948,6 +948,24 @@ class _defs_sculpt:
             keymap=(),
         )
 
+    @ToolDef.from_fn
+    def mask_filter():
+        def draw_settings(context, layout, tool):
+            props = tool.operator_properties("sculpt.mask_filter")
+            sub = layout.row()
+            sub.use_property_split = False
+            sub.prop(props, "type", expand=False)
+            sub.prop(props, "iterations")
+
+        return dict(
+            idname="builtin.mask_filter",
+            label="Mask Filter",
+            icon="ops.sculpt.mask_filter",
+            widget=None,
+            keymap= (),
+            draw_settings=draw_settings,
+        )
+
     @ToolDef.from_fn
     def mesh_filter():
         def draw_settings(context, layout, tool):
@@ -1887,6 +1905,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             _defs_sculpt.hide_border,
             _defs_sculpt.mask_border,
             _defs_sculpt.mesh_filter,
+            _defs_sculpt.mask_filter,
             _defs_sculpt.translate,
             _defs_transform.rotate,
             *_tools_annotate,
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index fbe99191fbe..413bb7ab902 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -7911,8 +7911,6 @@ static void mask_filter_task_cb(void *__restrict userdata,
 
   PBVHVertexIter vd;
 
-  sculpt_undo_push_node(data->ob, node, SCULPT_UNDO_MASK);
-
   BKE_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_UNIQUE)
   {
     float val;
@@ -7995,27 +7993,35 @@ static int sculpt_mask_filter_exec(bContext *C, wmOperator *op)
 
   sculpt_undo_push_begin("Mask blur fill");
 
-  float *prev_mask;
-  if (ELEM(mode, MASK_FILTER_GROW, MASK_FILTER_SHRINK)) {
-    prev_mask = MEM_dupallocN(ss->vmask);
+  float *prev_mask = NULL;
+  int iterations = RNA_int_get(op->ptr, "iterations");
+
+  for (int i = 0; i < totnode; i++) {
+    sculpt_undo_push_node(ob, nodes[i], SCULPT_UNDO_MASK);
   }
 
-  SculptThreadedTaskData data = {
-      .sd = sd,
-      .ob = ob,
-      .nodes = nodes,
-      .smooth_value = 0.5f,
-      .filter_type = mode,
-      .prev_mask = prev_mask,
-  };
+  for (int i = 0; i < iterations; i++) {
+    if (ELEM(mode, MASK_FILTER_GROW, MASK_FILTER_SHRINK)) {
+      prev_mask = MEM_dupallocN(ss->vmask);
+    }
 
-  ParallelRangeSettings settings;
-  BLI_parallel_range_settings_defaults(&settings);
-  settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT);
-  BLI_task_parallel_range(0, totnode, &data, mask_filter_task_cb, &settings);
+    SculptThreadedTaskData data = {
+        .sd = sd,
+        .ob = ob,
+        .nodes = nodes,
+        .smooth_value = 0.5f,
+        .filter_type = mode,
+        .prev_mask = prev_mask,
+    };
 
-  if (ELEM(mode, MASK_FILTER_GROW, MASK_FILTER_SHRINK))
-    MEM_freeN(prev_mask);
+    ParallelRangeSettings settings;
+    BLI_parallel_range_settings_defaults(&settings);
+    settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT);
+    BLI_task_parallel_range(0, totnode, &data, mask_filter_task_cb, &settings);
+
+    if (ELEM(mode, MASK_FILTER_GROW, MASK_FILTER_SHRINK))
+      MEM_freeN(prev_mask);
+  }
 
   sculpt_undo_push_end();
 
@@ -8044,6 +8050,7 @@ void SCULPT_OT_mask_filter(struct wmOperatorType *ot)
 
   /* rna */
   ot->prop = RNA_def_enum(ot->srna, "type", prop_mask_filter_types, MASK_FILTER_BLUR, "Type", "");
+  ot->prop = RNA_def_int(ot->srna, "iterations", 1, 1, 100, "Iterations", "", 1, 50);
 }
 
 static void do_color_fill_task_cb(void *__restrict userdata,



More information about the Bf-blender-cvs mailing list