Sculpting optimization: Avoid iterating the PBVH for intersection during

the paint cursor drawing when a stroke is underway; this information is
already available from the stroke itself.

Should improve performance when "show brush" is enabled (which is
always, for sane people). Finding an intersection is not always cheap,
especially on heavy meshes.

Cudos to the dyntopo test thread for the report and the sculpt love :)
This commit is contained in:
Antonis Ryakiotakis 2015-11-24 21:40:18 +01:00
parent fe3aaac118
commit 697acebeb7
3 changed files with 26 additions and 12 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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.