Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2022-09-29 02:22:34 +0300
committerJoseph Eagar <joeedh@gmail.com>2022-09-29 02:22:34 +0300
commit0156a677c7d13106a1d049d74fca43b5311eb53e (patch)
tree9e2c73fc0349cde80555dbe0cbf67e2dfb531011 /source/blender/editors/sculpt_paint/sculpt.c
parent53ac3192ba07c4271c86479186ed0d0b8cd7846f (diff)
Sculpt: New Cavity Automasking Mode
Add new cavity automasking mode based on local mesh curvature. Cavity masking is a great way to quickly add detail in crevices and the like. It's meant to be used with the Paint brush in color attribute mode. It does work with other brushes but the results can be unpredictable. {F13131497} The old "dirty mask" operator has been replace with a new "mask from cavity" operator that shares the same code with cavity automasking. Differences from the sculpt-dev implementation: * It uses the word "cavity." When I first implemented this I wasn't aware this feature existed in other software (and other paint modes in Blender), and for reasons that escape me today I initially decided to call it a concave or concavity mask. * The cavity factor works a bit differently. It's no longer non-linear and functions as a simple scale around 0.5f. * Supports custom curves. * Supports blurring. Reviewed By: Julian Kaspar, Jeroen Bakker and Campbell Barton Differential Revision: https://developer.blender.org/D15122 Ref D15122
Diffstat (limited to 'source/blender/editors/sculpt_paint/sculpt.c')
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 114c2c3839a..ac77e007081 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3364,6 +3364,8 @@ static void do_brush_action(Sculpt *sd,
/* Initialize auto-masking cache. */
if (SCULPT_is_automasking_enabled(sd, ss, brush)) {
ss->cache->automasking = SCULPT_automasking_cache_init(sd, brush, ob);
+ ss->last_automasking_settings_hash = SCULPT_automasking_settings_hash(
+ ob, ss->cache->automasking);
}
/* Initialize surface smooth cache. */
if ((brush->sculpt_tool == SCULPT_TOOL_SMOOTH) &&
@@ -3546,6 +3548,11 @@ static void do_brush_action(Sculpt *sd,
SCULPT_bmesh_topology_rake(sd, ob, nodes, totnode, brush->topology_rake_factor);
}
+ if (!SCULPT_tool_can_reuse_cavity_mask(brush->sculpt_tool) || (ss->cache->supports_gravity && sd->gravity_factor > 0.0f)) {
+ /* Clear cavity mask cache. */
+ ss->last_automasking_settings_hash = 0;
+ }
+
/* The cloth brush adds the gravity as a regular force and it is processed in the solver. */
if (ss->cache->supports_gravity && !ELEM(brush->sculpt_tool,
SCULPT_TOOL_CLOTH,
@@ -4234,6 +4241,8 @@ static void sculpt_update_cache_invariants(
ss->cache = cache;
+ cache->stroke_id = ss->stroke_id;
+
/* Set scaling adjustment. */
max_scale = 0.0f;
for (int i = 0; i < 3; i++) {
@@ -4339,6 +4348,10 @@ static void sculpt_update_cache_invariants(
cache->original = true;
}
+ if (SCULPT_automasking_needs_original(sd, brush)) {
+ cache->original = true;
+ }
+
/* Draw sharp does not need the original coordinates to produce the accumulate effect, so it
* should work the opposite way. */
if (brush->sculpt_tool == SCULPT_TOOL_DRAW_SHARP) {
@@ -5398,6 +5411,8 @@ static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const f
SCULPT_undo_push_begin_ex(ob, sculpt_tool_name(sd));
}
+ SCULPT_stroke_id_next(ob);
+
return true;
}
return false;
@@ -5996,4 +6011,24 @@ void SCULPT_fake_neighbors_free(Object *ob)
sculpt_pose_fake_neighbors_free(ss);
}
+void SCULPT_stroke_id_next(Object *ob)
+{
+ /* Manually wrap in int32 space to avoid tripping up undefined behavior
+ * sanitizers.
+ */
+ ob->sculpt->stroke_id = (uchar)(((int)ob->sculpt->stroke_id + 1) & 255);
+}
+
+void SCULPT_stroke_id_ensure(Object *ob)
+{
+ SculptSession *ss = ob->sculpt;
+
+ if (!ss->attrs.stroke_id) {
+ SculptAttributeParams params = {0};
+
+ ss->attrs.stroke_id = BKE_sculpt_attribute_ensure(
+ ob, ATTR_DOMAIN_POINT, CD_PROP_INT8, SCULPT_ATTRIBUTE_NAME(stroke_id), &params);
+ }
+}
+
/** \} */