[Bf-blender-cvs] [3fc687ad753] sculpt-dev: Sculpt: Finish color support for brush channels

Joseph Eagar noreply at git.blender.org
Tue Sep 21 04:42:45 CEST 2021


Commit: 3fc687ad753e7e597321220b5ff9b2ff6ae847e1
Author: Joseph Eagar
Date:   Mon Sep 20 19:41:00 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rB3fc687ad753e7e597321220b5ff9b2ff6ae847e1

Sculpt: Finish color support for brush channels

* BRUSH_CHANNEL_VEC3/4 are now implemented
* New flag BRUSH_CHANNEL_COLOR
* Also tried to sculpt's usage of wm.radial_control in keymaps

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
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/brush_engine_presets.c
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/blenloader/CMakeLists.txt
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/makesdna/DNA_sculpt_brush_types.h
M	source/blender/makesrna/intern/rna_brush_engine.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 322c5e63a18..cd3f78e7342 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -4299,6 +4299,28 @@ def km_curve(params):
 
 # Radial control setup helpers, this operator has a lot of properties.
 
+def radial_control_properties_channels(paint, prop, secondary_prop, secondary_rotation=False, color=False, zoom=False, type="float"):
+    brush_path = 'tool_settings.' + paint + '.brush'
+    channels_path = brush_path + ".channels.channels"
+    unified  = "tool_settings." + paint + ".channels.channels"
+
+    rotation = 'mask_texture_slot_angle' if secondary_rotation else 'texture_slot_angle'
+    return {
+        "properties": [
+            ("data_path_primary", '%s["%s"].%s_value' % (channels_path, prop, type)),
+            ("data_path_secondary", '%s["%s"].%s_value' % (unified, prop, type) if secondary_prop else ''),
+            ("use_secondary", '%s["%s"].inherit' % (channels_path, prop) if secondary_prop else ''),
+            #("rotation_path", '%s["%s"].float_value' % (channels_path, rotation)),
+            #("color_path", brush_path + '.cursor_color_add'),
+            #("fill_color_path", brush_path + '.color' if color else ''),
+            #("fill_color_override_path", unified_path + '.color' if color else ''),
+            #("fill_color_override_test_path", unified_path + '.use_unified_color' if color else ''),
+            #("zoom_path", 'space_data.zoom' if zoom else ''),
+            #("image_id", brush_path + ''),
+            #("secondary_tex", secondary_rotation),
+        ],
+    }
+
 
 def radial_control_properties(paint, prop, secondary_prop, secondary_rotation=False, color=False, zoom=False):
     brush_path = 'tool_settings.' + paint + '.brush'
@@ -4348,6 +4370,32 @@ def _template_paint_radial_control(paint, rotation=False, secondary_rotation=Fal
     return items
 
 
+def _template_paint_radial_control_channels(paint, rotation=False, secondary_rotation=False, color=False, zoom=False):
+    items = []
+
+    items.extend([
+        ("wm.radial_control", {"type": 'F', "value": 'PRESS'},
+         radial_control_properties_channels(paint, 'radius', 'use_unified_size', type="float", secondary_rotation=secondary_rotation, color=color, zoom=zoom)),
+        ("wm.radial_control", {"type": 'F', "value": 'PRESS', "shift": True},
+         radial_control_properties_channels(paint, 'strength', 'use_unified_strength', type="factor", secondary_rotation=secondary_rotation, color=color)),
+    ])
+
+    """
+    if rotation:
+        items.extend([
+            ("wm.radial_control", {"type": 'F', "value": 'PRESS', "ctrl": True},
+             radial_control_properties_channels(paint, 'texture_slot_angle', None, color=color)),
+        ])
+
+    if secondary_rotation:
+        items.extend([
+            ("wm.radial_control", {"type": 'F', "value": 'PRESS', "ctrl": True, "alt": True},
+             radial_control_properties_channels(paint, 'mask_texture_slot_angle', None, secondary_rotation=secondary_rotation, color=color)),
+        ])
+    """
+
+    return items
+
 def km_image_paint(params):
     items = []
     keymap = (
@@ -4567,7 +4615,8 @@ def km_sculpt(params):
          {"properties": [("scalar", 0.9)]}),
         ("brush.scale_size", {"type": 'RIGHT_BRACKET', "value": 'PRESS', "repeat": True},
          {"properties": [("scalar", 1.0 / 0.9)]}),
-        *_template_paint_radial_control("sculpt", rotation=True),
+        *_template_paint_radial_control_channels("sculpt", rotation=True),
+        #*_template_paint_radial_control("sculpt", rotation=True),
         # Stencil
         ("brush.stencil_control", {"type": 'RIGHTMOUSE', "value": 'PRESS'},
          {"properties": [("mode", 'TRANSLATION')]}),
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index c656df2fa81..38b75fe9713 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -126,6 +126,7 @@ class UnifiedPaintPanel:
         row = layout.row(align=True)
 
         typeprop = "float_value"
+
         if ch.type == "INT":
             typeprop = "int_value"
         elif ch.type == "BOOL":
@@ -134,6 +135,10 @@ class UnifiedPaintPanel:
             typeprop = "enum_value"
         elif ch.type == "BITMASK":
             typeprop = "flags_value"
+        elif ch.type == "VEC3":
+            typeprop = "color3_value"
+        elif ch.type == "VEC4":
+            typeprop = "color4_value"
 
         if text is None:
             s = prop_name.lower().replace("_", " ").split(" ");
@@ -274,6 +279,12 @@ class UnifiedPaintPanel:
 
     @staticmethod
     def prop_unified_color(parent, context, brush, prop_name, *, text=None):
+        if context.mode == 'SCULPT':
+#    def channel_unified(layout, context, brush, prop_name, icon='NONE', pressure=True, text=None,
+ #                       slider=False, header=False, expand=None, toolsettings_only=False):
+            return UnifiedPaintPanel.channel_unified(parent, context, brush, prop_name, text=text)
+
+
         ups = context.tool_settings.unified_paint_settings
         prop_owner = ups if ups.use_unified_color else brush
         parent.prop(prop_owner, prop_name, text=text)
diff --git a/source/blender/blenkernel/BKE_brush_engine.h b/source/blender/blenkernel/BKE_brush_engine.h
index f91b41d8a02..369d45d2bbf 100644
--- a/source/blender/blenkernel/BKE_brush_engine.h
+++ b/source/blender/blenkernel/BKE_brush_engine.h
@@ -89,6 +89,7 @@ typedef struct BrushChannelType {
   int type, flag;
   int ivalue;
   float fvalue;
+  float vector[4];
 
   BrushEnumDef enumdef[MAX_BRUSH_ENUM_DEF];  // for enum/bitmask types
   EnumPropertyItem *rna_enumdef;
@@ -188,6 +189,27 @@ void BKE_brush_channelset_set_final_float(BrushChannelSet *child,
                                           const char *idname,
                                           float value);
 
+void BKE_brush_channel_set_vector(BrushChannel *ch, float vec[4]);
+int BKE_brush_channel_get_vector_size(BrushChannel *ch);
+
+/* returns size of vector */
+int BKE_brush_channel_get_vector(BrushChannel *ch, float out[4], BrushMappingData *mapdata);
+
+float BKE_brush_channelset_get_final_vector(BrushChannelSet *brushset,
+                                            BrushChannelSet *toolset,
+                                            const char *idname,
+                                            float r_vec[4],
+                                            BrushMappingData *mapdata);
+void BKE_brush_channelset_set_final_vector(BrushChannelSet *brushset,
+                                           BrushChannelSet *toolset,
+                                           const char *idname,
+                                           float vec[4]);
+int BKE_brush_channelset_get_vector(BrushChannelSet *chset,
+                                    const char *idname,
+                                    float r_vec[4],
+                                    BrushMappingData *mapdata);
+bool BKE_brush_channelset_set_vector(BrushChannelSet *chset, const char *idname, float vec[4]);
+
 void BKE_brush_init_toolsettings(struct Sculpt *sd);
 void BKE_brush_builtin_create(struct Brush *brush, int tool);
 BrushCommandList *BKE_brush_commandlist_create();
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index d6d6692f06f..6f0b96e5d69 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -871,6 +871,175 @@ ATTR_NO_OPT float BKE_brush_channel_get_float(BrushChannel *ch, BrushMappingData
 
   return f;
 }
+ATTR_NO_OPT void BKE_brush_channel_set_vector(BrushChannel *ch, float vec[4])
+{
+  if (ch->type == BRUSH_CHANNEL_VEC4) {
+    copy_v4_v4(ch->vector, vec);
+  }
+  else {
+    copy_v3_v3(ch->vector, vec);
+  }
+}
+
+ATTR_NO_OPT int BKE_brush_channel_get_vector_size(BrushChannel *ch)
+{
+  switch (ch->type) {
+    case BRUSH_CHANNEL_VEC3:
+      return 3;
+    case BRUSH_CHANNEL_VEC4:
+      return 4;
+    default:
+      return 1;
+  }
+}
+
+ATTR_NO_OPT int BKE_brush_channel_get_vector(BrushChannel *ch,
+                                             float out[4],
+                                             BrushMappingData *mapdata)
+{
+  int size = 3;
+  if (ch->type == BRUSH_CHANNEL_VEC4) {
+    size = 4;
+  }
+
+  if (mapdata) {
+    float factor = 1.0f;
+
+    for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
+      BrushMapping *mp = ch->mappings + i;
+
+      if (!(mp->flag & BRUSH_MAPPING_ENABLED)) {
+        continue;
+      }
+
+      float inputf = ((float *)mapdata)[i];
+
+      float f2 = BKE_curvemapping_evaluateF(mp->curve, 0, inputf);
+
+      switch (mp->blendmode) {
+        case MA_RAMP_BLEND:
+          break;
+        case MA_RAMP_MULT:
+          f2 *= inputf * f2;
+          break;
+        case MA_RAMP_DIV:
+          f2 = inputf / (0.00001f + inputf);
+          break;
+        case MA_RAMP_ADD:
+          f2 += inputf;
+          break;
+        case MA_RAMP_SUB:
+          f2 = inputf - f2;
+          break;
+        case MA_RAMP_DIFF:
+          f2 = fabsf(inputf - f2);
+          break;
+        default:
+          printf("Unsupported brush mapping blend mode for %s (%s); will mix instead\n",
+                 ch->name,
+                 ch->idname);
+          break;
+      }
+
+      factor += (f2 - factor) * mp->factor;
+    }
+
+    if (size == 3) {
+      copy_v3_v3(out, ch->vector);
+      mul_v3_fl(out, factor);
+    }
+    else {
+      copy_v4_v4(out, ch->vector);
+
+      if (ch->flag & BRUSH_CHANNEL_APPLY_MAPPING_TO_ALPHA) {
+        mul_v4_fl(out, factor);
+      }
+      else {
+        mul_v3_fl(out, factor);
+      }
+    }
+  }
+
+  return size;
+}
+
+float BKE_brush_channelset_get_final_vector(BrushChannelSet *brushset,
+                                            BrushChannelSet *toolset,
+                                        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list