[Bf-blender-cvs] [abbba7371fc] sculpt-dev: Sculpt: UI organization

Joseph Eagar noreply at git.blender.org
Thu Sep 30 04:44:51 CEST 2021


Commit: abbba7371fca3437ed15afad6afb274a5863ee0d
Author: Joseph Eagar
Date:   Wed Sep 29 19:31:44 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBabbba7371fca3437ed15afad6afb274a5863ee0d

Sculpt: UI organization

* Brush channels can now be grouped in
  categories.
* TODO: let user edit and create the
  categories.

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

M	release/scripts/startup/bl_ui/properties_paint_common.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

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 1b8dceebdd5..5d554cfbc9b 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -17,7 +17,168 @@
 # ##### END GPL LICENSE BLOCK #####
 
 # <pep8 compliant>
-from bpy.types import Menu
+from bpy.types import Menu, Panel
+
+classes = []
+
+
+class DynamicBrushCategoryPanel(Panel):
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'UI'
+    bl_category = "Tool"
+
+    @classmethod
+    def poll(self, context):        
+        ok = context.mode == "SCULPT" and context.tool_settings.sculpt and context.tool_settings.sculpt.brush
+        ok = ok and len(self.get_channels(context)) > 0
+
+        return ok
+
+    @classmethod
+    def get_channels(self, context):
+        brush = context.tool_settings.sculpt.brush
+        
+        idname = self.get_category(self)
+
+        channels = list(filter(lambda ch: ch.show_in_workspace and ch.category == idname, brush.channels))
+        channels.sort(key=lambda ch: ch.ui_order)
+
+        return channels
+
+    def draw(self, context):
+        layout = self.layout
+        brush = context.tool_settings.sculpt.brush
+        
+        idname = self.get_category()
+        opt = self.get_options()
+
+        layout.use_property_split = True
+
+        channels = self.get_channels(context)
+
+        for ch in channels:
+            ok = ch.show_in_workspace
+            ok = ok and ch.category == idname
+            
+            if not ok:
+                continue
+            
+            UnifiedPaintPanel.channel_unified(
+                layout, 
+                context, 
+                brush,
+                ch.idname, 
+                slider=True,
+                ui_editing=opt["ui_editing"],
+                show_reorder=opt["show_reorder"])
+            
+class DynamicPaintPanelGen:
+    class Group:
+        def __init__(self, idname, name, prefix, parent):
+            self.idname = idname
+            self.name = name
+            self.prefix = prefix
+            self.rnaclass = None
+            self.parent = parent
+            self.options = {}
+    
+    groups = {}
+    
+    @staticmethod
+    def ensureCategory(idname, name=None, prefix="VIEW3D_PT_brush_category_", parent=None, show_reorder=False, ui_editing=False):
+        if name is None:
+            name = idname
+
+        groupid = prefix + idname.lower()
+
+        if groupid in DynamicPaintPanelGen.groups:
+            return DynamicPaintPanelGen.groups[groupid]
+
+        group = DynamicPaintPanelGen.Group(idname, name, prefix, parent)
+        DynamicPaintPanelGen.groups[groupid] = group
+
+        group.options={
+            "ui_editing" : ui_editing,
+            "show_reorder" : show_reorder
+        }
+        
+        def callback():
+            print("creating panel")
+            DynamicPaintPanelGen.createPanel(group)
+            pass
+        
+        import bpy
+        bpy.app.timers.register(callback)
+        
+        return group
+    
+    @staticmethod
+    def get(idname, prefix):
+        return DynamicPaintPanelGen.groups[idname]
+
+    @staticmethod
+    def createPanel(group):
+        from bpy.utils import register_class, unregister_class
+
+        from bpy.types import Panel
+        global classes
+        
+        name = group.prefix + group.idname.lower()
+        name2 = ""
+
+        for c in name:
+            n = ord(c)
+
+            ok = n >= ord("a") and n <= ord("a")
+            ok = ok or n >= ord("A") and n <= ord("Z")
+            ok = ok or n >= ord("0") and n <= ord("9")
+            ok = ok or c == "_"
+
+            if not ok:
+                c = "_"
+            name2 += c
+        name = name2
+
+        for cls in classes[:]:
+            print("_", cls.bl_rna.identifier, cls.bl_rna.identifier == name) #r, dir(cls.bl_rna)) #.name)
+            
+            if cls.bl_rna.identifier == name:
+                try:
+                    unregister_class(cls)
+                except:
+                    print("failed to unregister", name)
+                    
+                classes.remove(cls)
+
+        if group.parent:
+            parent = 'bl_parent_id = "%s"' % group.parent
+        else:
+            parent = ""
+
+        opt = repr(group.options)
+
+        code = """
+
+global classes
+
+class CLASSNAME (DynamicBrushCategoryPanel):
+    bl_label = "LABEL"
+    PARENT
+    
+    def get_category(self):
+        return "IDNAME"
+
+    def get_options(self):
+        return OPT
+
+register_class(CLASSNAME)
+classes.append(CLASSNAME)
+
+""".strip().replace("CLASSNAME", name).replace("PARENT", parent).replace("LABEL", group.name).replace("OPT", opt)
+        code = code.replace("IDNAME", group.idname)
+        
+        print("\n", code)
+        exec(code)        
 
 channel_name_map = {
     "size" : "radius",
@@ -1556,15 +1717,30 @@ class ReorderBrushChannel(Operator):
         
         return {'FINISHED'}
 
-def brush_settings_channels(layout, context, brush, ui_editing=False, popover=False, filterkey="show_in_workspace"):
+def brush_settings_channels(layout, context, brush, ui_editing=False, popover=False, show_reorder=None, filterkey="show_in_workspace",
+                            parent="VIEW3D_PT_tools_brush_settings_channels", prefix="VIEW3D_PT_brush_category_"):
     channels = get_ui_channels(brush.channels, [filterkey])
-    
+
+    if show_reorder is None:
+        show_reorder = ui_editing
+
+    DynamicPaintPanelGen.ensureCategory("Basic", "Basic", parent=parent,
+                       prefix=prefix, ui_editing=ui_editing,
+                       show_reorder=show_reorder)
+
     for ch in channels:
+        if len(ch.category) > 0:
+            DynamicPaintPanelGen.ensureCategory(ch.category, ch.category, parent=parent,
+                       prefix=prefix, ui_editing=ui_editing,
+                       show_reorder=show_reorder)
+            continue
+
+        #VIEW3D_PT_brush_category_edit_
         UnifiedPaintPanel.channel_unified(
                 layout.column(),
                 context,
                 brush,
-                ch.idname, show_reorder = ui_editing, expand=False, ui_editing=False)
+                ch.idname, show_reorder = show_reorder, expand=False, ui_editing=ui_editing)
 
 
 def brush_settings_advanced(layout, context, brush, popover=False):
@@ -2047,10 +2223,10 @@ def brush_basic_gpencil_vertex_settings(layout, _context, brush, *, compact=Fals
         row.prop(gp_settings, "vertex_mode", text="Mode")
 
 
-classes = (
+classes += [
     VIEW3D_MT_tools_projectpaint_clone,
     ReorderBrushChannel
-)
+]
 
 if __name__ == "__main__":  # only for live edit.
     from bpy.utils import register_class
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 820684a08d2..f882ef28567 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -452,8 +452,13 @@ class VIEW3D_PT_tools_brush_settings_channels_preview(Panel, View3DPaintBrushPan
 
         settings = self.paint_settings(context)
         brush = settings.brush
+        
+        brush_settings_channels(layout.column(), context, brush, show_reorder=True, ui_editing=False,
+            popover=self.is_popover,
+            prefix="VIEW3D_PT_brush_category_edit_",
+            parent="VIEW3D_PT_tools_brush_settings_channels_preview"
+        )
 
-        brush_settings_channels(layout.column(), context, brush, ui_editing=True, popover=self.is_popover)
 
 class VIEW3D_PT_tools_brush_settings_advanced(Panel, View3DPaintBrushPanel):
     bl_context = ".paint_common"
diff --git a/source/blender/blenkernel/intern/brush_channel_define.h b/source/blender/blenkernel/intern/brush_channel_define.h
index 88cc5caa132..2227e2e7218 100644
--- a/source/blender/blenkernel/intern/brush_channel_define.h
+++ b/source/blender/blenkernel/intern/brush_channel_define.h
@@ -421,8 +421,8 @@ MAKE_ENUM(deform_target, "Deformation Target", "How the deformation of the brush
     {-1}
 })
 
-MAKE_CURVE(autosmooth_falloff_curve, "Falloff", "Custom curve for autosmooth", BRUSH_CURVE_SMOOTH)
-MAKE_CURVE(topology_rake_falloff_curve, "Falloff", "Custom curve for topolgoy rake", BRUSH_CURVE_SMOOTH)
+MAKE_CURVE(autosmooth_falloff_curve, "Autosmooth Falloff", "Custom curve for autosmooth", BRUSH_CURVE_SMOOTH)
+MAKE_CURVE(topology_rake_falloff_curve, "Rake Falloff", "Custom curve for topolgoy rake", BRUSH_CURVE_SMOOTH)
 MAKE_CURVE(falloff_curve, "Falloff", "Falloff curve", BRUSH_CURVE_SMOOTH)
 MAKE_FLOAT_EX(unprojected_radius, "Unprojected Radius", "Radius of brush in Blender units", 0.1f, 0.001, FLT_MAX, 0.001, 1.0f, false)
 MAKE_ENUM_EX(radius_unit,  "Radius Unit", "Measure brush size relative to the view or the scene", 0, BRUSH_CHANNEL_SHOW_IN_WORKSPACE, {\
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index ec37caaea3f..045eaa202a2 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -212,7 +212,7 @@ static BrushChannelType *_get_def(const char *idname)
   BLI_strncpy(GETDEF(idname)->category, cat, sizeof(GETDEF(idname)->category))
 
 static bool do_builtin_init = true;
-ATTR_NO_OPT static bool check_builtin_init()
+static bool check_builtin_init()
 {
   if (!do_builtin_init || !BLI_thread_is_main()) {
     return false;
@@ -225,35 +225,70 @@ ATTR_NO_OPT static bool check_builtin_init()
   // BKE_brush_channeltype_rna_check(brush_builtin_channels + i);
   //}
 
-  SETCAT(strength, "Basic");
-  SETCAT(radius, "Basic");
-  SETCAT(direction, "Basic");
+  // don't group strength/radius/direction in subpanels
+  // SETCAT(strength, "Basic");
+  // SETCAT(radius, "Basic");
+  // SETCAT(direction, "Basic");
   SETCAT(accumulate, "Basic");
+
   SETCAT(tip_roundness, "Basic");
   SETCAT(hardness, "Basic");
   SETCAT(tip_scale_x, "Basic");
   SETCAT(tip_roundness, "Basic");
-
   SETCAT(normal_rad

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list