[Bf-blender-cvs] [c8aedd75d7b] sculpt-dev: Sculpt-dev: New normal automasking modes

Joseph Eagar noreply at git.blender.org
Fri Jan 7 21:09:32 CET 2022


Commit: c8aedd75d7b549bd2e4073a548efa34360be6614
Author: Joseph Eagar
Date:   Fri Jan 7 12:03:40 2022 -0800
Branches: sculpt-dev
https://developer.blender.org/rBc8aedd75d7b549bd2e4073a548efa34360be6614

Sculpt-dev: New normal automasking modes

Two new automasking modes: "Brush Normal"
and "View Normal."

Brush Normal compares vertex normals to
the initial sculpt normal, while View
Normal of course compares with the
view vector.

Each of these modes have an angular limit
and a falloff.  There's also an "original
normal" option, which needs a better name;
"original normal" is actually already taken,
but "automasking original normal" is a lot of
characters.  Not sure what to do here.

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/brush_channel_define.h
M	source/blender/blenkernel/intern/brush_engine_presets.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_automasking.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesdna/DNA_brush_enums.h
M	source/blender/makesdna/DNA_sculpt_brush_types.h
M	source/blender/makesrna/intern/rna_brush_engine.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 9364aafb4ed..c6bad232953 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -2105,11 +2105,51 @@ def brush_settings_advanced(layout, context, brush, popover=False):
             context,
             brush,
             "automasking_boundary_edges_propagation_steps")
-        UnifiedPaintPanel.channel_unified(layout.column(),
+
+        flags = UnifiedPaintPanel.get_channel_value(context, brush, "automasking")
+
+        if "CONCAVITY" in flags:
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "concave_mask_factor",
+                slider=True)
+
+        enable_orig_normal = False
+        
+        if "BRUSH_NORMAL" in flags:
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "normal_mask_limit",
+                slider=True)
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "normal_mask_falloff",
+                slider=True)
+            enable_orig_normal = True
+
+        if "VIEW_NORMAL" in flags:
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "view_normal_mask_limit",
+                slider=True)
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "view_normal_mask_falloff",
+                slider=True)
+            enable_orig_normal = True
+
+        sub = layout.row()
+        sub.enabled = enable_orig_normdal
+
+        UnifiedPaintPanel.channel_unified(sub,
             context,
             brush,
-            "concave_mask_factor",
-            slider=True)
+            "automasking_use_original_normal")
 
         """
         col = layout.column(heading="Auto-Masking", align=True)
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index c4dabb5b5bc..f63beee3f03 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -120,6 +120,8 @@ ToolDef = namedtuple(
         "draw_cursor",
         # Various options, see: `bpy.types.WorkSpaceTool.setup` options argument.
         "options",
+        #get_enabled(ctx, idname) whether tool should be grayed out
+        "get_enabled"
     )
 )
 del namedtuple
@@ -143,6 +145,7 @@ def from_dict(kw_args):
         "operator": None,
         "draw_settings": None,
         "draw_cursor": None,
+        "get_enabled": None
     }
     kw.update(kw_args)
 
@@ -725,9 +728,14 @@ class ToolSelectPanelHelper:
             icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(item.icon)
 
             sub = ui_gen.send(False)
+            sub2 = sub
+
+            if item.get_enabled is not None:
+                sub2 = sub.row(align=False)
+                sub2.enabled = item.get_enabled(context, item.idname)
 
             if use_menu:
-                sub.operator_menu_hold(
+                sub2.operator_menu_hold(
                     "wm.tool_set_by_id",
                     text=item.label if show_text else "",
                     depress=is_active,
@@ -735,7 +743,7 @@ class ToolSelectPanelHelper:
                     icon_value=icon_value,
                 ).name = item.idname
             else:
-                sub.operator(
+                sub2.operator(
                     "wm.tool_set_by_id",
                     text=item.label if show_text else "",
                     depress=is_active,
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index da185b53544..6edd0cb5a6d 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1211,6 +1211,83 @@ class _defs_particle:
             attr="tool",)
 
 
+def generate_from_enum_ex(_context, *,
+        idname_prefix,
+        icon_prefix,
+        type,
+        attr,
+        cursor='DEFAULT',
+        tooldef_keywords={},
+        exclude_filter={},
+        combine_map={}):
+    """
+    combine_map combines items, takes the form of a dict:
+
+        combine_map = {
+            "PARENT KEY" : (
+              "CHILD KEY"
+            )
+        }
+
+    """
+
+    combinekeys = {}
+    parentmap = {}
+
+    for k, v in combine_map.items():
+        combinekeys[k] = []
+
+        for child in v:
+            parentmap[child] = k
+
+    tool_defs = []
+
+    #build combine key owners first
+    for enum in type.bl_rna.properties[attr].enum_items_static:
+        name = enum.name
+        idname = enum.identifier
+        if idname in exclude_filter:
+            continue
+
+        if idname in combinekeys:
+            combinekeys[idname].append(ToolDef.from_dict(dict(idname=idname_prefix + name,
+                    label=name,
+                    icon=icon_prefix + idname.lower(),
+                    cursor=cursor,
+                    data_block=idname,
+                    **tooldef_keywords,)))
+
+    for enum in type.bl_rna.properties[attr].enum_items_static:
+        name = enum.name
+        idname = enum.identifier
+        if idname in exclude_filter:
+            continue
+
+        if idname in combinekeys:
+            tool_defs.append(combinekeys[idname])
+        elif idname in parentmap:
+            parentkey = parentmap[idname]
+
+            combinekeys[parentkey].append(ToolDef.from_dict(dict(idname=idname_prefix + name,
+                        label=name,
+                        icon=icon_prefix + idname.lower(),
+                        cursor=cursor,
+                        data_block=idname,
+                        **tooldef_keywords,)))
+        else:
+            tool_defs.append(ToolDef.from_dict(dict(idname=idname_prefix + name,
+                        label=name,
+                        icon=icon_prefix + idname.lower(),
+                        cursor=cursor,
+                        data_block=idname,
+                        **tooldef_keywords,)))
+
+    # finalize combined keys
+    for k, v in combinekeys.items():
+        tool_defs[tool_defs.index(v)] = tuple(v)
+
+    return tuple(tool_defs)
+
 class _defs_sculpt:
 
     @staticmethod
@@ -1229,12 +1306,32 @@ class _defs_sculpt:
             "SMOOTH" : ("ENHANCE_DETAILS",)
         }
 
+        def get_enabled(context, idname):
+            if "multires" in idname.lower() or idname.lower() == "builtin_brush.displacement heal":
+                print("IDNAME", idname)
+                have_multires = False;
+                ob = context.object
+
+                for mod in ob.modifiers:
+                    ok = mod.type == "MULTIRES"
+                    ok = ok and mod.sculpt_levels > 0
+                    ok = ok and mod.show_viewport
+
+                    if ok:
+                        have_multires = True
+                        break
+
+                return have_multires
+
+            return True
+
         return generate_from_enum_ex(context,
             idname_prefix="builtin_brush.",
             icon_prefix="brush.sculpt.",
             type=bpy.types.Brush,
             attr="sculpt_tool",
             exclude_filter=exclude_filter,
+            tooldef_keywords={"get_enabled" : get_enabled},
             combine_map=combine_map)
 
     @ToolDef.from_fn
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 2fbad9ba285..c5f0c055b9a 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1361,11 +1361,50 @@ class VIEW3D_PT_sculpt_automasking(Panel, View3DPaintPanel):
             brush,
             "automasking_boundary_edges_propagation_steps",
             ui_editing=False)
-        UnifiedPaintPanel.channel_unified(layout.column(),
+
+        if "CONCAVITY" in sculpt.channels["automasking"].value:
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "concave_mask_factor",
+                ui_editing=False, slider=True, show_mappings=True)
+
+        enable_orig_normal = False
+
+        if "BRUSH_NORMAL" in sculpt.channels["automasking"].value:
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "normal_mask_limit",
+                ui_editing=False, slider=True, show_mappings=True)
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "normal_mask_falloff",
+                ui_editing=False, slider=True, show_mappings=True)
+            enable_orig_normal = True
+
+        if "VIEW_NORMAL" in sculpt.channels["automasking"].value:
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "view_normal_mask_limit",
+                ui_editing=False, slider=True, show_mappings=True)
+            UnifiedPaintPanel.channel_unified(layout.column(),
+                context,
+                brush,
+                "view_normal_mask_falloff",
+                ui_editing=False, slider=True, show_mappings=True)
+            enable_orig_normal = True
+
+        sub = layout.row()
+        sub.enabled = enable_orig_normal
+
+        UnifiedPaintPanel.channel_unified(sub,
             context,
             brush,
-            "concave_mask_factor",
-            ui_editing=False, slider=True, show_mappings=True)
+            "automasking_use_original_normal",
+            ui_editing=False, show_mappings=False)
 
 
 class VIEW3D_PT_sculpt_options_gravity(Panel, View3DPaintPanel):
diff --git a/source/blender/blenkernel/intern/brush_channel_define.h b/sourc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list