[Bf-blender-cvs] [5855c23a645] greasepencil-object: Tweak missing event algorithm for extreme zoom

Antonio Vazquez noreply at git.blender.org
Fri Mar 2 11:26:15 CET 2018


Commit: 5855c23a6452e59762cccafb7d94f62ce2206e30
Author: Antonio Vazquez
Date:   Fri Mar 2 11:26:04 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB5855c23a6452e59762cccafb7d94f62ce2206e30

Tweak missing event algorithm for extreme zoom

Due int number limitations, when the zoom factor is extreme, the points are captured with gaps. This change try to minimize this effect, but it's impossible to solve this issue completely.

The problem is the mouse position is always defined by a pair of int number, so the maximum precision is limited to that, so when project the point in 3D space, there are small precission erros.

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

M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 38ed0aa20bf..e9f2f1c5155 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -2666,22 +2666,31 @@ static void gpencil_add_missing_events(bContext *C, wmOperator *op, const wmEven
 	else {
 		scale = defaultpixsize;
 	}
+
+	/* The thickness of the brush is reduced at 30 % of thickness to get overlap dots */ 
 	float factor = ((thickness * 0.30f) / scale) * samples;
 
-	/* get distance to generate new points. The thickness of the brush is reduced at 30% of
-	 * thickness to get overlap dots */
 	copy_v2fl_v2i(a, p->mvalo);
 	b[0] = event->mval[0] + 1;
 	b[1] = event->mval[1] + 1;
 
+	/* get distance in pixels */
 	float dist = len_v2v2(a, b);
-	if (dist >= factor) {
+
+	/* for very small distances, add a half way point */
+	if (dist < 2.0f) {
+		interp_v2_v2v2(pt, a, b, 0.5f);
+		sub_v2_v2v2(pt, b, pt);
+		/* create fake event */
+		gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C),
+			(int)pt[0], (int)pt[1]);
+	}
+	else if (dist >= factor) {
 		int slices = 2 + (int)((dist - 1.0) / factor);
 		float n = 1.0f / slices;
 		for (int i = 1; i < slices; i++) {
 			interp_v2_v2v2(pt, a, b, n * i);
 			sub_v2_v2v2(pt, b, pt);
-
 			/* create fake event */
 			gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C),
 									(int)pt[0], (int)pt[1]);



More information about the Bf-blender-cvs mailing list