[Bf-blender-cvs] [45b03320348] temp-sculpt-brush-channel: temp-sculpt-brush-channel: Flesh out rna backend a bit
Joseph Eagar
noreply at git.blender.org
Mon Aug 8 11:36:33 CEST 2022
Commit: 45b03320348808dd002fce3b26423815fa46d03c
Author: Joseph Eagar
Date: Fri Aug 5 16:36:00 2022 -0700
Branches: temp-sculpt-brush-channel
https://developer.blender.org/rB45b03320348808dd002fce3b26423815fa46d03c
temp-sculpt-brush-channel: Flesh out rna backend a bit
===================================================================
M source/blender/blenkernel/BKE_brush_channel.h
M source/blender/blenkernel/intern/brush_channel.cc
M source/blender/makesdna/DNA_brush_channel_types.h
M source/blender/makesdna/DNA_brush_enums.h
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_brush.c
M source/blender/makesrna/intern/rna_brush_channels.c
M source/blender/makesrna/intern/rna_internal.h
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 44ecc85ffca..825e5269fdd 100644
--- a/source/blender/blenkernel/BKE_brush_channel.h
+++ b/source/blender/blenkernel/BKE_brush_channel.h
@@ -61,6 +61,7 @@ struct BlendExpander;
struct Brush;
struct Sculpt;
struct LibraryForeachIDData;
+struct ToolSettings;
struct UnifiedPaintSettings;
#define make_builtin_ch_name(idname) BRUSH_BUILTIN_##idname
@@ -170,6 +171,12 @@ void _BKE_brush_channelset_float_set(struct Brush *br,
BrushChannelSet *BKE_brush_channelset_copy(BrushChannelSet *chset);
+/* Create a (copied) final brush channel set with all inheritance and unified flags
+ and input mappings taken into account. */
+BrushChannelSet *BKE_brush_channelset_create_final(struct Brush *brush,
+ struct ToolSettings *tool_settings,
+ BrushMappingData *mapdata);
+
#define BKE_brush_channelset_float_set(br, scene, chset, channel, f, set_rna) \
_BKE_brush_channelset_float_set(br, scene, chset, make_builtin_ch_name(channel), f, set_rna)
@@ -197,6 +204,11 @@ BLI_INLINE const char *BKE_brush_mapping_type_to_typename(eBrushMappingType type
const char *BKE_brush_channel_category_get(BrushChannel *ch);
const void BKE_brush_channel_category_set(BrushChannel *ch, const char *category);
+bool BKE_brush_channel_inherits(struct Brush *brush,
+ struct ToolSettings *tool_settings,
+ BrushChannel *ch);
+BrushChannelSet *BKE_brush_channelset_get_final(struct Brush *brush,
+ struct ToolSettings *tool_settings);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/brush_channel.cc b/source/blender/blenkernel/intern/brush_channel.cc
index 3c37af49349..bb5e9a35bd6 100644
--- a/source/blender/blenkernel/intern/brush_channel.cc
+++ b/source/blender/blenkernel/intern/brush_channel.cc
@@ -27,6 +27,8 @@
#include "BKE_brush.h"
#include "BKE_brush_channel.h"
#include "BKE_colortools.h"
+#include "BKE_idprop.h"
+#include "BKE_idprop.hh"
#include "BKE_paint.h"
#include "BLO_read_write.h"
@@ -289,11 +291,11 @@ void _brush_channel_ensure_value(Brush *brush,
BrushChannelSet *chset,
const char *idname)
{
- Sculpt *sd = scene->toolsettings->sculpt;
+ ToolSettings *tool_settings = scene->toolsettings;
BrushChannel *dest_ch = _BKE_brush_channelset_lookup(chset, idname);
BrushChannel *brush_ch = _BKE_brush_channelset_lookup(brush->channels, idname);
- BrushChannel *scene_ch = _BKE_brush_channelset_lookup(sd->channels, idname);
+ BrushChannel *scene_ch = _BKE_brush_channelset_lookup(tool_settings->unified_channels, idname);
if (!(dest_ch->flag & BRUSH_CHANNEL_NEEDS_EVALUATE)) {
return;
@@ -304,20 +306,25 @@ void _brush_channel_ensure_value(Brush *brush,
ID *id;
const char *rnaname = dest_ch->idname;
+ bool inherit = BKE_brush_channel_inherits(brush, scene->toolsettings, dest_ch);
- if (brush_ch->flag & BRUSH_CHANNEL_INHERIT) {
+ if (!inherit) {
path = "";
id = &brush->id;
srna = RNA_struct_find("Brush");
}
else {
- path = "tool_settings.unified_paint_settings.";
+ path = "tool_settings.unified_properties[\"";
id = &scene->id;
srna = RNA_struct_find("Scene");
}
path += string(rnaname);
+ if (inherit) {
+ path += string("\"]");
+ }
+
dest_ch->flag &= ~BRUSH_CHANNEL_NEEDS_EVALUATE;
PointerRNA ptr, ptr2;
PropertyRNA *prop = nullptr;
@@ -485,6 +492,13 @@ void BKE_brush_mapping_copy_data(BrushMapping *dest, BrushMapping *src)
}
}
+void BKE_brush_mapping_free_data(BrushMapping *mp)
+{
+ if (mp->curve.curve) {
+ BKE_curvemapping_free(mp->curve.curve);
+ }
+}
+
void BKE_brush_channel_copy_data(BrushChannel *dest, BrushChannel *src)
{
*dest = *src;
@@ -545,4 +559,100 @@ extern "C" void BKE_brush_channelset_blend_read(BrushChannelSet *chset, BlendDat
}
}
}
+
+extern "C" bool BKE_brush_channel_inherits(Brush *brush,
+ ToolSettings *tool_settings,
+ BrushChannel *ch)
+{
+ BrushChannel *scene_ch = _BKE_brush_channelset_lookup(tool_settings->unified_channels,
+ ch->idname);
+
+ if (!scene_ch) {
+ return false;
+ }
+
+ if (ch->flag & BRUSH_CHANNEL_INHERIT) {
+ return true;
+ }
+
+ if (scene_ch->flag & BRUSH_CHANNEL_FORCE_INHERIT) {
+ return !(ch->flag & BRUSH_CHANNEL_IGNORE_FORCE_INHERIT);
+ }
+
+ return false;
+}
+
+BrushChannelSet *BKE_brush_channelset_create_final(Brush *brush,
+ ToolSettings *tool_settings,
+ BrushMappingData *mapdata)
+{
+ BrushChannelSet *chset = BKE_brush_channelset_copy(brush->channels);
+
+ LISTBASE_FOREACH (BrushChannel *, ch, &chset->channels) {
+ BrushChannel *ch1 = _BKE_brush_channelset_lookup(brush->channels, ch->idname);
+ BrushChannel *ch2 = _BKE_brush_channelset_lookup(tool_settings->unified_channels, ch->idname);
+ bool inherit = BKE_brush_channel_inherits(brush, tool_settings, ch);
+
+ if (inherit) {
+ BKE_brush_channel_copy_data(ch, ch2);
+ }
+
+ for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
+ BrushMapping *mp1 = ch1->mappings + i;
+ BrushMapping *mp2 = ch2->mappings + i;
+
+ if ((mp1->flag & BRUSH_MAPPING_INHERIT_NEVER) && inherit) {
+ BKE_brush_mapping_free_data(ch->mappings + i);
+ BKE_brush_mapping_copy_data(ch->mappings + i, mp1);
+ }
+ else if ((mp1->flag & BRUSH_MAPPING_INHERIT_ALWAYS) && !inherit) {
+ BKE_brush_mapping_free_data(ch->mappings + i);
+ BKE_brush_mapping_copy_data(ch->mappings + i, mp2);
+ }
+ }
+ }
+
+ return chset;
+}
+
+void BKE_brush_channelset_toolsettings_init(ToolSettings *ts)
+{
+ if (!ts->unified_properties) {
+ ts->unified_properties = IDP_New(IDP_GROUP, nullptr, "group");
+ }
+
+ if (!ts->unified_channels) {
+ ts->unified_channels = BKE_brush_channelset_create();
+ }
+
+ for (const BrushChannelType &type : builtin_channels.values()) {
+ _BKE_brush_channelset_ensure(ts->unified_channels, type.idname);
+ }
+
+ LISTBASE_FOREACH (BrushChannel *, ch, &ts->unified_channels) {
+ IDProperty *idprop = IDP_GetPropertyFromGroup(ts->unified_properties, ch->idname);
+
+ if (!idprop) {
+ IDPropertyTemplate tmpl;
+ IDPropertyType type;
+
+ switch (ch->type) {
+ case BRUSH_CHANNEL_TYPE_FLOAT:
+ tmpl.f = ch->fvalue;
+ type = IDP_FLOAT;
+ break;
+ case BRUSH_CHANNEL_TYPE_INT:
+ case BRUSH_CHANNEL_TYPE_ENUM:
+ case BRUSH_CHANNEL_TYPE_BITMASK:
+ case BRUSH_CHANNEL_TYPE_BOOL:
+ tmpl.i = ch->ivalue;
+ type = IDP_INT;
+ break;
+ }
+
+ prop = IDP_New(type, &tmpl, ch->idname);
+ }
+ }
+}
+
} // namespace blender
diff --git a/source/blender/makesdna/DNA_brush_channel_types.h b/source/blender/makesdna/DNA_brush_channel_types.h
index 93b491c3933..d11de55f56e 100644
--- a/source/blender/makesdna/DNA_brush_channel_types.h
+++ b/source/blender/makesdna/DNA_brush_channel_types.h
@@ -176,6 +176,12 @@ typedef enum eBrushChannelFlag {
BRUSH_CHANNEL_UI_EXPANDED = 1 << 3,
BRUSH_CHANNEL_APPLY_MAPPING_TO_ALPHA = 1 << 4,
BRUSH_CHANNEL_NEEDS_EVALUATE = 1 << 5,
+
+ /* Set in scene channels; forces inheritance on brush properties. */
+ BRUSH_CHANNEL_FORCE_INHERIT = 1 << 6,
+
+ /* Set in brush channels; ignores BRUSH_CHANNEL_FORCE_INHERIT. */
+ BRUSH_CHANNEL_IGNORE_FORCE_INHERIT = 1 << 7,
} eBrushChannelFlag;
typedef enum eBrushChannelUIFlag {
diff --git a/source/blender/makesdna/DNA_brush_enums.h b/source/blender/makesdna/DNA_brush_enums.h
index adda23c26f2..f53b41642c2 100644
--- a/source/blender/makesdna/DNA_brush_enums.h
+++ b/source/blender/makesdna/DNA_brush_enums.h
@@ -452,6 +452,7 @@ typedef enum eBrushSculptTool {
SCULPT_TOOL_BOUNDARY = 30,
SCULPT_TOOL_DISPLACEMENT_ERASER = 31,
SCULPT_TOOL_DISPLACEMENT_SMEAR = 32,
+ SCULPT_TOOL_MAX,
} eBrushSculptTool;
/** #Brush.uv_sculpt_tool */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index f47782a653b..678633dbc2c 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1018,7 +1018,6 @@ typedef struct Sculpt {
char _pad[4];
struct Object *gravity_object;
- struct BrushChannelSet *channels;
} Sculpt;
typedef struct CurvesSculpt {
@@ -1558,6 +1557,8 @@ typedef struct ToolSettings {
/* Unified Paint Settings */
struct UnifiedPaintSettings unified_paint_settings;
+ struct BrushChannelSet *unified_channels;
+ IDProperty *unified_properties;
struct CurvePaintSettings curve_paint_settings;
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 9d027b12efa..7ce33f2f786 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -3431,7 +3431,7 @@ static void rna_def_brush(BlenderRNA *brna)
// RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_override_flag(
prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY | PROPOVERRIDE_LIBRARY_INSERTION);
- RNA_def_brush_channelset(brna, prop, "Brush");
+ RNA_def_brush_channelset(brna, prop, "channels", "Brush");
/* gradient source */
prop = RNA_def_property(srna, "gradient_stroke_mode", PROP_ENUM, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_brush_channels.c b/source/blender/makesrna/intern/rna_brush_channels.c
index 0b57259c246..7f25679bc23 100644
--- a/source/blender/makesrna/intern/rna_brush_channels.c
+++ b/source/blender/makesrna/intern/rna_brush_channels.c
@@ -81,11 +81,11 @@ BrushChannelSet *rna_BrushChannelSet_get_set(struct PointerRNA *ptr)
case ID_SCE: {
Scene *scene = (Scene *)id;
- if (!scene->toolsettings || !scene->toolsettings->sculpt) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list