[Bf-blender-cvs] [e5a111c6371] sculpt-dev: sculpt-dev: Device mapping curves reversed
Joseph Eagar
noreply at git.blender.org
Thu May 12 07:39:05 CEST 2022
Commit: e5a111c6371d0807ba69af7361c4e63118f74839
Author: Joseph Eagar
Date: Wed May 11 22:38:09 2022 -0700
Branches: sculpt-dev
https://developer.blender.org/rBe5a111c6371d0807ba69af7361c4e63118f74839
sculpt-dev: Device mapping curves reversed
* Turns out BKE_brush_curve_strength_ex requires inverted input,
except for BRUSH_CURVE_CUSTOM.
===================================================================
M release/datafiles/startup.blend
M release/scripts/startup/bl_ui/properties_paint_common.py
M source/blender/blenkernel/intern/brush_engine.c
M source/blender/blenkernel/intern/brush_engine_presets.c
===================================================================
diff --git a/release/datafiles/startup.blend b/release/datafiles/startup.blend
index de64cd00d26..09738836408 100644
Binary files a/release/datafiles/startup.blend and b/release/datafiles/startup.blend differ
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 37b1cc05971..f78b792e512 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -274,7 +274,7 @@ def template_curve(layout, base, propname, full_path, use_negative_slope=None):
for i, shape in enumerate(shapes):
props = row.operator("brush.curve_preset_load", icon=icons[i], text="")
- props.invert = use_negative_slope
+ props.invert = not use_negative_slope
props.shape = shape
props.path = path
@@ -675,15 +675,7 @@ class UnifiedPaintPanel:
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"
+ template_curve(col, mp.curve, "curve", path2 + ".curve", use_negative_slope=False)
col.prop(mp, "factor")
col.prop(mp, "blendmode")
diff --git a/source/blender/blenkernel/intern/brush_engine.c b/source/blender/blenkernel/intern/brush_engine.c
index efd4008a467..348239b46d7 100644
--- a/source/blender/blenkernel/intern/brush_engine.c
+++ b/source/blender/blenkernel/intern/brush_engine.c
@@ -152,7 +152,7 @@ bool BKE_brush_mapping_ensure_write(BrushMapping *mp)
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);
+ CURVEMAP_SLOPE_NEGATIVE);
BKE_curvemapping_init(curve);
@@ -200,43 +200,6 @@ bool BKE_brush_channel_curve_ensure_write(BrushCurve *curve)
return false;
}
-static bool check_corrupted_curve(BrushMapping *dst)
-{
- CurveMapping *curve = dst->mapping_curve.curve;
-
- if (!curve) {
- return false;
- }
-
- if (BKE_curvemapping_in_cache(curve)) {
- return false;
- }
-
- const float clip_size_x = BLI_rctf_size_x(&curve->curr);
- const float clip_size_y = BLI_rctf_size_y(&curve->curr);
-
- // fix corrupted curve
- 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->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->mapping_curve.curve);
- }
-
- return false;
- }
-
- return true;
-}
-
/*
Brush command lists.
@@ -562,7 +525,7 @@ void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
BKE_curvemap_reset(mp->mapping_curve.curve->cm,
&(struct rctf){.xmin = 0.0f, .ymin = 0.0f, .xmax = 1.0f, .ymax = 1.0f},
mdef->curve,
- CURVEMAP_SLOPE_POSITIVE);
+ CURVEMAP_SLOPE_NEGATIVE);
BKE_curvemapping_init(mp->mapping_curve.curve);
@@ -1133,7 +1096,7 @@ double BKE_brush_channel_eval_mappings(BrushChannel *ch,
}
double f2 = BKE_brush_curve_strength_ex(
- mp->mapping_curve.preset, mp->mapping_curve.curve, inputf, 1.0f);
+ mp->mapping_curve.preset, mp->mapping_curve.curve, 1.0f - inputf, 1.0f);
f2 = mp->min + (mp->max - mp->min) * f2;
/* make sure to update blend_items in rna_brush_engine.c
@@ -2089,6 +2052,16 @@ void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *chset)
/* Only convert curve if it's not linear. */
if (!BKE_curvemapping_equals(mp->curve, &linear_curve)) {
mp->mapping_curve.preset = BRUSH_CURVE_CUSTOM;
+
+ /* TODO: figure out why BKE_brush_curve_strength_ex inverts custom curves
+ * but not any other preset.
+ */
+ for (int i = 0; i < mp->curve->cm->totpoint; i++) {
+ mp->curve->cm->curve[i].x = 1.0f - mp->curve->cm->curve[i].x;
+ }
+
+ BKE_curvemapping_changed(mp->curve, false);
+
mp->mapping_curve.curve = GET_CACHE_CURVE(mp->curve);
}
else {
diff --git a/source/blender/blenkernel/intern/brush_engine_presets.c b/source/blender/blenkernel/intern/brush_engine_presets.c
index ae798edb1fb..0a1d6457a60 100644
--- a/source/blender/blenkernel/intern/brush_engine_presets.c
+++ b/source/blender/blenkernel/intern/brush_engine_presets.c
@@ -995,7 +995,7 @@ void BKE_brush_channelset_compat_load(BrushChannelSet *chset, Brush *brush, bool
BKE_curvemap_reset(ch->curve.curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_LINE,
- 1);
+ CURVEMAP_SLOPE_NEGATIVE);
}
BKE_curvemapping_init(ch->curve.curve);
}
@@ -1031,29 +1031,33 @@ void reset_clay_mappings(BrushChannelSet *chset, bool strips)
BKE_curvemap_reset(curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_LINE,
- 1);
+ CURVEMAP_SLOPE_NEGATIVE);
BKE_curvemapping_init(curve);
CurveMap *cuma = curve->cm;
if (!strips) { //[[0,0.200], [0.354,0.200], [0.595,0.210], [0.806,0.523], [1,1.000]
#if 0
- cuma->curve[0].x = 0.0f;
+ cuma->curve[0].x = 1.0f;
cuma->curve[0].y = 0.2f;
- BKE_curvemap_insert(cuma, 0.35f, 0.2f);
- BKE_curvemap_insert(cuma, 0.6f, 0.210f);
- BKE_curvemap_insert(cuma, 0.8f, 0.525f);
+ cuma->curve[1].x = 0.0f;
+
+ BKE_curvemap_insert(cuma, 1.0f-0.35f, 0.2f);
+ BKE_curvemap_insert(cuma, 1.0f-0.6f, 0.210f);
+ BKE_curvemap_insert(cuma, 1.0f-0.8f, 0.525f);
BKE_curvemapping_changed(curve, true);
#endif
}
else {
//[[0,0], [0.250,0.050], [0.500,0.125], [0.750,0.422], [1,1]
- cuma->curve[0].x = 0.0f;
+ cuma->curve[0].x = 1.0f;
cuma->curve[0].y = 0.55f;
+ cuma->curve[1].x = 0.0f;
+
BKE_curvemap_insert(cuma, 0.5f, 0.7f);
- cuma->curve[2].x = 1.0f;
+ cuma->curve[2].x = 0.0f;
cuma->curve[2].y = 1.0f;
BKE_curvemapping_changed(curve, true);
}
@@ -1068,7 +1072,7 @@ void reset_clay_mappings(BrushChannelSet *chset, bool strips)
BKE_curvemap_reset(curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_LINE,
- 1);
+ CURVEMAP_SLOPE_NEGATIVE);
BKE_curvemapping_init(curve);
cuma = curve->cm;
@@ -1142,7 +1146,7 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
BKE_curvemap_reset(ch->curve.curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
CURVE_PRESET_SMOOTH,
- 1);
+ CURVEMAP_SLOPE_NEGATIVE);
BKE_curvemapping_init(ch->curve.curve);
}
}
@@ -1719,17 +1723,17 @@ void BKE_brush_mapping_reset(BrushChannel *ch, int tool, int mapping)
BKE_curvemap_reset(curve->cm,
&(struct rctf){.xmin = 0, .ymin = 0.0, .xmax = 1.0, .ymax = 1.0},
mdef->curve,
- 1);
+ CURVEMAP_SLOPE_NEGATIVE);
BKE_curvemapping_init(curve);
CurveMap *cuma = curve->cm;
- cuma->curve[0].x = 0.0f;
- cuma->curve[0].y = 0.0f;
+ cuma->curve[0].x = 1.0f;
+ cuma->curve[0].y = 1.0f;
- cuma->curve[1].x = 1.0f;
- cuma->curve[1].y = 1.0f;
+ cuma->curve[1].x = 0.0f;
+ cuma->curve[1].y = 0.0f;
- BKE_curvemap_insert(cuma, 0.65f, 0.0f);
+ BKE_curvemap_insert(cuma, 0.35f, 0.0f);
cuma->curve[1].flag |= CUMA_HANDLE_VECTOR;
BKE_curvemapping_changed(curve, true);
More information about the Bf-blender-cvs
mailing list