[Bf-blender-cvs] [697aceb] master: 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.

Antony Riakiotakis noreply at git.blender.org
Tue Nov 24 21:41:19 CET 2015


Commit: 697acebeb7f61ece1bd17d129d424b3f470438ba
Author: Antony Riakiotakis
Date:   Tue Nov 24 21:40:18 2015 +0100
Branches: master
https://developer.blender.org/rB697acebeb7f61ece1bd17d129d424b3f470438ba

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 :)

===================================================================

M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/makesdna/DNA_scene_types.h

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index e19756c..1a12ec3 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 db6ee70..3225d4d 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 2d0a482..5e3dc6f 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.




More information about the Bf-blender-cvs mailing list