[Bf-blender-cvs] [ecf5f2b1186] temp-sculpt-brush-channel: temp-sculpt-brush-channel: Commit current code

Joseph Eagar noreply at git.blender.org
Mon Aug 8 11:36:33 CEST 2022


Commit: ecf5f2b1186a1c05ddebb8e1287f7111de008bd7
Author: Joseph Eagar
Date:   Sat Aug 6 16:28:10 2022 -0700
Branches: temp-sculpt-brush-channel
https://developer.blender.org/rBecf5f2b1186a1c05ddebb8e1287f7111de008bd7

temp-sculpt-brush-channel: Commit current code

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

M	source/blender/blenkernel/BKE_brush_channel.h
M	source/blender/blenkernel/intern/brush_channel.cc
M	source/blender/blenkernel/intern/brush_channel_define.h
M	source/blender/blenkernel/intern/scene.cc
M	source/blender/makesrna/intern/rna_brush_channels.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/BKE_brush_channel.h b/source/blender/blenkernel/BKE_brush_channel.h
index 825e5269fdd..a757ea1caa6 100644
--- a/source/blender/blenkernel/BKE_brush_channel.h
+++ b/source/blender/blenkernel/BKE_brush_channel.h
@@ -210,6 +210,20 @@ bool BKE_brush_channel_inherits(struct Brush *brush,
 BrushChannelSet *BKE_brush_channelset_get_final(struct Brush *brush,
                                                 struct ToolSettings *tool_settings);
 
+void BKE_brush_channelset_toolsettings_init(struct ToolSettings *ts);
+
+
+/* Disable optimization for a function (for debugging use only!)*/
+#ifdef __clang__
+#  define ATTR_NO_OPT __attribute__((optnone))
+#elif defined(_MSC_VER)
+#  define ATTR_NO_OPT __pragma(optimize("", off))
+#elif defined(__GNUC__)
+#  define ATTR_NO_OPT __attribute__((optimize("O0")))
+#else
+#  define ATTR_NO_OPT
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/brush_channel.cc b/source/blender/blenkernel/intern/brush_channel.cc
index bb5e9a35bd6..8285ac68745 100644
--- a/source/blender/blenkernel/intern/brush_channel.cc
+++ b/source/blender/blenkernel/intern/brush_channel.cc
@@ -35,17 +35,19 @@
 
 #include <string>
 
+#define BRUSH_CHANNEL_DEFINE_INTERNAL_NAMES
+#include "brush_channel_define.h"
+#undef BRUSH_CHANNEL_DEFINE_INTERNAL_NAMES
+
 using string = std::string;
 
 namespace blender {
 
-Map<const char *, BrushChannelType> builtin_channels;
+using KeyString = const char*;
 
-using ChannelNameMap = Map<const char *, BrushChannel *>;
+static Map<const char *, BrushChannelType> builtin_channels;
 
-#define BRUSH_CHANNEL_DEFINE_INTERNAL_NAMES
-#include "brush_channel_define.h"
-#undef BRUSH_CHANNEL_DEFINE_INTERNAL_NAMES
+using ChannelNameMap = Map<const char *, BrushChannel *>;
 
 static void init_builtin_brush_channels()
 {
@@ -77,6 +79,11 @@ static void init_builtin_brush_channels()
     PropertyRNA *prop = RNA_struct_type_find_property(srna, def.path);
     BLI_assert(prop);
 
+    if (!prop) {
+      printf("%s: Missing property %s\n", __func__, def.path);
+      continue;
+    }
+
     PropertyType prop_type = RNA_property_type(prop);
     PropertySubType prop_subtype = RNA_property_subtype(prop);
 
@@ -91,9 +98,10 @@ static void init_builtin_brush_channels()
     switch (prop_type) {
       case PROP_INT: {
         int min, max, soft_min, soft_max;
+        int step;
 
         RNA_property_int_range(nullptr, prop, &min, &max);
-        RNA_property_int_ui_range(nullptr, prop, &soft_min, &soft_max, nullptr);
+        RNA_property_int_ui_range(nullptr, prop, &soft_min, &soft_max, &step);
 
         type.min = (float)min;
         type.max = (float)max;
@@ -102,9 +110,11 @@ static void init_builtin_brush_channels()
         type.type = BRUSH_CHANNEL_TYPE_INT;
         break;
       }
-      case PROP_FLOAT:
+      case PROP_FLOAT: {
+        float precision, step;
+
         RNA_property_float_range(ptr, prop, &type.min, &type.max);
-        RNA_property_float_ui_range(ptr, prop, &type.soft_min, &type.soft_max, nullptr, nullptr);
+        RNA_property_float_ui_range(ptr, prop, &type.soft_min, &type.soft_max, &step, &precision);
 
         if (!RNA_property_array_check(prop)) {
           type.type = BRUSH_CHANNEL_TYPE_FLOAT;
@@ -124,6 +134,7 @@ static void init_builtin_brush_channels()
           }
         }
         break;
+      }
       default:
         break;
     }
@@ -149,6 +160,8 @@ static void init_builtin_brush_channels()
         break;
     }
 
+    printf("size: %i\n", (int)ARRAY_SIZE(channel_props));
+    printf("type: %s\n", type.idname); 
     builtin_channels.add(type.idname, type);
   }
 #undef BRUSH_CHANNEL_DEFINE_INTERNAL
@@ -259,9 +272,14 @@ extern "C" const void BKE_brush_channel_category_set(BrushChannel *ch, const cha
   ch->category = BLI_strdup(category);
 }
 
-extern "C" BrushChannel *_BKE_brush_channelset_ensure(BrushChannelSet *chset, const char *idname)
+ATTR_NO_OPT extern "C" BrushChannel *_BKE_brush_channelset_ensure(BrushChannelSet *chset, const char *idname)
 {
   if (!builtin_channels.contains(idname)) {
+    printf("channel types:\n");
+    for (const char *key : builtin_channels.keys()) {
+      printf("  %s\n", key);
+    }
+
     printf("Unknown brush channel %s\n", idname);
     return nullptr;
   }
@@ -278,7 +296,9 @@ extern "C" BrushChannel *_BKE_brush_channelset_ensure(BrushChannelSet *chset, co
 
 extern "C" void BKE_brush_channelset_ensure_channels(BrushChannelSet *chset, int sculpt_tool)
 {
-  BKE_brush_channelset_ensure(chset, radius);
+  check_builtin_brush_channels();
+
+  BKE_brush_channelset_ensure(chset, size);
   BKE_brush_channelset_ensure(chset, unprojected_radius);
   BKE_brush_channelset_ensure(chset, strength);
 
@@ -615,8 +635,10 @@ BrushChannelSet *BKE_brush_channelset_create_final(Brush *brush,
   return chset;
 }
 
-void BKE_brush_channelset_toolsettings_init(ToolSettings *ts)
+extern "C" void BKE_brush_channelset_toolsettings_init(ToolSettings *ts)
 {
+  check_builtin_brush_channels();
+
   if (!ts->unified_properties) {
     ts->unified_properties = IDP_New(IDP_GROUP, nullptr, "group");
   }
@@ -629,12 +651,14 @@ void BKE_brush_channelset_toolsettings_init(ToolSettings *ts)
     _BKE_brush_channelset_ensure(ts->unified_channels, type.idname);
   }
 
-  LISTBASE_FOREACH (BrushChannel *, ch, &ts->unified_channels) {
+  StructRNA *srna = RNA_struct_find("Brush");
+
+  LISTBASE_FOREACH (BrushChannel *, ch, &ts->unified_channels->channels) {
     IDProperty *idprop = IDP_GetPropertyFromGroup(ts->unified_properties, ch->idname);
 
     if (!idprop) {
       IDPropertyTemplate tmpl;
-      IDPropertyType type;
+      char type;
 
       switch (ch->type) {
         case BRUSH_CHANNEL_TYPE_FLOAT:
@@ -648,10 +672,60 @@ void BKE_brush_channelset_toolsettings_init(ToolSettings *ts)
           tmpl.i = ch->ivalue;
           type = IDP_INT;
           break;
+        default:
+          printf(
+              "%s: unsupported brush channel type for unified channel: %d\n", __func__, ch->type);
+          continue;
       }
 
-      prop = IDP_New(type, &tmpl, ch->idname);
+      idprop = IDP_New(type, &tmpl, ch->idname);
+      IDP_AddToGroup(ts->unified_properties, idprop);
     }
+
+    IDPropertyUIData *uidata = IDP_ui_data_ensure(idprop);
+
+    MEM_SAFE_FREE(uidata->description);
+    uidata->description = BLI_strdup(ch->def->tooltip);
+
+    PropertyRNA *prop = RNA_struct_type_find_property(srna, ch->def->idname);
+    BLI_assert(prop);
+
+    PropertyType prop_type = RNA_property_type(prop);
+    PropertySubType prop_subtype = RNA_property_subtype(prop);
+
+    switch (ch->type) {
+      case BRUSH_CHANNEL_TYPE_FLOAT: {
+        IDPropertyUIDataFloat *uidataf = reinterpret_cast<IDPropertyUIDataFloat *>(uidata);
+
+        float min, max, soft_min, soft_max, step, precision;
+
+        RNA_property_float_range(nullptr, prop, &min, &max);
+        RNA_property_float_ui_range(nullptr, prop, &soft_min, &soft_max, &step, &precision);
+
+        uidataf->min = (float)min;
+        uidataf->max = (float)max;
+        uidataf->soft_min = (float)soft_min;
+        uidataf->soft_max = (float)soft_max;
+        uidataf->step = (float)step;
+        uidataf->precision = (int)precision;
+        break;
+      }
+      case BRUSH_CHANNEL_TYPE_INT: {
+        IDPropertyUIDataInt *uidatai = reinterpret_cast<IDPropertyUIDataInt *>(uidata);
+
+        RNA_property_int_range(nullptr, prop, &uidatai->min, &uidatai->max);
+        RNA_property_int_ui_range(
+            nullptr, prop, &uidatai->soft_min, &uidatai->soft_max, &uidatai->step);
+        break;
+      }
+      case BRUSH_CHANNEL_TYPE_ENUM:
+      case BRUSH_CHANNEL_TYPE_BITMASK:
+      case BRUSH_CHANNEL_TYPE_BOOL: {
+        break;
+      }
+    }
+
+    uidata->rna_subtype = prop_subtype;
   }
 }
 
diff --git a/source/blender/blenkernel/intern/brush_channel_define.h b/source/blender/blenkernel/intern/brush_channel_define.h
index 6f9a6557b79..e1a4a94001c 100644
--- a/source/blender/blenkernel/intern/brush_channel_define.h
+++ b/source/blender/blenkernel/intern/brush_channel_define.h
@@ -37,10 +37,10 @@
 #define SHOW_HEADER BRUSH_CHANNEL_SHOW_IN_HEADER
 #define SHOW_ALL (SHOW_WORKSPACE | SHOW_CONTEXT | SHOW_HEADER)
 
-MAKE_PROP(radius, "Basic", SHOW_ALL)
+MAKE_PROP(size, "Basic", SHOW_ALL)
 MAKE_PROP(unprojected_radius, "Basic", SHOW_ALL)
 MAKE_PROP(strength, "Basic", SHOW_ALL)
-MAKE_PROP(autosmooth_factor, "Smooth", SHOW_WORKSPACE | SHOW_CONTEXT)
+MAKE_PROP(auto_smooth_factor, "Smooth", SHOW_WORKSPACE | SHOW_CONTEXT)
 
 #undef SHOW_WORKSPACE
 #undef SHOW_HEADER
diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc
index aaa6baac1ff..05cbd952aa3 100644
--- a/source/blender/blenkernel/intern/scene.cc
+++ b/source/blender/blenkernel/intern/scene.cc
@@ -56,6 +56,7 @@
 #include "BKE_animsys.h"
 #include "BKE_armature.h"
 #include "BKE_bpath.h"
+#include "BKE_brush_channel.h"
 #include "BKE_cachefile.h"
 #include "BKE_collection.h"
 #include "BKE_colortools.h"
@@ -136,6 +137,7 @@ static void scene_init_data(ID *id)
                      CURVEMAP_SLOPE_POS_NEG);
 
   scene->toolsettings = DNA_struct_default_alloc(ToolSettings);
+  BKE_brush_channelset_toolsettings_init(scene->toolsettings);
 
   scene->toolsettings->autokey_mode = (uchar)U.autokey_mode;
 
@@ -1127,6 +1129,16 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
 
   BLO_read_data_address(reader, &sce->toolsettings);
   if (sce->toolsettings) {
+    BLO_read_data_address(reader, &sce->toolsettings->unified_channels);
+
+    BLO_read_data_address(reader, &sce->toolsettings->unified_properties);
+    IDP_BlendDataRead(reader, &sce->toolsettings->unified_properties);
+
+    if (sce->toolsettings->unified_channels) {
+      BKE_brush_channelset_blend_read(sce->toolsettings->unified_channels, reader);
+    }
+
+    BKE_brush_channelset_toolsettings_init(sce->toolsettings);
 
     /* Reset last_location and last_hit, so they are not remembered across sessions. In some files
      * these are also NaN, which could lead to crashes in painting. */
diff --git a/source/blender/makesrna/intern/rna_brush_channels.c b/source/blender/makesrna/i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list