Sculpt: Unnest channels.channels in RNA

* BrushChannelSet is now a pure collection. This
  eliminated the annoying brush.channels.channels
  paths, and also makes library overriding work.
* Now sure I've done this correctly. Struct extended
  collection properties are a bit confusing.
This commit is contained in:
Joseph Eagar 2021-09-24 18:47:24 -07:00
parent 23f952d7d7
commit 430e7efd09
18 changed files with 286 additions and 96 deletions

View File

@ -4301,8 +4301,8 @@ def km_curve(params):
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"
channels_path = brush_path + ".channels"
unified = "tool_settings." + paint + ".channels"
rotation = 'mask_texture_slot_angle' if secondary_rotation else 'texture_slot_angle'
return {

View File

@ -127,25 +127,25 @@ class UnifiedPaintPanel:
@staticmethod
def get_channel(context, brush, prop_name, toolsettings_only=False):
ch = brush.channels.channels[prop_name]
ch = brush.channels[prop_name]
if ch.inherit or toolsettings_only:
sd = context.tool_settings.sculpt
#ensure channel exists in tool settings channel set
sd.channels.ensure(ch)
ch = sd.channels.channels[prop_name]
ch = sd.channels[prop_name]
return ch
@staticmethod
def get_channel_value(context, brush, prop_name, toolsettings_only=False):
ch = brush.channels.channels[prop_name]
ch = brush.channels[prop_name]
if ch.inherit or toolsettings_only:
sd = context.tool_settings.sculpt
#ensure channel exists in tool settings channel set
sd.channels.ensure(ch)
ch = sd.channels.channels[prop_name]
ch = sd.channels[prop_name]
if ch.type == "FLOAT":
return ch.float_value
@ -176,14 +176,14 @@ class UnifiedPaintPanel:
elif prop_name == "use_locked_size":
prop_name = "radius_unit"
ch = brush.channels.channels[prop_name]
ch = brush.channels[prop_name]
#dynamically switch to unprojected radius if necassary
if prop_name == "radius":
size_mode = brush.channels.channels["radius_unit"].enum_value == "SCENE"
size_mode = brush.channels["radius_unit"].enum_value == "SCENE"
if size_mode:
prop_name = "unprojected_radius"
ch = brush.channels.channels[prop_name]
ch = brush.channels[prop_name]
finalch = ch
@ -236,14 +236,14 @@ class UnifiedPaintPanel:
#ensure channel exists in tool settings channel set
sd.channels.ensure(ch)
finalch = sd.channels.channels[prop_name]
finalch = sd.channels[prop_name]
if ch.mappings["PRESSURE"].inherit:
pressurech = finalch
is_toolset = True
path = "tool_settings.sculpt.channels.channels[\"%s\"]" % ch.idname
path = "tool_settings.sculpt.channels[\"%s\"]" % ch.idname
else:
path = "tool_settings.sculpt.brush.channels.channels[\"%s\"]" % ch.idname
path = "tool_settings.sculpt.brush.channels[\"%s\"]" % ch.idname
if show_reorder:
props = row.operator("brush.change_channel_order", text="", icon="TRIA_UP")
@ -388,7 +388,7 @@ class UnifiedPaintPanel:
if prop_name in channel_name_map:
prop_name = channel_name_map[prop_name]
if prop_name in brush.channels.channels:
if prop_name in brush.channels:
# def channel_unified(layout, context, brush, prop_name, icon='NONE', pressure=True, text=None, slider=False, header=False):
return UnifiedPaintPanel.channel_unified(layout, context, brush, prop_name, icon=icon, text=text, slider=slider, header=header)
@ -833,10 +833,22 @@ def brush_settings(layout, context, brush, popover=False):
sculpt_tool = brush.sculpt_tool
# normal_radius_factor
layout.prop(brush, "normal_radius_factor", slider=True)
UnifiedPaintPanel.prop_unified(
layout,
context,
brush,
"normal_radius_factor",
slider=True,
)
if context.preferences.experimental.use_sculpt_tools_tilt and capabilities.has_tilt:
layout.prop(brush, "tilt_strength_factor", slider=True)
UnifiedPaintPanel.prop_unified(
layout,
context,
brush,
"tilt_strength_factor",
slider=True,
)
UnifiedPaintPanel.prop_unified(
layout,
@ -855,7 +867,7 @@ def brush_settings(layout, context, brush, popover=False):
# auto_smooth_factor and use_inverse_smooth_pressure
if capabilities.has_auto_smooth:
box = layout.box().column() #.column() is a bit more compact
box = layout.column() #.column() is a bit more compact
UnifiedPaintPanel.prop_unified(
box,
@ -925,7 +937,7 @@ def brush_settings(layout, context, brush, popover=False):
capabilities.has_topology_rake and
context.sculpt_object.use_dynamic_topology_sculpting
):
box = layout.box().column() #.column() is a bit more compact
box = layout.column() #.column() is a bit more compact
#box.prop(brush, "topology_rake_factor", slider=True)
UnifiedPaintPanel.prop_unified(
@ -938,7 +950,7 @@ def brush_settings(layout, context, brush, popover=False):
)
box.prop(brush, "use_custom_topology_rake_spacing", text="Custom Spacing")
if brush.channels.channels["topology_rake_use_spacing"].bool_value:
if brush.channels["topology_rake_use_spacing"].bool_value:
UnifiedPaintPanel.prop_unified(
box,
context,
@ -1226,7 +1238,7 @@ def brush_settings(layout, context, brush, popover=False):
#col.prop(brush, "use_weighted_smooth")
#col.prop(brush, "preserve_faceset_boundary")
if brush.channels.channels["preserve_faceset_boundary"].bool_value:
if brush.channels["preserve_faceset_boundary"].bool_value:
UnifiedPaintPanel.channel_unified(
layout,
context,
@ -1426,7 +1438,7 @@ class ReorderBrushChannel(Operator):
brush = ts.sculpt.brush
channels = brush.channels.channels
channels = brush.channels
if self.channel not in channels:
print("bad channel ", self.channel)
return {'CANCELLED'}
@ -1465,7 +1477,7 @@ class ReorderBrushChannel(Operator):
return {'FINISHED'}
def brush_settings_channels(layout, context, brush, ui_editing=False, popover=False, filterkey="show_in_workspace"):
channels = get_ui_channels(brush.channels.channels, [filterkey])
channels = get_ui_channels(brush.channels, [filterkey])
for ch in channels:
UnifiedPaintPanel.channel_unified(

View File

@ -833,7 +833,7 @@ class VIEW3D_PT_sculpt_dyntopo_advanced(Panel, View3DPaintPanel):
brush = context.tool_settings.sculpt.brush
ch = brush.channels.channels["dyntopo_mode"]
ch = brush.channels["dyntopo_mode"]
if ch.inherit:
row = layout.row()
@ -959,7 +959,7 @@ class SCULPT_OT_set_dyntopo_mode (Operator):
def set_dyntopo_mode_button(layout, context):
brush = context.tool_settings.sculpt.brush
ch = brush.channels.channels["dyntopo_mode"]
ch = brush.channels["dyntopo_mode"]
finalch = UnifiedPaintPanel.get_channel(context, brush, "dyntopo_mode")
if "SUBDIVIDE" in finalch.flags_value and "COLLAPSE" in finalch.flags_value:

View File

@ -50,6 +50,9 @@ This should completely replace UnifiedPaintSettings.
struct BrushChannel;
struct BlendWriter;
struct BlendDataReader;
struct BlendLibReader;
struct ID;
struct BlendExpander;
struct Brush;
struct Sculpt;
@ -264,6 +267,14 @@ void BKE_builtin_commandlist_create(struct Brush *brush,
BrushMappingData *map_data); // map_data may be NULL
void BKE_brush_channelset_read(struct BlendDataReader *reader, BrushChannelSet *cset);
void BKE_brush_channelset_write(struct BlendWriter *writer, BrushChannelSet *cset);
void BKE_brush_channelset_read_lib(struct BlendLibReader *reader,
struct ID *id,
BrushChannelSet *chset);
void BKE_brush_channelset_expand(struct BlendExpander *expander,
struct ID *id,
BrushChannelSet *chset);
void BKE_brush_channelset_foreach_id(struct LibraryForeachIDData *data, BrushChannelSet *chset);
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);

View File

@ -78,6 +78,10 @@ static void brush_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
brush_dst->icon_imbuf = IMB_dupImBuf(brush_src->icon_imbuf);
}
if (brush_src->channels) {
brush_dst->channels = BKE_brush_channelset_copy(brush_src->channels);
}
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
BKE_previewimg_id_copy(&brush_dst->id, &brush_src->id);
}
@ -224,6 +228,10 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
}
BKE_texture_mtex_foreach_id(data, &brush->mtex);
BKE_texture_mtex_foreach_id(data, &brush->mask_mtex);
if (brush->channels) {
BKE_brush_channelset_foreach_id(data, brush->channels);
}
}
static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
@ -456,6 +464,10 @@ static void brush_blend_read_lib(BlendLibReader *reader, ID *id)
brush->gpencil_settings->material = NULL;
}
}
if (brush->channels) {
BKE_brush_channelset_read_lib(reader, id, brush->channels);
}
}
static void brush_blend_read_expand(BlendExpander *expander, ID *id)
@ -468,6 +480,10 @@ static void brush_blend_read_expand(BlendExpander *expander, ID *id)
if (brush->gpencil_settings != NULL) {
BLO_expand(expander, brush->gpencil_settings->material);
}
if (brush->channels) {
BKE_brush_channelset_expand(expander, id, brush->channels);
}
}
static int brush_undo_preserve_cb(LibraryIDLinkCallbackData *cb_data)

View File

@ -341,6 +341,7 @@ MAKE_ENUM_EX(radius_unit, "Radius Unit", "Measure brush size relative to the vi
{BRUSH_LOCK_SIZE, "SCENE", "NONE", "Scene", "Measure brush size relative to the scene"},
{-1}
}), BRUSH_CHANNEL_SHOW_IN_WORKSPACE)
MAKE_FLOAT(tilt_strength_factor, "Tilt Strength", "How much the tilt of the pen will affect the brush", 0.0f, 0.0f, 1.0f)
/* clang-format on */
#if defined(BRUSH_CHANNEL_DEFINE_TYPES) || defined(BRUSH_CHANNEL_DEFINE_EXTERNAL)

View File

@ -32,6 +32,9 @@
#include "BKE_context.h"
#include "BKE_curvemapping_cache.h"
#include "BKE_curveprofile.h"
#include "BKE_lib_override.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_paint.h"
@ -1596,6 +1599,18 @@ void BKE_builtin_commandlist_create(Brush *brush,
BKE_brush_commandset_inherit_all_mappings(cmd->params);
}
void BKE_brush_channelset_read_lib(BlendLibReader *reader, ID *id, BrushChannelSet *chset)
{
}
void BKE_brush_channelset_expand(BlendExpander *expander, ID *id, BrushChannelSet *chset)
{
}
void BKE_brush_channelset_foreach_id(LibraryForeachIDData *data, BrushChannelSet *chset)
{
}
void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *chset)
{
BLO_read_list(reader, &chset->channels);

View File

@ -291,6 +291,7 @@ static BrushSettingsMap brush_settings_map[] = {
DEF(boundary_deform_type, boundary_deform_type, INT, INT)
DEF(boundary_falloff_type, boundary_falloff_type, INT, INT)
DEF(deform_target, deform_target, INT, INT)
DEF(tilt_strength_factor, tilt_strength_factor, FLOAT, FLOAT)
};
static const int brush_settings_map_len = ARRAY_SIZE(brush_settings_map);
@ -723,6 +724,8 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
ADDCH(radius_unit);
ADDCH(unprojected_radius);
ADDCH(tilt_strength_factor);
ADDCH(autosmooth);
ADDCH(autosmooth_radius_scale);
ADDCH(autosmooth_spacing);
@ -1117,6 +1120,7 @@ void BKE_brush_check_toolsettings(Sculpt *sd)
ADDCH(radius_unit);
ADDCH(unprojected_radius);
ADDCH(tilt_strength_factor);
ADDCH(automasking_boundary_edges_propagation_steps);
ADDCH(concave_mask_factor);
ADDCH(automasking);

View File

@ -1854,7 +1854,7 @@ BLI_INLINE IDOverrideLibraryRuntime *override_library_rna_path_runtime_ensure(
}
/* We only build override GHash on request. */
BLI_INLINE GHash *override_library_rna_path_mapping_ensure(IDOverrideLibrary *override)
ATTR_NO_OPT BLI_INLINE GHash *override_library_rna_path_mapping_ensure(IDOverrideLibrary *override)
{
IDOverrideLibraryRuntime *override_runtime = override_library_rna_path_runtime_ensure(override);
if (override_runtime->rna_path_to_override_properties == NULL) {

View File

@ -645,7 +645,12 @@ static void scene_foreach_toolsettings(LibraryForeachIDData *data,
reader,
toolsett_old->sculpt->gravity_object,
IDWALK_CB_NOP);
if (toolsett->sculpt->channels) {
BKE_brush_channelset_foreach_id(data, toolsett->sculpt->channels);
}
}
if (toolsett->uvsculpt) {
scene_foreach_paint(
data, &toolsett->uvsculpt->paint, do_undo_restore, reader, &toolsett_old->uvsculpt->paint);
@ -1296,6 +1301,10 @@ static void scene_blend_read_lib(BlendLibReader *reader, ID *id)
BKE_paint_blend_read_lib(reader, sce, &sce->toolsettings->imapaint.paint);
if (sce->toolsettings->sculpt) {
BKE_paint_blend_read_lib(reader, sce, &sce->toolsettings->sculpt->paint);
if (sce->toolsettings->sculpt->channels) {
BKE_brush_channelset_read_lib(reader, id, sce->toolsettings->sculpt->channels);
}
}
if (sce->toolsettings->vpaint) {
BKE_paint_blend_read_lib(reader, sce, &sce->toolsettings->vpaint->paint);
@ -1423,6 +1432,10 @@ static void scene_blend_read_expand(BlendExpander *expander, ID *id)
{
Scene *sce = (Scene *)id;
if (sce->toolsettings && sce->toolsettings->sculpt && sce->toolsettings->sculpt->channels) {
BKE_brush_channelset_expand(expander, id, sce->toolsettings->sculpt->channels);
}
LISTBASE_FOREACH (Base *, base_legacy, &sce->base) {
BLO_expand(expander, base_legacy->object);
}

View File

@ -47,11 +47,11 @@ const char *sculpt_keymap_fix_intern(const char *str)
type = "inherit";
}
// tool_settings.sculpt.channels.channels["strength"].factor_value
// tool_settings.sculpt.channels["strength"].factor_value
basic_string sub1 = R"'(tool_settings.sculpt.brush.channels.channels["$1"].)'" + type;
basic_string sub2 = R"'(tool_settings.sculpt.channels.channels["$1"].)'" + type;
basic_string sub3 = R"'(tool_settings.sculpt.brush.channels.channels["$1"].)'" + type;
basic_string sub1 = R"'(tool_settings.sculpt.brush.channels["$1"].)'" + type;
basic_string sub2 = R"'(tool_settings.sculpt.channels["$1"].)'" + type;
basic_string sub3 = R"'(tool_settings.sculpt.brush.channels["$1"].)'" + type;
// sub += type;
@ -65,6 +65,8 @@ const char *sculpt_keymap_fix_intern(const char *str)
repl = std::regex_replace(repl, pat2, sub2);
}
repl = regex_replace(repl, regex(R"'(\.channels\.channels)'"), ".channels");
const char *out = repl.c_str();
size_t len = (size_t)strlen(out);
@ -99,7 +101,7 @@ static void test_regexp()
const char *sculpt_keymap_fix(const char *str)
{
test_regexp();
// test_regexp();
return sculpt_keymap_fix_intern(str);
}

View File

@ -341,22 +341,6 @@ static void do_version_select_mouse(UserDef *userdef, wmKeyMapItem *kmi)
}
}
/* clang-format off */
static const char *sculpt_replacements[][4] = {
{"tool_settings.sculpt.brush.", "tool_settings.sculpt.brush.channels.channels[\"PROP\"].float_value"},
{"tool_settings.unified_paint_settings.", "tool_settings.sculpt.channels.channels[\"PROP\"].float_value"},
{"tool_settings.unified_paint_settings.use_unified_size", "tool_settings.sculpt.brush.channels.channels[\"PROP\"].inherit"},
};
static const char *sculpt_prop_map[][2] = {
{"size", "radius"},
{"use_unified_size", "radius"},
{"use_unified_strength", "strength"}
};
/* clang-format on */
static int tot_sculpt_prop_map = ARRAY_SIZE(sculpt_prop_map);
static int tot_sculpt_replacements = ARRAY_SIZE(sculpt_replacements);
extern char *sculpt_keymap_fix(const char *str);
static void fix_radial_control_path(IDProperty *prop, void *userdata)

View File

@ -330,15 +330,15 @@ bool RNA_struct_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACo
* \note When there is no equality,
* but we cannot determine an order (greater than/lesser than), we return 1.
*/
static int rna_property_override_diff(Main *bmain,
PropertyRNAOrID *prop_a,
PropertyRNAOrID *prop_b,
const char *rna_path,
const size_t rna_path_len,
eRNACompareMode mode,
IDOverrideLibrary *override,
const eRNAOverrideMatch flags,
eRNAOverrideMatchResult *r_report_flags)
ATTR_NO_OPT static int rna_property_override_diff(Main *bmain,
PropertyRNAOrID *prop_a,
PropertyRNAOrID *prop_b,
const char *rna_path,
const size_t rna_path_len,
eRNACompareMode mode,
IDOverrideLibrary *override,
const eRNAOverrideMatch flags,
eRNAOverrideMatchResult *r_report_flags)
{
BLI_assert(!ELEM(NULL, prop_a, prop_b));
@ -640,14 +640,15 @@ static bool rna_property_override_operation_apply(Main *bmain,
*
* \return True if _resulting_ \a ptr_local does match \a ptr_reference.
*/
bool RNA_struct_override_matches(Main *bmain,
PointerRNA *ptr_local,
PointerRNA *ptr_reference,
const char *root_path,
const size_t root_path_len,
IDOverrideLibrary *override,
const eRNAOverrideMatch flags,
eRNAOverrideMatchResult *r_report_flags)
#include "stdio.h"
ATTR_NO_OPT bool RNA_struct_override_matches(Main *bmain,
PointerRNA *ptr_local,
PointerRNA *ptr_reference,
const char *root_path,
const size_t root_path_len,
IDOverrideLibrary *override,
const eRNAOverrideMatch flags,
eRNAOverrideMatchResult *r_report_flags)
{
CollectionPropertyIterator iter;
PropertyRNA *iterprop;
@ -711,6 +712,10 @@ bool RNA_struct_override_matches(Main *bmain,
rna_property_rna_or_id_get(rawprop, ptr_local, &prop_local);
rna_property_rna_or_id_get(rawprop, ptr_reference, &prop_reference);
if (STREQ(prop_local.identifier, "channels")) {
printf("break\n");
}
BLI_assert(prop_local.rnaprop != NULL);
BLI_assert(prop_local.rnaprop == prop_reference.rnaprop);
BLI_assert(prop_local.is_idprop == prop_reference.is_idprop);
@ -788,6 +793,10 @@ bool RNA_struct_override_matches(Main *bmain,
continue;
}
if (STRPREFIX(rna_path, "channels[\"autosmooth\"].factor_value")) {
printf("break\n");
}
CLOG_INFO(&LOG, 5, "Override Checking %s", rna_path);
IDOverrideLibraryProperty *op = BKE_lib_override_library_property_find(override, rna_path);

View File

@ -3712,11 +3712,15 @@ static void rna_def_brush(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Gradient", "");
RNA_def_property_update(prop, 0, "rna_Brush_update");
prop = RNA_def_property(srna, "channels", PROP_POINTER, 0);
RNA_def_property_pointer_sdna(prop, NULL, "channels");
RNA_def_property_struct_type(prop, "BrushChannelSet");
prop = RNA_def_property(srna, "channels", PROP_COLLECTION, 0);
RNA_def_property_collection_sdna(prop, NULL, "channels", NULL);
RNA_def_property_struct_type(prop, "BrushChannel");
RNA_def_property_ui_text(prop, "Channels", "");
RNA_def_property_update(prop, 0, "rna_Brush_update");
// 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");
/* gradient source */
prop = RNA_def_property(srna, "gradient_stroke_mode", PROP_ENUM, PROP_NONE);

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include "DNA_ID_enums.h"
#include "DNA_brush_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_listBase.h"
@ -51,9 +52,40 @@ static EnumPropertyItem null_enum[2] = {{0, "null", ICON_NONE, "null"}, {0, NULL
#ifdef RNA_RUNTIME
int rna_BrushChannelSet_channels_begin(CollectionPropertyIterator *iter, struct PointerRNA *ptr)
# include "RNA_access.h"
BrushChannelSet *rna_BrushChannelSet_get_set(struct PointerRNA *ptr)
{
BrushChannelSet *chset = ptr->data;
BrushChannelSet *chset = NULL;
ID *id = ptr->owner_id;
switch (GS(id->name)) {
case ID_BR:
chset = ((Brush *)id)->channels;
break;
case ID_SCE: {
Scene *scene = (Scene *)id;
if (!scene->toolsettings || !scene->toolsettings->sculpt) {
return NULL;
}
chset = scene->toolsettings->sculpt->channels;
break;
}
}
return chset;
}
ATTR_NO_OPT int rna_BrushChannelSet_channels_begin(CollectionPropertyIterator *iter,
struct PointerRNA *ptr)
{
BrushChannelSet *chset = rna_BrushChannelSet_get_set(ptr);
if (!chset) {
return 0;
}
rna_iterator_listbase_begin(iter, &chset->channels, NULL);
@ -64,7 +96,8 @@ int rna_BrushChannelSet_channels_assignint(struct PointerRNA *ptr,
int key,
const struct PointerRNA *assign_ptr)
{
BrushChannelSet *chset = ptr->data;
BrushChannelSet *chset = rna_BrushChannelSet_get_set(ptr);
BrushChannel *src = assign_ptr->data;
BrushChannel *ch = BLI_findlink(&chset->channels, key);
@ -345,7 +378,7 @@ static void rna_BrushChannel_enum_items_begin(CollectionPropertyIterator *iter,
printf("%s: channel '%s' had no definition\n", __func__, ch->idname);
}
else {
printf("%s: channel '%s' is not an enum/bitmask\n", __func__, ch->idname);
// printf("%s: channel '%s' is not an enum/bitmask\n", __func__, ch->idname);
}
item = null_enum;
@ -368,6 +401,48 @@ static void rna_BrushChannel_enum_items_begin(CollectionPropertyIterator *iter,
iter, (void *)item, sizeof(EnumPropertyItem), totitem, false, rna_enum_check_separator);
}
char *rna_BrushChannel_rnapath(PointerRNA *ptr)
{
BrushChannel *ch = (BrushChannel *)ptr->data;
char buf[512];
if (!ptr->owner_id) {
return NULL;
}
if (GS(ptr->owner_id->name) == ID_BR) {
return BLI_sprintfN("channels[\"%s\"]", ch->idname);
}
else if (GS(ptr->owner_id->name) == ID_SCE) {
return BLI_sprintfN("tool_settings.sculpt.channels[\"%s\"]", ch->idname);
}
else {
return NULL;
}
}
ATTR_NO_OPT void rna_BrushChannelSet_ensure(ID *id, BrushChannel *channel)
{
PointerRNA ptr;
ptr.owner_id = id;
ptr.data = NULL;
ptr.type = NULL;
BrushChannelSet *chset = rna_BrushChannelSet_get_set(&ptr);
if (chset) {
BKE_brush_channelset_ensure_existing(chset, channel);
}
}
ATTR_NO_OPT int rna_BrushChannelSet_length(PointerRNA *ptr)
{
BrushChannelSet *chset = rna_BrushChannelSet_get_set(ptr);
// BrushChannelSet *chset = (BrushChannelSet *)ptr->data;
return chset->totchannel;
}
#endif
static EnumPropertyItem mapping_type_items[] = {
@ -478,6 +553,7 @@ void RNA_def_brush_channel(BlenderRNA *brna)
srna = RNA_def_struct(brna, "BrushChannel", NULL);
RNA_def_struct_sdna(srna, "BrushChannel");
RNA_def_struct_ui_text(srna, "Brush Channel", "Brush Channel");
RNA_def_struct_path_func(srna, "rna_BrushChannel_rnapath");
prop = RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, "BrushChannel", "idname");
@ -517,64 +593,64 @@ void RNA_def_brush_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "float_value", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, "BrushChannel", "fvalue");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Value", "Current value");
RNA_def_property_float_funcs(prop,
"rna_BrushChannel_get_value",
"rna_BrushChannel_set_value",
"rna_BrushChannel_value_range");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
// XXX hack warning: these next two are duplicates of above
// to get different subtypes
prop = RNA_def_property(srna, "factor_value", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, "BrushChannel", "fvalue");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Value", "Current value");
RNA_def_property_float_funcs(prop,
"rna_BrushChannel_get_value",
"rna_BrushChannel_set_value",
"rna_BrushChannel_value_range");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "percent_value", PROP_FLOAT, PROP_PERCENTAGE);
RNA_def_property_float_sdna(prop, "BrushChannel", "fvalue");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Value", "Current value");
RNA_def_property_float_funcs(prop,
"rna_BrushChannel_get_value",
"rna_BrushChannel_set_value",
"rna_BrushChannel_value_range");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "inherit", PROP_BOOLEAN, PROP_NONE);
// RNA_def_property_boolean_sdna(prop, "BrushChannel", "flag", BRUSH_CHANNEL_INHERIT);
RNA_def_property_ui_text(prop, "Inherit", "Inherit from scene defaults");
RNA_def_property_boolean_funcs(
prop, "rna_BrushChannel_inherit_get", "rna_BrushChannel_inherit_set");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Inherit", "Inherit from scene defaults");
prop = RNA_def_property(srna, "show_in_header", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, "BrushChannel", "flag", BRUSH_CHANNEL_SHOW_IN_HEADER);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "In Header", "Show in header");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "show_in_workspace", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, "BrushChannel", "flag", BRUSH_CHANNEL_SHOW_IN_WORKSPACE);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "In Workspace", "Show in workspace");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "is_color", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, "BrushChannel", "flag", BRUSH_CHANNEL_COLOR);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Is Color", "Is this channel a color");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "ui_expanded", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, "BrushChannel", "flag", BRUSH_CHANNEL_UI_EXPANDED);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Expanded", "View advanced properties");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "inherit_if_unset", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, "BrushChannel", "flag", BRUSH_CHANNEL_INHERIT_IF_UNSET);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Combine", "Combine with default settings");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "mappings", PROP_COLLECTION, PROP_NONE);
// RNA_def_property_collection_sdna(prop, "BrushChannel", "mappings", NULL);
@ -620,6 +696,7 @@ void RNA_def_brush_channel(BlenderRNA *brna)
"rna_BrushChannel_enum_value_get",
"rna_BrushChannel_enum_value_set",
"rna_BrushChannel_enum_value_get_items");
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "enum_items", PROP_COLLECTION, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE | PROP_ANIMATABLE);
@ -645,44 +722,63 @@ void RNA_def_brush_channel(BlenderRNA *brna)
"rna_BrushChannel_enum_value_set",
"rna_BrushChannel_enum_value_get_items");
RNA_def_property_flag(prop, PROP_ENUM_FLAG);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "BrushCurve");
RNA_def_property_ui_text(prop, "Curve", "Curve");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
// PROP_ENUM_FLAG
}
void RNA_def_brush_channelset(BlenderRNA *brna)
void RNA_def_brush_channelset(BlenderRNA *brna, PropertyRNA *cprop, const char *type_prefix)
{
StructRNA *srna;
PropertyRNA *prop;
FunctionRNA *func;
PropertyRNA *parm;
srna = RNA_def_struct(brna, "BrushChannelSet", NULL);
RNA_def_struct_sdna(srna, "BrushChannelSet");
RNA_def_struct_ui_text(srna, "Channel Set", "Brush Channel Collection");
char buf[256], *name;
sprintf(buf, "%sBrushChannels", type_prefix);
name = strdup(buf);
RNA_def_property_srna(cprop, name);
srna = RNA_def_struct(brna, name, NULL);
RNA_def_struct_sdna(srna, "BrushChannelSet");
RNA_def_struct_ui_text(srna, "Brush Channels", "Collection of brush channels");
// srna = RNA_def_struct(brna, "BrushChannelSet", NULL);
// RNA_def_struct_sdna(srna, "BrushChannelSet");
// RNA_def_struct_ui_text(srna, "Channel Set", "Brush Channel Collection");
func = RNA_def_function(srna, "ensure", "rna_BrushChannelSet_ensure");
RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF);
func = RNA_def_function(srna, "ensure", "BKE_brush_channelset_ensure_existing");
parm = RNA_def_pointer(
func, "channel", "BrushChannel", "", "Ensure a copy of channel exists in this channel set");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
// RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
prop = RNA_def_property(srna, "channels", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "channels", "totchannel");
// prop = RNA_def_property(srna, "channels", PROP_COLLECTION, PROP_NONE);
prop = cprop;
RNA_def_property_collection_sdna(prop, NULL, "channels", NULL);
RNA_def_property_collection_funcs(prop,
"rna_BrushChannelSet_channels_begin",
"rna_iterator_listbase_next",
"rna_iterator_listbase_end",
"rna_iterator_listbase_get",
NULL,
"rna_BrushChannelSet_length",
NULL,
NULL,
"rna_BrushChannelSet_channels_assignint");
RNA_def_property_struct_type(prop, "BrushChannel");
RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_flag(prop, PROP_THICK_WRAP | PROP_DYNAMIC);
RNA_def_property_override_flag(
prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY | PROPOVERRIDE_LIBRARY_INSERTION);
}
@ -692,5 +788,4 @@ void RNA_def_brush_engine(BlenderRNA *brna)
RNA_def_brush_curve(brna);
RNA_def_brush_mapping(brna);
RNA_def_brush_channel(brna);
RNA_def_brush_channelset(brna);
}

View File

@ -157,6 +157,9 @@ void RNA_def_asset(struct BlenderRNA *brna);
void RNA_def_boid(struct BlenderRNA *brna);
void RNA_def_brush(struct BlenderRNA *brna);
void RNA_def_brush_engine(struct BlenderRNA *brna);
void RNA_def_brush_channelset(struct BlenderRNA *brna,
struct PropertyRNA *cprop,
const char *type_prefix);
void RNA_def_cachefile(struct BlenderRNA *brna);
void RNA_def_camera(struct BlenderRNA *brna);
void RNA_def_cloth(struct BlenderRNA *brna);
@ -643,6 +646,16 @@ const char *rna_translate_ui_text(const char *text,
/* Internal functions that cycles uses so we need to declare (tsk tsk) */
void rna_RenderPass_rect_set(PointerRNA *ptr, const float *values);
int rna_BrushChannelSet_channels_assignint(struct PointerRNA *ptr,
int key,
const struct PointerRNA *assign_ptr);
int rna_BrushChannelSet_channels_begin(struct CollectionPropertyIterator *iter,
struct PointerRNA *ptr);
int rna_BrushChannelSet_length(struct PointerRNA *rna);
void rna_BrushChannelSet_ensure(struct ID *id, struct BrushChannel *channel);
/* internal brush channel functions */
#ifdef RNA_RUNTIME
# ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wredundant-decls"

View File

@ -1488,15 +1488,15 @@ static int rna_property_override_diff_propptr(Main *bmain,
(is_array ? RNA_property_##_typename##_set_index((_ptr), (_prop), (_index), (_value)) : \
RNA_property_##_typename##_set((_ptr), (_prop), (_value)))
int rna_property_override_diff_default(Main *bmain,
PropertyRNAOrID *prop_a,
PropertyRNAOrID *prop_b,
const int mode,
IDOverrideLibrary *override,
const char *rna_path,
const size_t rna_path_len,
const int flags,
bool *r_override_changed)
ATTR_NO_OPT int rna_property_override_diff_default(Main *bmain,
PropertyRNAOrID *prop_a,
PropertyRNAOrID *prop_b,
const int mode,
IDOverrideLibrary *override,
const char *rna_path,
const size_t rna_path_len,
const int flags,
bool *r_override_changed)
{
PointerRNA *ptr_a = &prop_a->ptr;
PointerRNA *ptr_b = &prop_b->ptr;

View File

@ -830,11 +830,22 @@ static void rna_def_sculpt(BlenderRNA *brna)
RNA_def_struct_path_func(srna, "rna_Sculpt_path");
RNA_def_struct_ui_text(srna, "Sculpt", "");
# if 0
prop = RNA_def_property(srna, "channels", PROP_POINTER, 0);
RNA_def_property_pointer_sdna(prop, NULL, "channels");
RNA_def_property_struct_type(prop, "BrushChannelSet");
RNA_def_property_ui_text(prop, "Channels", "");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
# endif
prop = RNA_def_property(srna, "channels", PROP_COLLECTION, 0);
RNA_def_property_collection_sdna(prop, NULL, "channels", NULL);
RNA_def_property_struct_type(prop, "BrushChannel");
RNA_def_property_ui_text(prop, "Channels", "");
// 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, "Unified");
prop = RNA_def_property(srna, "radial_symmetry", PROP_INT, PROP_XYZ);
RNA_def_property_int_sdna(prop, NULL, "radial_symm");