[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22907] branches/blender2.5/blender/source /blender/editors: Grease Pencil: Cleanup Work + Bugfixes

Joshua Leung aligorith at gmail.com
Mon Aug 31 06:24:29 CEST 2009


Revision: 22907
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22907
Author:   aligorith
Date:     2009-08-31 06:24:28 +0200 (Mon, 31 Aug 2009)

Log Message:
-----------
Grease Pencil: Cleanup Work + Bugfixes

* Disabled temporary debugging prints, since event handling now seems stable

* Modified the initgrabz() code so that when the cursor is behind the viewplane, the z-factor is calculated as if the cursor was on the other side of the view plane. This seems to work well, and doesn't seem to have any negative side-effects (yet).

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c

Modified: branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c	2009-08-31 03:36:02 UTC (rev 22906)
+++ branches/blender2.5/blender/source/blender/editors/gpencil/gpencil_paint.c	2009-08-31 04:24:28 UTC (rev 22907)
@@ -86,6 +86,7 @@
 	} im2d_settings;	/* needed for GP_STROKE_2DIMAGE */
 #endif
 	
+	PointerRNA ownerPtr;/* pointer to owner of gp-datablock */
 	bGPdata *gpd;		/* gp-datablock layer comes from */
 	bGPDlayer *gpl;		/* layer we're working on */
 	bGPDframe *gpf;		/* frame we're working on */
@@ -153,6 +154,29 @@
 /* ******************************************* */
 /* Calculations/Conversions */
 
+/* Utilities --------------------------------- */
+
+/* get the reference point for stroke-point conversions */
+static void gp_get_3d_reference (tGPsdata *p, float *vec)
+{
+	View3D *v3d= p->sa->spacedata.first;
+	float *fp= give_cursor(p->scene, v3d);
+	
+	/* the reference point used depends on the owner... */
+	if (p->ownerPtr.type == &RNA_Object) {
+		Object *ob= (Object *)p->ownerPtr.data;
+		
+		/* active Object 
+		 * 	- use relative distance of 3D-cursor from object center 
+		 */
+		VecSubf(vec, fp, ob->loc);
+	}
+	else {
+		/* use 3D-cursor */
+		VecCopyf(vec, fp);
+	}
+}
+
 /* Stroke Editing ---------------------------- */
 
 /* check if the current mouse position is suitable for adding a new point */
@@ -187,10 +211,8 @@
 	
 	/* in 3d-space - pt->x/y/z are 3 side-by-side floats */
 	if (gpd->sbuffer_sflag & GP_STROKE_3DSPACE) {
-		View3D *v3d= p->sa->spacedata.first;
 		const short mx=mval[0], my=mval[1];
-		float *fp= give_cursor(p->scene, v3d);
-		float dvec[3];
+		float rvec[3], dvec[3];
 		
 		/* Current method just converts each point in screen-coordinates to 
 		 * 3D-coordinates using the 3D-cursor as reference. In general, this 
@@ -201,11 +223,12 @@
 		 *	  reference point instead or as offset, for easier stroke matching
 		 *	- investigate projection onto geometry (ala retopo)
 		 */
+		gp_get_3d_reference(p, rvec);
 		
 		/* method taken from editview.c - mouse_cursor() */
-		project_short_noclip(p->ar, fp, mval);
+		project_short_noclip(p->ar, rvec, mval);
 		window_to_3d_delta(p->ar, dvec, mval[0]-mx, mval[1]-my);
-		VecSubf(out, fp, dvec);
+		VecSubf(out, rvec, dvec);
 	}
 	
 	/* 2d - on 'canvas' (assume that p->v2d is set) */
@@ -831,7 +854,7 @@
 #endif
 		case SPACE_IMAGE:
 		{
-			SpaceImage *sima= curarea->spacedata.first;
+			//SpaceImage *sima= curarea->spacedata.first;
 			
 			/* set the current area */
 			p->sa= curarea;
@@ -863,7 +886,7 @@
 	}
 	
 	/* get gp-data */
-	gpd_ptr= gpencil_data_get_pointers(C, NULL);
+	gpd_ptr= gpencil_data_get_pointers(C, &p->ownerPtr);
 	if (gpd_ptr == NULL) {
 		p->status= GP_STATUS_ERROR;
 		if (G.f & G_DEBUG)
@@ -951,13 +974,11 @@
 		switch (p->sa->spacetype) {
 			case SPACE_VIEW3D:
 			{
-				View3D *v3d= (View3D *)p->sa->spacedata.first;
 				RegionView3D *rv3d= p->ar->regiondata;
+				float rvec[3];
 				
-				// TODO 1: when using objects, make the data stick to the object centers?
-				// TODO 2: what happens when cursor is behind view-camera plane?
-				float *fp= give_cursor(p->scene, v3d);
-				initgrabz(rv3d, fp[0], fp[1], fp[2]);
+				gp_get_3d_reference(p, rvec);
+				initgrabz(rv3d, rvec[0], rvec[1], rvec[2]);
 				
 				p->gpd->sbuffer_sflag |= GP_STROKE_3DSPACE;
 			}
@@ -1215,18 +1236,18 @@
 {
 	tGPsdata *p = NULL;
 	
-	printf("GPencil - Starting Re-Drawing \n");
+	//printf("GPencil - Starting Re-Drawing \n");
 	
 	/* try to initialise context data needed while drawing */
 	if (!gpencil_draw_init(C, op)) {
 		if (op->customdata) MEM_freeN(op->customdata);
-		printf("\tGP - no valid data \n");
+		//printf("\tGP - no valid data \n");
 		return OPERATOR_CANCELLED;
 	}
 	else
 		p= op->customdata;
 	
-	printf("\tGP - Start redrawing stroke \n");
+	//printf("\tGP - Start redrawing stroke \n");
 	
 	/* loop over the stroke RNA elements recorded (i.e. progress of mouse movement),
 	 * setting the relevant values in context at each step, then applying
@@ -1235,7 +1256,7 @@
 	{
 		float mousef[2];
 		
-		printf("\t\tGP - stroke elem \n");
+		//printf("\t\tGP - stroke elem \n");
 		
 		/* get relevant data for this point from stroke */
 		RNA_float_get_array(&itemptr, "mouse", mousef);
@@ -1257,7 +1278,7 @@
 	}
 	RNA_END;
 	
-	printf("\tGP - done \n");
+	//printf("\tGP - done \n");
 	
 	/* cleanup */
 	gpencil_draw_exit(C, op);
@@ -1277,7 +1298,7 @@
 	tGPsdata *p = NULL;
 	wmWindow *win= CTX_wm_window(C);
 	
-	printf("GPencil - Starting Drawing \n");
+	//printf("GPencil - Starting Drawing \n");
 	
 	/* try to initialise context data needed while drawing */
 	if (!gpencil_draw_init(C, op)) {
@@ -1308,7 +1329,7 @@
 	 */
 	if (event->type) {
 		/* hotkey invoked - start drawing */
-		printf("\tGP - set first spot\n");
+		//printf("\tGP - set first spot\n");
 		p->status= GP_STATUS_PAINTING;
 		
 		/* handle the initial drawing - i.e. for just doing a simple dot */
@@ -1316,7 +1337,7 @@
 	}
 	else {
 		/* toolbar invoked - don't start drawing yet... */
-		printf("\tGP - hotkey invoked... waiting for click-drag\n");
+		//printf("\tGP - hotkey invoked... waiting for click-drag\n");
 	}
 	
 	/* add a modal handler for this operator, so that we can then draw continuous strokes */
@@ -1329,7 +1350,7 @@
 {
 	tGPsdata *p= op->customdata;
 	
-	printf("\tGP - handle modal event...\n");
+	//printf("\tGP - handle modal event...\n");
 	
 	switch (event->type) {
 		/* end of stroke -> ONLY when a mouse-button release occurs 
@@ -1340,7 +1361,7 @@
 			/* if painting, end stroke */
 			if (p->status == GP_STATUS_PAINTING) {
 				/* basically, this should be mouse-button up */
-				printf("\t\tGP - end of stroke \n");
+				//printf("\t\tGP - end of stroke \n");
 				gpencil_draw_exit(C, op);
 				
 				/* one last flush before we're done */
@@ -1350,7 +1371,7 @@
 			}
 			else {
 				/* not painting, so start stroke (this should be mouse-button down) */
-				printf("\t\tGP - start stroke \n");
+				//printf("\t\tGP - start stroke \n");
 				p->status= GP_STATUS_PAINTING;
 				/* no break now, since we should immediately start painting */
 			}
@@ -1360,31 +1381,20 @@
 			/* check if we're currently painting */
 			if (p->status == GP_STATUS_PAINTING) {
 				/* handle drawing event */
-				printf("\t\tGP - add point\n");
+				//printf("\t\tGP - add point\n");
 				gpencil_draw_apply_event(C, op, event);
 				
 				/* finish painting operation if anything went wrong just now */
 				if (p->status == GP_STATUS_ERROR) {
-					printf("\t\t\tGP - error done! \n");
+					//printf("\t\t\tGP - error done! \n");
 					gpencil_draw_exit(C, op);
 					return OPERATOR_CANCELLED;
 				}
 			}
 			break;
 		
-		/* scrolling mouse-wheel increases radius of eraser 
-		 * 	- though this is quite a difficult action to perform
-		 */
-		// XXX this stuff doesn't work
-		case WHEELUPMOUSE:
-			p->radius += 1.5f;
-			break;
-		case WHEELDOWNMOUSE:
-			p->radius -= 1.5f;
-			break;
-		
 		default:
-			printf("\t\tGP unknown event - %d \n", event->type);
+			//printf("\t\tGP unknown event - %d \n", event->type);
 			break;
 	}
 	

Modified: branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c	2009-08-31 03:36:02 UTC (rev 22906)
+++ branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c	2009-08-31 04:24:28 UTC (rev 22907)
@@ -482,7 +482,10 @@
 	/* Negative zfac means x, y, z was behind the camera (in perspective).
 		* This gives flipped directions, so revert back to ok default case.
 	*/
-	if (rv3d->zfac < 0.0f) rv3d->zfac = 1.0f;
+	// NOTE: I've changed this to flip zfac to be positive again for now so that GPencil draws ok
+	// 	-- Aligorith, 2009Aug31
+	//if (rv3d->zfac < 0.0f) rv3d->zfac = 1.0f;
+	if (rv3d->zfac < 0.0f) rv3d->zfac= -rv3d->zfac;
 }
 
 /* always call initgrabz */





More information about the Bf-blender-cvs mailing list