[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16222] trunk/blender/source/blender: Grease Pencil: WIP commit (nothing new)

Joshua Leung aligorith at gmail.com
Fri Aug 22 10:36:31 CEST 2008


Revision: 16222
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16222
Author:   aligorith
Date:     2008-08-22 10:36:29 +0200 (Fri, 22 Aug 2008)

Log Message:
-----------
Grease Pencil: WIP commit (nothing new)

Just a little commit so that I can transfer some changes back over to laptop. 
* Line drawing should now be improved for most cases, but acute angles still need more work to reduce 'shrinking' artifacts. As such, this is still hidden behind 'rt' setting
* Preparation work for Grease-Pencil in Image Editor, and also 'Stick to View' for Image/Sequence editors.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BDR_gpencil.h
    trunk/blender/source/blender/include/BIF_drawgpencil.h
    trunk/blender/source/blender/makesdna/DNA_gpencil_types.h
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/src/drawgpencil.c
    trunk/blender/source/blender/src/gpencil.c

Modified: trunk/blender/source/blender/include/BDR_gpencil.h
===================================================================
--- trunk/blender/source/blender/include/BDR_gpencil.h	2008-08-22 06:02:01 UTC (rev 16221)
+++ trunk/blender/source/blender/include/BDR_gpencil.h	2008-08-22 08:36:29 UTC (rev 16222)
@@ -43,7 +43,6 @@
 /* Temporary 'Stroke Point' data */
 typedef struct tGPspoint {
 	short x, y;				/* x and y coordinates of cursor (in relative to area) */
-	float xf, yf;			/* same as x and y, but as floats */
 	float pressure;			/* pressure of tablet at this point */
 } tGPspoint;
 

Modified: trunk/blender/source/blender/include/BIF_drawgpencil.h
===================================================================
--- trunk/blender/source/blender/include/BIF_drawgpencil.h	2008-08-22 06:02:01 UTC (rev 16221)
+++ trunk/blender/source/blender/include/BIF_drawgpencil.h	2008-08-22 08:36:29 UTC (rev 16222)
@@ -28,15 +28,18 @@
 #ifndef BIF_DRAWGPENCIL_H
 #define BIF_DRAWGPENCIL_H
 
+
+struct bGPdata;
 struct ScrArea;
 struct View3D;
 struct SpaceNode;
 struct SpaceSeq;
-struct bGPdata;
 struct uiBlock;
+struct ImBuf;
 
 short draw_gpencil_panel(struct uiBlock *block, struct bGPdata *gpd, struct ScrArea *sa); 
 
+void draw_gpencil_2dimage(struct ScrArea *sa, struct ImBuf *ibuf);
 void draw_gpencil_2dview(struct ScrArea *sa, short onlyv2d);
 void draw_gpencil_3dview(struct ScrArea *sa, short only3d);
 void draw_gpencil_oglrender(struct View3D *v3d, int winx, int winy);

Modified: trunk/blender/source/blender/makesdna/DNA_gpencil_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_gpencil_types.h	2008-08-22 06:02:01 UTC (rev 16221)
+++ trunk/blender/source/blender/makesdna/DNA_gpencil_types.h	2008-08-22 08:36:29 UTC (rev 16222)
@@ -59,8 +59,10 @@
 #define GP_STROKE_3DSPACE		(1<<0)
 	/* stroke is in 2d-space */
 #define GP_STROKE_2DSPACE		(1<<1)
+	/* stroke is in 2d-space (but with special 'image' scaling) */
+#define GP_STROKE_2DIMAGE		(1<<2)
 	/* stroke is an "eraser" stroke */
-#define GP_STROKE_ERASER		(1<<2)
+#define GP_STROKE_ERASER		(1<<15)
 
 
 /* Grease-Pencil Annotations - 'Frame'

Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h	2008-08-22 06:02:01 UTC (rev 16221)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h	2008-08-22 08:36:29 UTC (rev 16222)
@@ -247,6 +247,7 @@
 	float xof, yof;					/* user defined offset, image is centered */
 	float centx, centy;				/* storage for offset while render drawing */
 	
+	struct bGPdata *gpd;			/* grease pencil data */
 } SpaceImage;
 
 typedef struct SpaceNla {

Modified: trunk/blender/source/blender/src/drawgpencil.c
===================================================================
--- trunk/blender/source/blender/src/drawgpencil.c	2008-08-22 06:02:01 UTC (rev 16221)
+++ trunk/blender/source/blender/src/drawgpencil.c	2008-08-22 08:36:29 UTC (rev 16222)
@@ -37,6 +37,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
 #include "BMF_Api.h"
 
 #include "BLI_arithb.h"
@@ -317,6 +320,7 @@
 	GP_DRAWDATA_NOSTATUS 	= (1<<0),	/* don't draw status info */
 	GP_DRAWDATA_ONLY3D		= (1<<1),	/* only draw 3d-strokes */
 	GP_DRAWDATA_ONLYV2D		= (1<<2),	/* only draw 'canvas' strokes */
+	GP_DRAWDATA_ONLYI2D		= (1<<3),	/* only draw 'image' strokes */
 };
 
 /* ----- Tool Buffer Drawing ------ */
@@ -466,18 +470,22 @@
 	}
 	else { /* tesselation code: currently only enabled with rt != 0 */
 		bGPDspoint *pt1, *pt2;
-		float p0[2], p1[2], pm[2];
+		float pm[2];
 		int i;
+		short n;
 		
 		glShadeModel(GL_FLAT);
-		glBegin(GL_QUAD_STRIP);
 		
+		glPointSize(3.0f); // temp
+		
+		for (n= 0; n < 2; n++) { // temp
+		glBegin((n)?GL_POINTS:GL_QUADS);
+		
 		for (i=0, pt1=points, pt2=points+1; i < (totpoints-1); i++, pt1++, pt2++) {
 			float s0[2], s1[2];		/* segment 'center' points */
 			float t0[2], t1[2];		/* tesselated coordinates */
 			float m1[2], m2[2];		/* gradient and normal */
-			float pthick, dist;		/* thickness at segment point, and length of segment */
-			float sminorang;		/* minor angle between strokes */
+			float pthick;			/* thickness at segment point */
 			
 			/* get x and y coordinates from points */
 			if (sflag & GP_STROKE_2DSPACE) {
@@ -494,94 +502,74 @@
 			/* calculate gradient and normal - 'angle'=(ny/nx) */
 			m1[1]= s1[1] - s0[1];		
 			m1[0]= s1[0] - s0[0];
-			dist = Vec2Lenf(s0, s1);
-			m2[1]= -(m1[0]) / dist;
-			m2[0]= m1[1] / dist;
+			m2[1]= -m1[0];
+			m2[0]= m1[1];
+			Normalize2(m2);
 			
-			/* if the first segment, initialise the first segment using segment's normal */
-			if (i == 0) {	
-				pthick= (pt1->pressure * thickness);
-				
+			/* always use pressure from first point here */
+			pthick= (pt1->pressure * thickness);
+			
+			/* if the first segment, start of segment is segment's normal */
+			if (i == 0) {
 				// TODO: also draw/do a round end-cap first
 				
-				p0[0]= s0[0] - (pthick * m2[0]);
-				p0[1]= s0[1] - (pthick * m2[1]);
-				p1[0]= s1[0] + (pthick * m2[0]);
-				p1[1]= s1[1] + (pthick * m2[1]);
+				/* calculate points for start of segment */
+				t0[0]= s0[0] - (pthick * m2[0]);
+				t0[1]= s0[1] - (pthick * m2[1]);
+				t1[0]= s0[0] + (pthick * m2[0]);
+				t1[1]= s0[1] + (pthick * m2[1]);
 				
-				Vec2Copyf(pm, m1);
+				/* draw this line only once */
+				glVertex2fv(t0);
+				glVertex2fv(t1);
 			}
-			
-			/* if the minor angle between the current segment and the previous one is less than 90 degrees */
-			if (i)
-				sminorang= NormalizedVecAngle2_2D(pm, m1);
-			else
-				sminorang= 0.0f;
-			
-			if ((IS_EQ(sminorang, 0)==0) && (abs(sminorang) < M_PI_2) ) 
-			{
-				float closep[2];
+			/* if not the first segment, use bisector of angle between segments */
+			else {
+				float mb[2]; 	/* bisector normal */
 				
-				/* recalculate startpoint of segment, where the new start-line:
-				 * 	- starts a new gl-quad-strip
-				 *	- uses the vert of old startpoint closer to our endpoint
-				 *	- distance between new startpoints = distance between old startpoints
-				 *	- new startpoints occur on same gradient as old segment does (has potential for some 'minor' overlap, but ok)
-				 */
+				/* calculate gradient of bisector (as average of normals) */
+				mb[0]= (pm[0] + m2[0]) / 2;
+				mb[1]= (pm[1] + m2[1]) / 2;
+				Normalize2(mb);
 				
-				/* find the closer vertex, and distance between startpoints */
-				if (Vec2Lenf(p0, s1) > Vec2Lenf(p1, s1))
-					Vec2Copyf(closep, p1);
-				else
-					Vec2Copyf(closep, p0);
-					
-				/* determine which side this closer vertex should be on */
-				pthick= (pt1->pressure * thickness * 2);
-				if ( ((closep[0] - s0[0]) > 0) || ((closep[1] - s0[1]) > 0) ) {
-					/* assumes this is the 'second' point, (i.e. the 'plus' one), so the other is subtracting */
-					p0[0]= closep[0] - (pthick * pm[0]);
-					p0[1]= closep[1] - (pthick * pm[1]);
-					p1[0]= closep[0];
-					p1[1]= closep[1];
-				}
-				else if ( ((closep[0] - s0[0]) < 0) || ((closep[1] - s0[1]) < 0) ) {
-					/* assumes this is the 'first' point, (i.e. the 'minus' one), so the other is adding */
-					p0[0]= closep[0];
-					p0[1]= closep[1];
-					p1[0]= closep[0] + (pthick * pm[0]);
-					p1[1]= closep[1] + (pthick * pm[1]);
-				}
+				/* calculate points for start of segment */
+				// FIXME: do we need extra padding for acute angles?
+				t0[0]= s0[0] - (pthick * mb[0]);
+				t0[1]= s0[1] - (pthick * mb[1]);
+				t1[0]= s0[0] + (pthick * mb[0]);
+				t1[1]= s0[1] + (pthick * mb[1]);
 				
-				/* reset gl-states! */
-				glEnd();
-				glBegin(GL_QUAD_STRIP);				
+				/* draw this line twice (once for end of current segment, and once for start of next) */
+				glVertex2fv(t1);
+				glVertex2fv(t0);
+				glVertex2fv(t0);
+				glVertex2fv(t1);
 			}
 			
-			/* do the end of this segment */
-			pthick= (pt2->pressure * thickness);
-			t0[0] = s1[0] - (pthick * m2[0]);
-			t0[1] = s1[1] - (pthick * m2[1]);
-			t1[0] = s1[0] + (pthick * m2[0]);
-			t1[1] = s1[1] + (pthick * m2[1]);
-			
-			/* draw this segment */
-			glVertex2f(p0[0], p0[1]);
-			glVertex2f(p1[0], p1[1]);
-			glVertex2f(t0[0], t0[1]);
-			glVertex2f(t1[0], t1[1]);
-			
-			// TODO: draw end cap if last segment
+			/* if last segment, also draw end of segment (defined as segment's normal) */
 			if (i == totpoints-2) {
-			
+				/* for once, we use second point's pressure (otherwise it won't be drawn) */
+				pthick= (pt2->pressure * thickness);
+				
+				/* calculate points for end of segment */
+				t0[0]= s1[0] - (pthick * m2[0]);
+				t0[1]= s1[1] - (pthick * m2[1]);
+				t1[0]= s1[0] + (pthick * m2[0]);
+				t1[1]= s1[1] + (pthick * m2[1]);
+				
+				/* draw this line only once */
+				glVertex2fv(t1);
+				glVertex2fv(t0);
+				
+				// TODO: draw end cap as last step 
 			}
 			
-			/* store current points for next segment to use */
-			Vec2Copyf(p0, t0);
-			Vec2Copyf(p1, t1);
-			Vec2Copyf(pm, m1);
+			/* store stroke's 'natural' normal for next stroke to use */
+			Vec2Copyf(pm, m2);
 		}
 		
 		glEnd();
+		}
 	}
 	
 	/* draw debug points of curve on top? (original stroke points) */
@@ -626,6 +614,10 @@
 			continue;
 		if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE))
 			continue;
+		if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE))
+			continue;
+		if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE))
+			continue;
 		if ((gps->points == 0) || (gps->totpoints < 1))
 			continue;
 		
@@ -796,6 +788,22 @@
 
 /* ----- Grease Pencil Sketches Drawing API ------ */
 
+/* draw grease-pencil sketches to specified 2d-view that uses ibuf corrections */
+void draw_gpencil_2dimage (ScrArea *sa, ImBuf *ibuf)
+{
+	bGPdata *gpd;
+	int dflag = 0;
+	
+	/* check that we have grease-pencil stuff to draw */
+	if (ELEM(NULL, sa, ibuf)) return;
+	gpd= gpencil_data_getactive(sa);
+	if (gpd == NULL) return;
+	
+	/* draw it! */
+	dflag = (GP_DRAWDATA_ONLYI2D|GP_DRAWDATA_NOSTATUS);
+	gp_draw_data(gpd, sa->winx, sa->winy, dflag);
+}
+
 /* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly 
  * Note: this gets called twice - first time with onlyv2d=1 to draw 'canvas' strokes, second time with onlyv2d=0 for screen-aligned strokes
  */

Modified: trunk/blender/source/blender/src/gpencil.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list