[Bf-blender-cvs] [1ca57bc5f42] sculpt-dev: Sculpt: flushed out brush channel RNA and made basic UI

Joseph Eagar noreply at git.blender.org
Sat Sep 18 21:10:51 CEST 2021


Commit: 1ca57bc5f42bf92f672bf28a8a22d4d49bf5aee8
Author: Joseph Eagar
Date:   Sat Sep 18 12:10:14 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB1ca57bc5f42bf92f672bf28a8a22d4d49bf5aee8

Sculpt: flushed out brush channel RNA and made basic UI

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

M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/BKE_brush_engine.h
M	source/blender/blenkernel/intern/brush_engine.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/makesdna/DNA_sculpt_brush_types.h
M	source/blender/makesrna/intern/rna_brush_engine.c
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 3c5926e5972..c8d7817e5a7 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -19,7 +19,6 @@
 # <pep8 compliant>
 from bpy.types import Menu
 
-
 class UnifiedPaintPanel:
     # subclass must set
     # bl_space_type = 'IMAGE_EDITOR'
@@ -97,6 +96,68 @@ class UnifiedPaintPanel:
             return tool_settings.gpencil_vertex_paint
         return None
 
+    @staticmethod
+    def channel_unified(layout, context, brush, prop_name, icon='NONE', pressure=True, text=None, slider=False, header=False):
+        """ Generalized way of adding brush options to the UI,
+            along with their pen pressure setting and global toggle, if they exist. """
+        ch = brush.channels.channels[prop_name]
+        finalch = ch
+
+        l1 = layout
+
+        if ch.ui_expanded:
+            layout = layout.box().column() #.column() is a bit more compact
+
+        row = layout.row(align=True)
+            
+        if text is None:
+            s = prop_name.lower().replace("_", " ").split(" ");
+            text = ''
+            for k in s:
+                text += k[0].upper() + k[1:] + " "
+            text = text.strip()
+
+        if ch.inherit:
+            sd = context.tool_settings.sculpt
+            #ensure channel exists in tool settings channel set
+            sd.channels.ensure(ch)
+
+            finalch = sd.channels.channels[prop_name]
+
+        row.prop(finalch, "value", icon=icon, text=text, slider=slider)
+
+        if pressure:
+            row.prop(finalch.mappings["PRESSURE"], "enabled", text="", icon="STYLUS_PRESSURE")
+        #if pressure_name:
+        #    row.prop(brush, pressure_name, text="")
+
+        #if unified_name and not header:
+        #    # NOTE: We don't draw UnifiedPaintSettings in the header to reduce clutter. D5928#136281
+        #    row.prop(ups, unified_name, text="", icon='BRUSHES_ALL')
+        if not header:
+            row.prop(ch, "inherit", text="", icon='BRUSHES_ALL')
+            row.prop(ch, "ui_expanded", text="", icon="TRIA_DOWN" if ch.ui_expanded else "TRIA_RIGHT")
+
+            if ch.ui_expanded:
+                for mp in finalch.mappings:
+                    row2 = layout.row()
+                    name = mp.type.lower()
+
+                    if len(name) > 0:
+                        name = name[0].upper() + name[1:]
+                    else:
+                        name = "name error"
+
+                    row2.label(text=name)
+                    row2.prop(mp, "enabled", text="", icon="STYLUS_PRESSURE")
+                    row2.prop(mp, "ui_expanded", text="", icon="TRIA_DOWN" if mp.ui_expanded else "TRIA_RIGHT")
+
+                    if mp.ui_expanded:
+                        layout.template_curve_mapping(mp, "curve", brush=True)
+                    #row2.prop(mp, "curve")
+
+        return row
+
     @staticmethod
     def prop_unified(
             layout,
@@ -972,11 +1033,16 @@ def brush_shared_settings(layout, context, brush, popover=False):
             layout.row().prop(size_owner, "use_locked_size", expand=True)
             layout.separator()
 
-    #if strength and mode == "SCULPT":
-    #    layout.prop(brush.channels.channels["STRENGTH"], "value", text="Strength")
-    #    pass
-    #elif strength:
-    if strength:    
+    if 0 and strength:    
+        UnifiedPaintPanel.channel_unified(
+            layout,
+            context,
+            brush,
+            "STRENGTH",
+            slider=True
+        )
+        layout.separator()
+    elif strength:
         pressure_name = "use_pressure_strength" if strength_pressure else None
         UnifiedPaintPanel.prop_unified(
             layout,
@@ -988,7 +1054,6 @@ def brush_shared_settings(layout, context, brush, popover=False):
             slider=True,
         )
         layout.separator()
-
     if direction:
         layout.row().prop(brush, "direction", expand=True)
 
diff --git a/source/blender/blenkernel/BKE_brush_engine.h b/source/blender/blenkernel/BKE_brush_engine.h
index 5695cae3649..6b038f6d063 100644
--- a/source/blender/blenkernel/BKE_brush_engine.h
+++ b/source/blender/blenkernel/BKE_brush_engine.h
@@ -92,13 +92,19 @@ typedef struct BrushCommandList {
 } BrushCommandList;
 
 void BKE_brush_channel_free(BrushChannel *ch);
-void BKE_brush_channel_copy(BrushChannel *dst, BrushChannel *src);
+void BKE_brush_channel_copy_data(BrushChannel *dst, BrushChannel *src);
 void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def);
-BrushChannelSet *BKE_brush_channelset_create();
 
+BrushChannelSet *BKE_brush_channelset_create();
+BrushChannelSet *BKE_brush_channelset_copy(BrushChannelSet *src);
 void BKE_brush_channelset_free(BrushChannelSet *chset);
+
+// makes a copy of ch
 void BKE_brush_channelset_add(BrushChannelSet *chset, BrushChannel *ch);
 
+// checks is a channel with existing->idname exists; if not a copy of existing is made and inserted
+void BKE_brush_channelset_ensure_existing(BrushChannelSet *chset, BrushChannel *existing);
+
 BrushChannel *BKE_brush_channelset_lookup(BrushChannelSet *chset, const char *idname);
 
 bool BKE_brush_channelset_has(BrushChannelSet *chset, const char *idname);
@@ -123,6 +129,9 @@ BrushCommand *BKE_brush_command_init(BrushCommand *command, int tool);
 void BKE_builtin_commandlist_create(BrushChannelSet *chset, BrushCommandList *cl, int tool);
 void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *cset);
 void BKE_brush_channelset_write(BlendWriter *writer, BrushChannelSet *cset);
+void BKE_brush_mapping_copy_data(BrushMapping *dst, BrushMapping *src);
+const char *BKE_brush_mapping_type_to_str(BrushMappingType mapping);
+const char *BKE_brush_mapping_type_to_typename(BrushMappingType mapping);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index 6c4e879be3f..f35bd0d56dc 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -8,6 +8,7 @@
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_memarena.h"
+#include "BLI_rect.h"
 
 #include "DNA_brush_enums.h"
 #include "DNA_brush_types.h"
@@ -31,6 +32,31 @@
 
 #define ICON_NONE -1
 
+static bool check_corrupted_curve(BrushMapping *dst)
+{
+
+  const float clip_size_x = BLI_rctf_size_x(&dst->curve.curr);
+  const float clip_size_y = BLI_rctf_size_y(&dst->curve.curr);
+
+  // fix corrupted curve
+  if (clip_size_x == 0.0f || clip_size_y == 0.0f) {
+    for (int i = 0; i < 4; i++) {
+      BKE_curvemapping_free_data(&dst->curve);
+      BKE_curvemapping_set_defaults(&dst->curve, 1, 0.0, 0.0, 1.0, 1.0);
+
+      BKE_curvemap_reset(&dst->curve.cm[i],
+                         &(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
+                         CURVE_PRESET_LINE,
+                         dst->flag & BRUSH_MAPPING_INVERT);
+      BKE_curvemapping_init(&dst->curve);
+    }
+
+    return false;
+  }
+
+  return true;
+}
+
 /*
 Brush command lists.
 
@@ -50,6 +76,7 @@ BrushChannelType brush_builtin_channels[] = {
     .min = 0.001f,
     .type = BRUSH_CHANNEL_FLOAT,
     .max = 2048.0f,
+    .fvalue = 50.0f,
     .soft_min = 0.1f,
     .soft_max = 1024.0f,
     .mappings = {
@@ -62,6 +89,7 @@ BrushChannelType brush_builtin_channels[] = {
     .min = -1.0f,
     .type = BRUSH_CHANNEL_FLOAT,
     .max = 4.0f,
+    .fvalue = 0.5f,
     .soft_min = 0.0f,
     .soft_max = 1.0f,
     .mappings = {
@@ -74,6 +102,7 @@ BrushChannelType brush_builtin_channels[] = {
     .min = 0.001f,
     .type = BRUSH_CHANNEL_FLOAT,
     .max = 4.0f,
+    .fvalue = 0.1f,
     .soft_min = 0.005f,
     .soft_max = 2.0f,
     .mappings = {
@@ -110,6 +139,7 @@ BrushChannelType brush_builtin_channels[] = {
     .type = BRUSH_CHANNEL_FLOAT,
     .min = 0.0001f,
     .max = 25.0f,
+    .fvalue = 1.0f,
     .soft_min = 0.1f,
     .soft_max = 4.0f,
     .mappings = {
@@ -122,6 +152,7 @@ BrushChannelType brush_builtin_channels[] = {
     .type = BRUSH_CHANNEL_FLOAT,
     .min = 0.0001f,
     .max = 25.0f,
+    .fvalue = 1.0f,
     .soft_min = 0.1f,
     .soft_max = 4.0f,
     .mappings = {
@@ -134,6 +165,7 @@ BrushChannelType brush_builtin_channels[] = {
     .type = BRUSH_CHANNEL_FLOAT,
     .min = 0.0001f,
     .max = 1.0f,
+    .fvalue = 1.0f,
     .soft_min = 0.1f,
     .soft_max = 1.0f,
     .mappings = {
@@ -215,12 +247,13 @@ void BKE_brush_channel_free(BrushChannel *ch)
   }
 }
 
-ATTR_NO_OPT void BKE_brush_channel_copy(BrushChannel *dst, BrushChannel *src)
+ATTR_NO_OPT void BKE_brush_channel_copy_data(BrushChannel *dst, BrushChannel *src)
 {
   *dst = *src;
 
   for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
-    BKE_curvemapping_copy_data(&dst->mappings[i].curve, &src->mappings[i].curve);
+    BKE_brush_mapping_copy_data(dst->mappings + i, src->mappings + i);
+    dst->mappings[i].type = i;
   }
 }
 
@@ -241,6 +274,8 @@ ATTR_NO_OPT void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
     BrushMapping *map = ch->mappings + i;
     CurveMapping *curve = &map->curve;
 
+    map->type = i;
+
     memset(curve, 0, sizeof(*curve));
 
     float min, max;
@@ -262,9 +297,11 @@ ATTR_NO_OPT void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
 
     int slope = CURVEMAP_SLOPE_POSITIVE;
 
+    BKE_curvemapping_set_defaults(curve, 1, 0, min, 1, max);
+
     for (int i = 0; i < 4; i++) {
       BKE_curvemap_reset(&curve->cm[i],
-                         &(struct rctf){.xmax = 0, .ymax = min, .xmax = 1, .ymax = max},
+                         &(struct rctf){.xmin = 0, .ymin = min, .xmax = 1, .ymax = max},
                          mdef->curve,
                          slope);
     }
@@ -308,7 +345,7 @@ void BKE_brush_channelset_add(BrushChannelSet *chset, BrushChannel *ch)
     chset->channels = MEM_recallocN(chset->channels, sizeof(BrushChannel) * chset->totchannel);
   }
 
-  memcpy(chset->channels + chset->totchannel - 1, ch, sizeof(BrushChannel));
+  BKE_brush_channel_copy_data(chset->channels + chset

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list