diff options
author | Pablo Dobarro <pablodp606> | 2020-10-08 01:00:36 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2020-10-15 20:00:51 +0300 |
commit | 0d5ec990a9844e639fa6ab989b14b2e051ac8c42 (patch) | |
tree | 4130069e315263bcef6d66f2939c02fea13a6550 /source/blender/editors | |
parent | 6dda0779fcdef704a17ed3c0150073f77534d5e5 (diff) |
Sculpt: Experimental Pen Tilt Support
This adds support for pen tilt in sculpt mode. For now, pen tilt is used
by tweaking the tilt strength property, which controls how much the pen
angle affects the sculpt normal. This is available in Draw, Draw Sharp,
Flatten, Fill, Scrape and Clay Strips brushes, but it can be enabled in
more tools later.
The purpose of this patch is to have a usable implementation of pen tilt
in a painting mode, so users can test and see in which hardware and
platforms this feature is supported and how well it works. If it works
ok, more tools and features that rely on pen tilt can be implemented,
like brushes that blend between two deformations depending on the angle.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8893
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 12 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 26 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_intern.h | 7 |
3 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 21b33a4e2ab..da0a8dbd4b8 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -123,6 +123,10 @@ typedef struct PaintStroke { float zoom_2d; int pen_flip; + /* Tilt, as read from the event. */ + float x_tilt; + float y_tilt; + /* line constraint */ bool constrain_line; float constrained_pos[2]; @@ -620,6 +624,8 @@ static void paint_brush_stroke_add_step(bContext *C, RNA_float_set_array(&itemptr, "mouse", mouse_out); RNA_boolean_set(&itemptr, "pen_flip", stroke->pen_flip); RNA_float_set(&itemptr, "pressure", pressure); + RNA_float_set(&itemptr, "x_tilt", stroke->x_tilt); + RNA_float_set(&itemptr, "y_tilt", stroke->y_tilt); stroke->update_step(C, stroke, &itemptr); @@ -1383,6 +1389,12 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) paint_stroke_add_sample(p, stroke, event->mval[0], event->mval[1], pressure); paint_stroke_sample_average(stroke, &sample_average); + /* Tilt. */ + if (WM_event_is_tablet(event)) { + stroke->x_tilt = event->tablet.x_tilt; + stroke->y_tilt = event->tablet.y_tilt; + } + #ifdef WITH_INPUT_NDOF /* let NDOF motion pass through to the 3D view so we can paint and rotate simultaneously! * this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index c4c9db69dcd..6e99edcf682 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -2784,6 +2784,20 @@ static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat invert_m4_m4(local_mat, tmat); } +#define SCULPT_TILT_SENSITIVITY 0.7f +void SCULPT_tilt_apply_to_normal(float r_normal[3], StrokeCache *cache, const float tilt_strength) +{ + if (!U.experimental.use_sculpt_tools_tilt) { + return; + } + const float rot_max = M_PI_2 * tilt_strength * SCULPT_TILT_SENSITIVITY; + mul_v3_mat3_m4v3(r_normal, cache->vc->obact->obmat, r_normal); + rotate_v3_v3v3fl(r_normal, r_normal, cache->vc->rv3d->viewinv[0], cache->y_tilt * rot_max); + rotate_v3_v3v3fl(r_normal, r_normal, cache->vc->rv3d->viewinv[1], cache->x_tilt * rot_max); + mul_v3_mat3_m4v3(r_normal, cache->vc->obact->imat, r_normal); + normalize_v3(r_normal); +} + static void update_brush_local_mat(Sculpt *sd, Object *ob) { StrokeCache *cache = ob->sculpt->cache; @@ -3094,6 +3108,7 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) /* Offset with as much as possible factored in already. */ mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); + SCULPT_tilt_apply_to_normal(offset, ss->cache, brush->tilt_strength_factor); mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); @@ -3171,6 +3186,7 @@ static void do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to /* Offset with as much as possible factored in already. */ mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); + SCULPT_tilt_apply_to_normal(offset, ss->cache, brush->tilt_strength_factor); mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); @@ -4693,6 +4709,8 @@ static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co); + SCULPT_tilt_apply_to_normal(area_no, ss->cache, brush->tilt_strength_factor); + displace = radius * offset; mul_v3_v3v3(temp, area_no, ss->cache->scale); @@ -4977,6 +4995,7 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t float tmat[4][4]; SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no_sp, area_co); + SCULPT_tilt_apply_to_normal(area_no_sp, ss->cache, brush->tilt_strength_factor); if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) { SCULPT_calc_area_normal(sd, ob, nodes, totnode, area_no); @@ -5120,6 +5139,8 @@ static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co); + SCULPT_tilt_apply_to_normal(area_no, ss->cache, brush->tilt_strength_factor); + displace = radius * offset; mul_v3_v3v3(temp, area_no, ss->cache->scale); @@ -5213,6 +5234,8 @@ static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co); + SCULPT_tilt_apply_to_normal(area_no, ss->cache, brush->tilt_strength_factor); + displace = -radius * offset; mul_v3_v3v3(temp, area_no, ss->cache->scale); @@ -6935,6 +6958,9 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, Po cache->pressure = RNA_float_get(ptr, "pressure"); } + cache->x_tilt = RNA_float_get(ptr, "x_tilt"); + cache->y_tilt = RNA_float_get(ptr, "y_tilt"); + /* Truly temporary data that isn't stored in properties. */ if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(ss->cache)) { if (!BKE_brush_use_locked_size(scene, brush)) { diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 41982a441ad..6cdaafb548c 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -799,6 +799,11 @@ float SCULPT_brush_strength_factor(struct SculptSession *ss, const int vertex_index, const int thread_id); +/* Tilts a normal by the x and y tilt values using the view axis. */ +void SCULPT_tilt_apply_to_normal(float r_normal[3], + struct StrokeCache *cache, + const float tilt_strength); + /* just for vertex paint. */ bool SCULPT_pbvh_calc_area_normal(const struct Brush *brush, Object *ob, @@ -852,6 +857,8 @@ typedef struct StrokeCache { float mouse[2]; float bstrength; float normal_weight; /* from brush (with optional override) */ + float x_tilt; + float y_tilt; float (*prev_colors)[4]; |