[Bf-blender-cvs] [cfc46e43b2f] sculpt-dev: Sculpt-dev: Use brush curve presets for device curves
Joseph Eagar
noreply at git.blender.org
Thu May 12 04:54:30 CEST 2022
Commit: cfc46e43b2f4f653f2412ae564d3c6fb6638139a
Author: Joseph Eagar
Date: Wed May 11 19:18:33 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rBcfc46e43b2f4f653f2412ae564d3c6fb6638139a
Sculpt-dev: Use brush curve presets for device curves
* Brush mapping (device) curves now use the BrushCurve
API. This prevents having to save a CurveMapping
instance for every single device mapping (of which there
is ~5 or so) in every single channel (>40) for
every single brush (~40-70).
* Fixed regression where temporary attributes weren't being
stripped on file save in all cases.
===================================================================
M release/scripts/startup/bl_ui/properties_data_mesh.py
M release/scripts/startup/bl_ui/properties_paint_common.py
M source/blender/blenkernel/BKE_brush_engine.h
M source/blender/blenkernel/BKE_brush_engine.hh
M source/blender/blenkernel/intern/brush_engine.c
M source/blender/blenkernel/intern/brush_engine_presets.c
M source/blender/blenkernel/intern/curvemapping_cache.c
M source/blender/blenkernel/intern/customdata.cc
M source/blender/blenloader/intern/versioning_300.c
M source/blender/makesdna/DNA_sculpt_brush_types.h
M source/blender/makesrna/intern/rna_brush_engine.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index f866d60fdcd..516d037b03a 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -468,6 +468,7 @@ class DATA_PT_customdata(MeshButtonsPanel, Panel):
col.operator("mesh.customdata_mask_clear", icon='X')
col.operator("mesh.customdata_skin_clear", icon='X')
+ col.operator("mesh.customdata_ids_clear", icon='X')
if me.has_custom_normals:
col.operator("mesh.customdata_custom_splitnormals_clear", icon='X')
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 7e385a406c9..37b1cc05971 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -659,13 +659,9 @@ class UnifiedPaintPanel:
#here?
box = layout.box()
- box.template_curve_mapping(mp, "curve", brush=True, use_negative_slope=True)
-
col = box.column(align=True)
col.use_property_split = True
col.use_property_decorate = False
-
- row = col.row(align=True)
if mp0.inherit_mode == "ALWAYS" or (mp0.inherit_mode == "USE_CHANNEL" and ch.inherits):
path2 = path + ".mappings[\"%s\"].curve" % (mp.type)
@@ -673,13 +669,21 @@ class UnifiedPaintPanel:
brushpath = "tool_settings.sculpt.brush.channels[\"%s\"]" % ch.idname
path2 = brushpath + ".mappings[\"%s\"].curve" % (mp.type)
- shapes = ['SMOOTH', 'ROUND', 'ROOT', 'SHARP', 'LINE', 'MAX']
- icons = ['SMOOTHCURVE', 'SPHERECURVE', 'ROOTCURVE', 'SHARPCURVE', 'LINCURVE', 'NOCURVE']
- for i, shape in enumerate(shapes):
- props = row.operator("brush.curve_preset_load", icon=icons[i], text="")
- props.shape = shape
- props.path = path2
+ col.prop(mp.curve, "curve_preset", text=text)
+
+ row = col.row(align=True)
+
+ if not header and mp.curve.curve_preset == "CUSTOM":
+ template_curve(col, mp.curve, "curve", path2 + ".curve", use_negative_slope=True)
+
+ shapes = ['SMOOTH', 'ROUND', 'ROOT', 'SHARP', 'LINE', 'MAX']
+ icons = ['SMOOTHCURVE', 'SPHERECURVE', 'ROOTCURVE', 'SHARPCURVE', 'LINCURVE', 'NOCURVE']
+
+ for i, shape in enumerate(shapes):
+ props = row.operator("brush.curve_preset_load", icon=icons[i], text="")
+ props.shape = shape
+ props.path = path2 + ".curve"
col.prop(mp, "factor")
col.prop(mp, "blendmode")
diff --git a/source/blender/blenkernel/BKE_brush_engine.h b/source/blender/blenkernel/BKE_brush_engine.h
index 5b420395a9f..6c3a3384deb 100644
--- a/source/blender/blenkernel/BKE_brush_engine.h
+++ b/source/blender/blenkernel/BKE_brush_engine.h
@@ -348,7 +348,7 @@ bool BKE_brush_channelset_set_int(BrushChannelSet *chset, const char *idname, in
void BKE_brush_channel_set_int(BrushChannel *ch, int val);
/* mapdata may be NULL */
-float BKE_brush_channel_get_int(BrushChannel *ch, BrushMappingData *mapdata);
+int BKE_brush_channel_get_int(BrushChannel *ch, BrushMappingData *mapdata);
/* mapdata may be NULL */
float BKE_brush_channel_get_float(BrushChannel *ch, BrushMappingData *mapdata);
diff --git a/source/blender/blenkernel/BKE_brush_engine.hh b/source/blender/blenkernel/BKE_brush_engine.hh
index 84861ebe5c2..f449a4728f5 100644
--- a/source/blender/blenkernel/BKE_brush_engine.hh
+++ b/source/blender/blenkernel/BKE_brush_engine.hh
@@ -296,10 +296,8 @@ template<typename T> class BrushChannelIF {
inputf = 1.0f - inputf;
}
- /* ensure curve tables exist */
- BKE_curvemapping_init(mp->curve);
-
- double f2 = (float)BKE_curvemapping_evaluateF(mp->curve, 0, inputf);
+ double f2 = BKE_brush_curve_strength_ex(
+ mp->mapping_curve.preset, mp->mapping_curve.curve, inputf, 1.0f);
f2 = mp->min + (mp->max - mp->min) * f2;
/* make sure to update blend_items in rna_brush_engine.c
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index bd83b136cfb..87ce6db9f75 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -125,14 +125,36 @@ void BKE_brush_channel_system_exit()
{
BKE_curvemapping_cache_free(brush_curve_cache);
}
-// returns true if curve was duplicated
-bool BKE_brush_mapping_ensure_write(BrushMapping *mp)
+
+/* returns true if curve was duplicated or initialized. */
+ATTR_NO_OPT bool BKE_brush_mapping_ensure_write(BrushMapping *mp)
{
- if (IS_CACHE_CURVE(mp->curve)) {
- CurveMapping *newcurve = BKE_curvemapping_copy(mp->curve);
- RELEASE_CACHE_CURVE(mp->curve);
- mp->curve = newcurve;
+ if (mp->mapping_curve.curve && IS_CACHE_CURVE(mp->mapping_curve.curve)) {
+ CurveMapping *newcurve = BKE_curvemapping_copy(mp->mapping_curve.curve);
+ RELEASE_CACHE_CURVE(mp->mapping_curve.curve);
+
+ mp->mapping_curve.curve = newcurve;
+
+ return true;
+ }
+
+ if (mp->mapping_curve.preset != BRUSH_CURVE_CUSTOM) {
+ return false;
+ }
+
+ if (!mp->mapping_curve.curve) {
+ CurveMapping *curve = mp->mapping_curve.curve = MEM_callocN(sizeof(CurveMapping),
+ "brsh mapping curve");
+
+ BKE_curvemapping_set_defaults(curve, 1, 0, 0.0f, 1, 1.0f);
+
+ BKE_curvemap_reset(curve->cm,
+ &(struct rctf){.xmin = 0.0f, .ymin = 0.0f, .xmax = 1.0f, .ymax = 1.0f},
+ CURVE_PRESET_LINE,
+ CURVEMAP_SLOPE_POSITIVE);
+
+ BKE_curvemapping_init(curve);
return true;
}
@@ -176,7 +198,11 @@ bool BKE_brush_channel_curve_ensure_write(BrushCurve *curve)
static bool check_corrupted_curve(BrushMapping *dst)
{
- CurveMapping *curve = dst->curve;
+ CurveMapping *curve = dst->mapping_curve.curve;
+
+ if (!curve) {
+ return false;
+ }
if (BKE_curvemapping_in_cache(curve)) {
return false;
@@ -189,15 +215,16 @@ static bool check_corrupted_curve(BrushMapping *dst)
if (clip_size_x == 0.0f || clip_size_y == 0.0f) {
for (int i = 0; i < 4; i++) {
BKE_curvemapping_free_data(curve);
- memset(&dst->curve, 0, sizeof(CurveMapping));
- BKE_curvemapping_set_defaults(dst->curve, 1, 0.0, 0.0, 1.0, 1.0);
+ memset(&dst->mapping_curve.curve, 0, sizeof(CurveMapping));
+
+ BKE_curvemapping_set_defaults(dst->mapping_curve.curve, 1, 0.0, 0.0, 1.0, 1.0);
BKE_curvemap_reset(curve->cm + i,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_LINE,
1);
- BKE_curvemapping_init(dst->curve);
+ BKE_curvemapping_init(dst->mapping_curve.curve);
}
return false;
@@ -271,7 +298,9 @@ void BKE_brush_channel_free_data(BrushChannel *ch)
for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
BrushMapping *mp = ch->mappings + i;
- RELEASE_OR_FREE_CURVE(mp->curve);
+ if (mp->mapping_curve.curve) {
+ RELEASE_OR_FREE_CURVE(mp->mapping_curve.curve);
+ }
}
}
@@ -402,18 +431,18 @@ void BKE_brush_channel_copy_data(BrushChannel *dst,
for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
BrushMapping *mp = dst->mappings + i;
- if (!mp->curve) {
+ if (!mp->mapping_curve.curve) {
continue;
}
- if (IS_CACHE_CURVE(mp->curve)) {
- RELEASE_CACHE_CURVE(mp->curve);
+ if (IS_CACHE_CURVE(mp->mapping_curve.curve)) {
+ RELEASE_CACHE_CURVE(mp->mapping_curve.curve);
}
else {
- BKE_curvemapping_free(mp->curve);
+ BKE_curvemapping_free(mp->mapping_curve.curve);
}
- mp->curve = NULL;
+ mp->mapping_curve.curve = NULL;
}
// preserve linked list pointers
@@ -455,7 +484,7 @@ void BKE_brush_channel_copy_data(BrushChannel *dst,
namestack_push(__func__);
for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
- dst->mappings[i].curve = NULL;
+ dst->mappings[i].mapping_curve.curve = NULL;
BKE_brush_mapping_copy_data(dst->mappings + i, src->mappings + i);
dst->mappings[i].type = i;
@@ -490,12 +519,10 @@ void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
BrushMapping *mp = ch->mappings + i;
- if (mp->curve) {
- RELEASE_OR_FREE_CURVE(mp->curve);
+ if (mp->mapping_curve.curve) {
+ RELEASE_OR_FREE_CURVE(mp->mapping_curve.curve);
}
- CurveMapping *curve = mp->curve = (CurveMapping *)MEM_callocN(sizeof(*curve),
- "CurveMapping for BrushMapping");
mp->type = i;
float min, max;
@@ -519,22 +546,30 @@ void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
mp->inherit_mode = BRUSH_MAPPING_INHERIT_ALWAYS;
}
- int slope = CURVEMAP_SLOPE_POSITIVE;
+ mp->min = min;
+ mp->max = max;
- BKE_curvemapping_set_defaults(curve, 1, 0, 0.0f, 1, 1.0f);
+ if (mdef->curve != CURVE_PRESET_LINE) {
+ mp->mapping_curve.preset = BRUSH_CURVE_CUSTOM;
+ BKE_brush_mapping_ensure_write(mp);
+
+ mp->mapping_curve.curve = MEM_callocN(sizeof(CurveMapping), "CurveMapping");
+
+ BKE_curvemapping_set_defaults(mp->mapping_curve.curve, 1, 0, 0.0f, 1, 1.0f);
- for (int j = 0; j < 1; j++) {
- BKE_curvemap_reset(&curve->cm[j],
+ BKE_curvemap_reset(mp->mapping_curve.curve->cm,
&(struct rctf){.xmi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list