[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34619] trunk/blender/source/blender: fix [#25684] Grease pencil strokes with "Surface" option attach erratically to curves.

Campbell Barton ideasman42 at gmail.com
Wed Feb 2 04:33:00 CET 2011


Revision: 34619
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34619
Author:   campbellbarton
Date:     2011-02-02 03:32:58 +0000 (Wed, 02 Feb 2011)
Log Message:
-----------
fix [#25684] Grease pencil strokes with "Surface" option attach erratically to curves.
added new functions
- view_autodist_depth_segment()
- plot_line_v2v2i(), which takes a callback and plots x/y points.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2011-02-02 03:12:39 UTC (rev 34618)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2011-02-02 03:32:58 UTC (rev 34619)
@@ -120,6 +120,8 @@
 
 int clip_line_plane(float clipco[3], float plane[4], float co[3]);
 
+void plot_line_v2v2i(int p1[2], int p2[2], int (*callback)(int, int, void *), void *userData);
+
 /****************************** Interpolation ********************************/
 
 /* tri or quad, d can be NULL */

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2011-02-02 03:12:39 UTC (rev 34618)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2011-02-02 03:32:58 UTC (rev 34619)
@@ -1358,6 +1358,71 @@
 	}
 }
 
+
+void plot_line_v2v2i(int p1[2], int p2[2], int (*callback)(int, int, void *), void *userData)
+{
+	int x1= p1[0];
+	int y1= p1[1];
+	int x2= p2[0];
+	int y2= p2[1];
+
+	signed char ix;
+	signed char iy;
+
+	// if x1 == x2 or y1 == y2, then it does not matter what we set here
+	int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1;
+	int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1;
+
+	if(callback(x1, y1, userData) == 0) {
+		return;
+	}
+
+	if (delta_x >= delta_y) {
+		// error may go below zero
+		int error = delta_y - (delta_x >> 1);
+
+		while (x1 != x2) {
+			if (error >= 0) {
+				if (error || (ix > 0)) {
+					y1 += iy;
+					error -= delta_x;
+				}
+				// else do nothing
+			}
+			// else do nothing
+
+			x1 += ix;
+			error += delta_y;
+
+			if(callback(x1, y1, userData) == 0) {
+				return ;
+			}
+		}
+	}
+	else {
+		// error may go below zero
+		int error = delta_x - (delta_y >> 1);
+
+		while (y1 != y2) {
+			if (error >= 0) {
+				if (error || (iy > 0)) {
+					x1 += ix;
+					error -= delta_y;
+				}
+				// else do nothing
+			}
+			// else do nothing
+
+			y1 += iy;
+			error += delta_x;
+
+			if(callback(x1, y1, userData) == 0) {
+				return;
+			}
+		}
+	}
+}
+
 /****************************** Interpolation ********************************/
 
 static float tri_signed_area(float *v1, float *v2, float *v3, int i, int j)
@@ -2566,4 +2631,3 @@
 
 	return contrib;
 }
-

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-02-02 03:12:39 UTC (rev 34618)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-02-02 03:32:58 UTC (rev 34619)
@@ -547,18 +547,25 @@
 		
 		/* get an array of depths, far depths are blended */
 		if (gpencil_project_check(p)) {
-			short mval[2];
+			short mval[2], mval_prev[2]= {0};
 			int interp_depth = 0;
 			int found_depth = 0;
 			
 			depth_arr= MEM_mallocN(sizeof(float) * gpd->sbuffer_size, "depth_points");
-			
+
 			for (i=0, ptc=gpd->sbuffer; i < gpd->sbuffer_size; i++, ptc++, pt++) {
 				mval[0]= ptc->x; mval[1]= ptc->y;
-				if (view_autodist_depth(p->ar, mval, depth_margin, depth_arr+i) == 0)
+
+				if ((view_autodist_depth(p->ar, mval, depth_margin, depth_arr+i) == 0) &&
+					(i && (view_autodist_depth_segment(p->ar, mval, mval_prev, depth_margin + 1, depth_arr+i) == 0))
+				) {
 					interp_depth= TRUE;
-				else
+				}
+				else {
 					found_depth= TRUE;
+				}
+
+				VECCOPY2D(mval_prev, mval);
 			}
 			
 			if (found_depth == FALSE) {

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2011-02-02 03:12:39 UTC (rev 34618)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2011-02-02 03:32:58 UTC (rev 34619)
@@ -136,8 +136,9 @@
 
 /* only draw so view_autodist_simple can be called many times after */
 int view_autodist_init(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode);
-int view_autodist_simple(struct ARegion *ar, short *mval, float mouse_worldloc[3], int margin, float *force_depth);
-int view_autodist_depth(struct ARegion *ar, short *mval, int margin, float *depth);
+int view_autodist_simple(struct ARegion *ar, short mval[2], float mouse_worldloc[3], int margin, float *force_depth);
+int view_autodist_depth(struct ARegion *ar, short mval[2], int margin, float *depth);
+int view_autodist_depth_segment(struct ARegion *ar, short mval_sta[2], short mval_end[2], int margin, float *depth);
 
 /* select */
 #define MAXPICKBUF      10000

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-02-02 03:12:39 UTC (rev 34618)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-02-02 03:32:58 UTC (rev 34619)
@@ -2622,7 +2622,7 @@
 /* ************************* below the line! *********************** */
 
 
-static float view_autodist_depth_margin(ARegion *ar, short *mval, int margin)
+static float view_autodist_depth_margin(ARegion *ar, short mval[2], int margin)
 {
 	ViewDepths depth_temp= {0};
 	rcti rect;
@@ -2721,14 +2721,53 @@
 	return 1;
 }
 
-int view_autodist_depth(struct ARegion *ar, short *mval, int margin, float *depth)
+int view_autodist_depth(struct ARegion *ar, short mval[2], int margin, float *depth)
 {
 	*depth= view_autodist_depth_margin(ar, mval, margin);
 
 	return (*depth==FLT_MAX) ? 0:1;
+}
+
+static int depth_segment_cb(int x, int y, void *userData)
+{
+	struct { struct ARegion *ar; int margin; float depth; } *data = userData;
+	short mval[2];
+	float depth;
+
+	mval[0]= (short)x;
+	mval[1]= (short)y;
+
+	depth= view_autodist_depth_margin(data->ar, mval, data->margin);
+
+	if(depth != FLT_MAX) {
+		data->depth= depth;
 		return 0;
+	}
+	else {
+		return 1;
+	}
 }
 
+int view_autodist_depth_segment(struct ARegion *ar, short mval_sta[2], short mval_end[2], int margin, float *depth)
+{
+	struct { struct ARegion *ar; int margin; float depth; } data = {0};
+	int p1[2];
+	int p2[2];
+
+	data.ar= ar;
+	data.margin= margin;
+	data.depth= FLT_MAX;
+
+	VECCOPY2D(p1, mval_sta);
+	VECCOPY2D(p2, mval_end);
+
+	plot_line_v2v2i(p1, p2, depth_segment_cb, &data);
+
+	*depth= data.depth;
+
+	return (*depth==FLT_MAX) ? 0:1;
+}
+
 /* ********************* NDOF ************************ */
 /* note: this code is confusing and unclear... (ton) */
 /* **************************************************** */




More information about the Bf-blender-cvs mailing list