[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36765] trunk/blender/source/blender/ editors/gpencil/gpencil_edit.c: converting grease pencil now works in the camera view.

Campbell Barton ideasman42 at gmail.com
Thu May 19 09:43:10 CEST 2011


Revision: 36765
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36765
Author:   campbellbarton
Date:     2011-05-19 07:43:10 +0000 (Thu, 19 May 2011)
Log Message:
-----------
converting grease pencil now works in the camera view.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/gpencil/gpencil_edit.c

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_edit.c	2011-05-19 07:26:43 UTC (rev 36764)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_edit.c	2011-05-19 07:43:10 UTC (rev 36765)
@@ -365,7 +365,7 @@
 /* convert the coordinates from the given stroke point into 3d-coordinates 
  *	- assumes that the active space is the 3D-View
  */
-static void gp_strokepoint_convertcoords (bContext *C, bGPDstroke *gps, bGPDspoint *pt, float p3d[3])
+static void gp_strokepoint_convertcoords (bContext *C, bGPDstroke *gps, bGPDspoint *pt, float p3d[3], rctf *subrect)
 {
 	Scene *scene= CTX_data_scene(C);
 	View3D *v3d= CTX_wm_view3d(C);
@@ -377,7 +377,6 @@
 	}
 	else {
 		float *fp= give_cursor(scene, v3d);
-		int mval[2];
 		int mx, my;
 		
 		/* get screen coordinate */
@@ -386,29 +385,33 @@
 			UI_view2d_view_to_region(v2d, pt->x, pt->y, &mx, &my);
 		}
 		else {
-			mx= (int)(pt->x / 100 * ar->winx);
-			my= (int)(pt->y / 100 * ar->winy);
+			if(subrect) {
+				mx= (int)((pt->x/100.0f) * (subrect->xmax - subrect->xmin)) + subrect->xmin;
+				my= (int)((pt->y/100.0f) * (subrect->ymax - subrect->ymin)) + subrect->ymin;
+			}
+			else {
+				mx= (int)(pt->x / 100 * ar->winx);
+				my= (int)(pt->y / 100 * ar->winy);
+			}
 		}
-		mval[0]= mx;
-		mval[1]= my;
 		
 		/* convert screen coordinate to 3d coordinates 
 		 *	- method taken from editview.c - mouse_cursor() 
 		 */
-		window_to_3d(ar, p3d, fp, mval[0], mval[1]);
+		window_to_3d(ar, p3d, fp, mx, my);
 	}
 }
 
 /* --- */
 
 /* convert stroke to 3d path */
-static void gp_stroke_to_path (bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curve *cu)
+static void gp_stroke_to_path (bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curve *cu, rctf *subrect)
 {
 	bGPDspoint *pt;
 	Nurb *nu;
 	BPoint *bp;
 	int i;
-	
+
 	/* create new 'nurb' within the curve */
 	nu = (Nurb *)MEM_callocN(sizeof(Nurb), "gpstroke_to_path(nurb)");
 	
@@ -425,7 +428,7 @@
 		float p3d[3];
 		
 		/* get coordinates to add at */
-		gp_strokepoint_convertcoords(C, gps, pt, p3d);
+		gp_strokepoint_convertcoords(C, gps, pt, p3d, subrect);
 		copy_v3_v3(bp->vec, p3d);
 		
 		/* set settings */
@@ -437,8 +440,27 @@
 	BLI_addtail(&cu->nurb, nu);
 }
 
+static int gp_camera_view_subrect(bContext *C, rctf *subrect)
+{
+	Scene *scene= CTX_data_scene(C);
+	View3D *v3d= CTX_wm_view3d(C);
+	ARegion *ar= CTX_wm_region(C);
+
+	if (v3d) {
+		RegionView3D *rv3d= ar->regiondata;
+
+		/* for camera view set the subrect */
+		if (rv3d->persp == RV3D_CAMOB) {
+			view3d_calc_camera_border(scene, ar, NULL, v3d, subrect, -1); /* negative shift */
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 /* convert stroke to 3d bezier */
-static void gp_stroke_to_bezier (bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curve *cu)
+static void gp_stroke_to_bezier (bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curve *cu, rctf *subrect)
 {
 	bGPDspoint *pt;
 	Nurb *nu;
@@ -460,9 +482,9 @@
 	/* get initial coordinates */
 	pt=gps->points;
 	if (tot) {
-		gp_strokepoint_convertcoords(C, gps, pt, p3d_cur);
+		gp_strokepoint_convertcoords(C, gps, pt, p3d_cur, subrect);
 		if (tot > 1) {
-			gp_strokepoint_convertcoords(C, gps, pt+1, p3d_next);
+			gp_strokepoint_convertcoords(C, gps, pt+1, p3d_next, subrect);
 		}
 	}
 
@@ -490,7 +512,7 @@
 		copy_v3_v3(p3d_cur, p3d_next);
 
 		if (i + 1 < tot) {
-			gp_strokepoint_convertcoords(C, gps, pt+1, p3d_next);
+			gp_strokepoint_convertcoords(C, gps, pt+1, p3d_next, subrect);
 		}
 	}
 
@@ -509,7 +531,10 @@
 	bGPDstroke *gps;
 	Object *ob;
 	Curve *cu;
-	
+
+	/* camera framing */
+	rctf subrect, *subrect_ptr= NULL;
+
 	/* error checking */
 	if (ELEM3(NULL, gpd, gpl, gpf))
 		return;
@@ -518,6 +543,11 @@
 	if (gpf->strokes.first == NULL)
 		return;
 
+	/* initialize camera framing */
+	if(gp_camera_view_subrect(C, &subrect)) {
+		subrect_ptr= &subrect;
+	}
+
 	/* init the curve object (remove rotation and get curve data from it)
 	 *	- must clear transforms set on object, as those skew our results
 	 */
@@ -535,10 +565,10 @@
 	for (gps= gpf->strokes.first; gps; gps= gps->next) {
 		switch (mode) {
 			case GP_STROKECONVERT_PATH: 
-				gp_stroke_to_path(C, gpl, gps, cu);
+				gp_stroke_to_path(C, gpl, gps, cu, subrect_ptr);
 				break;
 			case GP_STROKECONVERT_CURVE:
-				gp_stroke_to_bezier(C, gpl, gps, cu);
+				gp_stroke_to_bezier(C, gpl, gps, cu, subrect_ptr);
 				break;
 		}
 	}




More information about the Bf-blender-cvs mailing list