commit prior to small refactor

This commit is contained in:
Joseph Eagar 2021-09-19 13:30:43 -07:00
parent 87feba04dd
commit b3ed969b86
9 changed files with 176 additions and 24 deletions

View File

@ -26,6 +26,8 @@ channel_name_map = {
"auto_smooth_projection": "SMOOTH_PROJECTION",
"auto_smooth_radius_factor": "AUTOSMOOTH_RADIUS_SCALE",
"boundary_smooth_factor": "BOUNDARY_SMOOTH",
"autosmooth_fset_slide": "FSET_SLIDE",
"topology_rake_factor": "TOPOLOGY_RAKE"
};
class UnifiedPaintPanel:
@ -122,6 +124,8 @@ class UnifiedPaintPanel:
typeprop = "float_value"
if ch.type == "INT":
typeprop = "int_value"
elif ch.type == "BOOL":
typeprop = "bool_value"
if text is None:
s = prop_name.lower().replace("_", " ").split(" ");
@ -133,12 +137,14 @@ class UnifiedPaintPanel:
if ch.inherit:
sd = context.tool_settings.sculpt
#ensure channel exists in tool settings channel set
sd.channels.ensure(ch)
sd.channels.ensure(ch, queue=True)
finalch = sd.channels.channels[prop_name]
row.prop(finalch, typeprop, icon=icon, text=text, slider=slider)
pressure = pressure and ch.type != "BOOL"
if pressure:
row.prop(finalch.mappings["PRESSURE"], "enabled", text="", icon="STYLUS_PRESSURE")
#if pressure_name:
@ -147,7 +153,7 @@ class UnifiedPaintPanel:
#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:
if not header and ch.type != "BOOL":
row.prop(ch, "inherit", text="", icon='BRUSHES_ALL')
row.prop(ch, "ui_expanded", text="", icon="TRIA_DOWN" if ch.ui_expanded else "TRIA_RIGHT")
@ -670,12 +676,17 @@ def brush_settings(layout, context, brush, popover=False):
slider=True,
)
box.prop(brush, "boundary_smooth_factor")
box.prop(brush, "use_weighted_smooth")
box.prop(brush, "preserve_faceset_boundary")
#box.prop(brush, "boundary_smooth_factor")
#box.prop(brush, "use_weighted_smooth")
#box.prop(brush, "preserve_faceset_boundary")
if brush.preserve_faceset_boundary:
box.prop(brush, "autosmooth_fset_slide")
UnifiedPaintPanel.prop_unified(box, context, brush, "boundary_smooth_factor", slider=True)
UnifiedPaintPanel.prop_unified(box, context, brush, "use_weighted_smooth")
UnifiedPaintPanel.prop_unified(box, context, brush, "preserve_faceset_boundary")
if 1: #brush.preserve_faceset_boundary:
UnifiedPaintPanel.prop_unified(box, context, brush, "autosmooth_fset_slide", slider=True)
#box.prop(brush, "autosmooth_fset_slide")
box.prop(brush, "use_custom_auto_smooth_spacing", text="Custom Spacing")
if brush.use_custom_auto_smooth_spacing:
@ -720,7 +731,15 @@ def brush_settings(layout, context, brush, popover=False):
):
box = layout.box().column() #.column() is a bit more compact
box.prop(brush, "topology_rake_factor", slider=True)
#box.prop(brush, "topology_rake_factor", slider=True)
UnifiedPaintPanel.prop_unified(
box,
context,
brush,
"topology_rake_factor",
slider=True,
text="Topology Rake"
)
box.prop(brush, "use_custom_topology_rake_spacing", text="Custom Spacing")
if brush.use_custom_topology_rake_spacing:

View File

@ -108,9 +108,12 @@ void BKE_brush_channelset_free(BrushChannelSet *chset);
// makes a copy of ch
void BKE_brush_channelset_add(BrushChannelSet *chset, BrushChannel *ch);
void BKE_brush_channelset_queue(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);
void BKE_brush_channelset_ensure_existing(BrushChannelSet *chset,
BrushChannel *existing,
bool queue);
BrushChannel *BKE_brush_channelset_lookup(BrushChannelSet *chset, const char *idname);
@ -188,6 +191,9 @@ void BKE_brush_channelset_compat_load(BrushChannelSet *chset,
struct Brush *brush,
bool to_channels);
// merge in channels the ui requested
void BKE_brush_apply_queued_channels(BrushChannelSet *chset, bool do_override);
#ifdef __cplusplus
}
#endif

View File

@ -200,15 +200,53 @@ BrushChannelSet *BKE_brush_channelset_create()
return (BrushChannelSet *)MEM_callocN(sizeof(BrushChannelSet), "BrushChannelSet");
}
void BKE_brush_apply_queued_channels(BrushChannelSet *chset, bool do_override)
{
if (!chset->tot_queued_channel) {
return;
}
for (int i = 0; i < chset->tot_queued_channel; i++) {
BrushChannel *ch = chset->queued_channels;
BrushChannel *exist = BKE_brush_channelset_lookup(chset, ch->idname);
if (exist) {
if (!do_override) {
continue;
}
BKE_brush_channel_free(exist);
*exist = *ch;
continue;
}
else {
BKE_brush_channelset_add(chset, ch);
BKE_brush_channel_free(ch);
}
}
MEM_SAFE_FREE(chset->queued_channels);
chset->queued_channels = NULL;
chset->tot_queued_channel = NULL;
}
void BKE_brush_channelset_free(BrushChannelSet *chset)
{
if (chset->channels) {
for (int i = 0; i < chset->totchannel; i++) {
BKE_brush_channel_free(chset->channels + i);
}
for (int step = 0; step < 2; step++) {
BrushChannel *channels = step ? chset->queued_channels : chset->channels;
int totchannel = step ? chset->tot_queued_channel : chset->totchannel;
MEM_freeN(chset->channels);
if (channels) {
for (int i = 0; i < totchannel; i++) {
BKE_brush_channel_free(channels + i);
}
MEM_freeN(channels);
}
}
MEM_freeN(chset);
}
@ -229,6 +267,26 @@ void BKE_brush_channelset_add(BrushChannelSet *chset, BrushChannel *ch)
namestack_pop();
}
// used to avoid messing up pointers in ui
void BKE_brush_channelset_queue(BrushChannelSet *chset, BrushChannel *ch)
{
chset->tot_queued_channel++;
if (!chset->queued_channels) {
chset->queued_channels = MEM_callocN(sizeof(BrushChannel) * chset->tot_queued_channel,
"chset->channels");
}
else {
chset->queued_channels = MEM_recallocN_id(chset->queued_channels,
sizeof(BrushChannel) * chset->tot_queued_channel,
"chset->queued_channels");
}
namestack_push(__func__);
BKE_brush_channel_copy_data(chset->queued_channels + chset->tot_queued_channel - 1, ch);
namestack_pop();
}
ATTR_NO_OPT BrushChannel *BKE_brush_channelset_lookup(BrushChannelSet *chset, const char *idname)
{
for (int i = 0; i < chset->totchannel; i++) {
@ -318,14 +376,22 @@ bool BKE_brush_channelset_ensure_builtin(BrushChannelSet *chset, const char *idn
return false;
}
void BKE_brush_channelset_ensure_existing(BrushChannelSet *chset, BrushChannel *existing)
void BKE_brush_channelset_ensure_existing(BrushChannelSet *chset,
BrushChannel *existing,
bool queue)
{
if (BKE_brush_channelset_has(chset, existing->idname)) {
return;
}
namestack_push(__func__);
BKE_brush_channelset_add(chset, existing);
if (!queue) {
BKE_brush_channelset_add(chset, existing);
}
else {
BKE_brush_channelset_queue(chset, existing);
}
namestack_pop();
}
#define ADDCH(name) BKE_brush_channelset_ensure_builtin(chset, name)
@ -667,6 +733,14 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
ADDCH("ORIGINAL_PLANE");
ADDCH("JITTER");
ADDCH("JITTER_ABSOLUTE");
ADDCH("USE_WEIGHTED_SMOOTH");
ADDCH("PRESERVE_FACESET_BOUNDARY");
ADDCH("HARD_EDGE_MODE");
ADDCH("GRAB_SILHOUETTE");
ADDCH("PROJECTION");
ADDCH("BOUNDARY_SMOOTH");
ADDCH("FSET_SLIDE");
switch (tool) {
case SCULPT_TOOL_DRAW: {
@ -680,6 +754,15 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
namestack_pop();
}
void BKE_brush_init_scene_defaults(Sculpt *sd)
{
if (!sd->channels) {
sd->channels = BKE_brush_channelset_create();
}
BrushChannelSet *chset = sd->channels;
}
void BKE_brush_builtin_create(Brush *brush, int tool)
{
namestack_push(__func__);
@ -801,6 +884,10 @@ static BrushSettingsMap brush_settings_map[] = {
DEF(topology_rake_projection, TOPOLOGY_RAKE_PROJECTION, FLOAT, FLOAT)
DEF(topology_rake_radius_factor, TOPOLOGY_RAKE_RADIUS_SCALE, FLOAT, FLOAT)
DEF(topology_rake_spacing, TOPOLOGY_RAKE_SPACING, INT, FLOAT)
DEF(topology_rake_factor, TOPOLOGY_RAKE, FLOAT, FLOAT)
DEF(autosmooth_fset_slide, FSET_SLIDE, FLOAT, FLOAT)
DEF(boundary_smooth_factor, BOUNDARY_SMOOTH, FLOAT, FLOAT)
DEF(autosmooth_radius_factor, AUTOSMOOTH_RADIUS_SCALE, FLOAT, FLOAT)
DEF(normal_weight, NORMAL_WEIGHT, FLOAT, FLOAT)
DEF(rake_factor, RAKE_FACTOR, FLOAT, FLOAT)
DEF(weight, WEIGHT, FLOAT, FLOAT)
@ -814,9 +901,6 @@ static BrushSettingsMap brush_settings_map[] = {
DEF(wet_persistence, WET_PERSISTENCE, FLOAT, FLOAT)
DEF(density, DENSITY, FLOAT, FLOAT)
DEF(tip_scale_x, TIP_SCALE_X, FLOAT, FLOAT)
DEF(autosmooth_fset_slide, FSET_SLIDE, FLOAT, FLOAT)
DEF(boundary_smooth_factor, BOUNDARY_SMOOTH, FLOAT, FLOAT)
DEF(autosmooth_radius_factor, AUTOSMOOTH_RADIUS_SCALE, FLOAT, FLOAT)
};
static const int brush_settings_map_len = ARRAY_SIZE(brush_settings_map);
@ -838,6 +922,10 @@ BrushFlagMap brush_flags_map[] = {
DEF(flag, ORIGINAL_NORMAL, BRUSH_ORIGINAL_NORMAL)
DEF(flag, ORIGINAL_PLANE, BRUSH_ORIGINAL_PLANE)
DEF(flag, ACCUMULATE, BRUSH_ACCUMULATE)
DEF(flag2, USE_WEIGHTED_SMOOTH, BRUSH_SMOOTH_USE_AREA_WEIGHT)
DEF(flag2, PRESERVE_FACESET_BOUNDARY, BRUSH_SMOOTH_PRESERVE_FACE_SETS)
DEF(flag2, HARD_EDGE_MODE, BRUSH_HARD_EDGE_MODE)
DEF(flag2, GRAB_SILHOUETTE, BRUSH_GRAB_SILHOUETTE)
};
int brush_flags_map_len = ARRAY_SIZE(brush_flags_map);
@ -1176,6 +1264,10 @@ void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *cset)
{
BLO_read_data_address(reader, &cset->channels);
// drop any queued channels, we don't save them.
cset->queued_channels = NULL;
cset->tot_queued_channel = 0;
for (int i = 0; i < cset->totchannel; i++) {
BrushChannel *ch = cset->channels + i;

View File

@ -416,7 +416,11 @@ BrushChannelType brush_builtin_channels[] = {
MAKE_FLOAT("DASH_RATIO", "Dash Ratio", "Ratio of samples in a cycle that the brush is enabled", 0.0f, 0.0f, 1.0f),
MAKE_FLOAT_EX("PLANE_OFFSET", "Plane Offset", "Adjust plane on which the brush acts towards or away from the object surface", 0.0f, -2.0f, 2.0f, -0.5f, 0.5f),
MAKE_BOOL("ORIGINAL_NORMAL", "Original Normal", "When locked keep using normal of surface where stroke was initiated", false),
MAKE_BOOL("ORIGINAL_PLANE", "Original Plane", "When locked keep using the plane origin of surface where stroke was initiated", false)
MAKE_BOOL("ORIGINAL_PLANE", "Original Plane", "When locked keep using the plane origin of surface where stroke was initiated", false),
MAKE_BOOL("USE_WEIGHTED_SMOOTH", "Weight By Area", "Weight by face area to get a smoother result", true),
MAKE_BOOL("PRESERVE_FACESET_BOUNDARY", "Keep FSet Boundary", "Preserve face set boundaries", true),
MAKE_BOOL("HARD_EDGE_MODE", "Hard Edge Mode", "Forces all brushes into hard edge face set mode (sets face set slide to 0)", false),
MAKE_BOOL("GRAB_SILHOUETTE", "Grab Silhouette", "Grabs trying to automask the silhouette of the object", false),
};
/* clang-format on */

View File

@ -1361,6 +1361,28 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 300, 24)) {
LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
// load old brush settings into channels
if (brush->channels) {
BKE_brush_channelset_free(brush->channels);
brush->channels = NULL;
}
BKE_brush_builtin_create(brush, brush->sculpt_tool);
BKE_brush_channelset_compat_load(brush->channels, brush, true);
}
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
if (scene->toolsettings->sculpt) {
printf("scene channels: %p\n", scene->toolsettings->sculpt->channels);
if (scene->toolsettings->sculpt->channels) {
BKE_brush_channelset_free(scene->toolsettings->sculpt->channels);
scene->toolsettings->sculpt->channels = BKE_brush_channelset_create();
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -9010,6 +9010,8 @@ ATTR_NO_OPT static void SCULPT_run_command_list(
*brush2 = *brush;
ss->cache->brush = brush2;
ss->cache->bstrength = BKE_brush_channelset_get_float(
cmd->params_final, "STRENGTH", &ss->cache->input_mapping);
// Load parameters into brush2 for compatibility with old code
BKE_brush_channelset_compat_load(cmd->params_final, brush2, false);

View File

@ -1061,9 +1061,9 @@ static void do_smooth_brush_task_cb_ex(void *__restrict userdata,
#else
static void do_smooth_brush_task_cb_ex(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict tls)
ATTR_NO_OPT static void do_smooth_brush_task_cb_ex(void *__restrict userdata,
const int n,
const TaskParallelTLS *__restrict tls)
{
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;

View File

@ -50,7 +50,10 @@ typedef struct BrushChannel {
typedef struct BrushChannelSet {
BrushChannel *channels;
int totchannel, _pad[1];
/*cannot add channels within the UI loop. Since it's
hard to avoid it they're put here.*/
BrushChannel *queued_channels;
int totchannel, tot_queued_channel;
} BrushChannelSet;
// mapping flags

View File

@ -406,6 +406,10 @@ void RNA_def_brush_channelset(BlenderRNA *brna)
func, "channel", "BrushChannel", "", "Ensure a copy of channel exists in this channel set");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
parm = RNA_def_boolean(
func, "queue", true, "queue", "Add channel to an internal queue to avoid corrupting the UI");
// 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");
RNA_def_property_collection_funcs(prop,