diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index e19756c6a35..1a12ec3e6bc 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -524,38 +524,45 @@ static int project_brush_radius(ViewContext *vc, static bool sculpt_get_brush_geometry( bContext *C, ViewContext *vc, int x, int y, int *pixel_radius, - float location[3]) + float location[3], UnifiedPaintSettings *ups) { Scene *scene = CTX_data_scene(C); Paint *paint = BKE_paint_get_active_from_context(C); float mouse[2]; - bool hit; + bool hit = false; mouse[0] = x; mouse[1] = y; - if (vc->obact->sculpt && vc->obact->sculpt->pbvh && - sculpt_stroke_get_location(C, location, mouse)) + if (vc->obact->sculpt && vc->obact->sculpt->pbvh) { + if (!ups->stroke_active) { + hit = sculpt_stroke_get_location(C, location, mouse); + } + else { + hit = ups->last_hit; + copy_v3_v3(location, ups->last_location); + } + } + + if (hit) { Brush *brush = BKE_paint_brush(paint); + *pixel_radius = - project_brush_radius(vc, - BKE_brush_unprojected_radius_get(scene, brush), - location); + project_brush_radius(vc, + BKE_brush_unprojected_radius_get(scene, brush), + location); if (*pixel_radius == 0) *pixel_radius = BKE_brush_size_get(scene, brush); mul_m4_v3(vc->obact->obmat, location); - - hit = 1; } else { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); *pixel_radius = BKE_brush_size_get(scene, brush); - hit = 0; } return hit; @@ -1020,7 +1027,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) bool hit; /* test if brush is over the mesh */ - hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location); + hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups); if (BKE_brush_use_locked_size(scene, brush)) BKE_brush_size_set(scene, brush, pixel_radius); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index db6ee705343..3225d4d4b7e 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -466,7 +466,10 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float copy_v2_v2(mouse_out, mouse_in); } - if (!paint_brush_update(C, brush, mode, stroke, mouse_in, mouse_out, pressure, location)) { + + ups->last_hit = paint_brush_update(C, brush, mode, stroke, mouse_in, mouse_out, pressure, location); + copy_v3_v3(ups->last_location, location); + if (!ups->last_hit) { return; } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 2d0a4820a51..5e3dc6f648d 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1133,6 +1133,10 @@ typedef struct UnifiedPaintSettings { char draw_anchored; char do_linear_conversion; + /* store last location of stroke or whether the mesh was hit. Valid only while stroke is active */ + float last_location[3]; + int last_hit; + float anchored_initial_mouse[2]; /* radius of brush, premultiplied with pressure.