[Bf-blender-cvs] [c78569a] GPencil_Editing_Stage3: Code Cleanup: Extract out screenspace to 3D logic for GP Sculpt

Joshua Leung noreply at git.blender.org
Sun Aug 16 16:25:18 CEST 2015


Commit: c78569a1e6351541eedefe577feca3d3a44afc38
Author: Joshua Leung
Date:   Mon Aug 10 01:02:01 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rBc78569a1e6351541eedefe577feca3d3a44afc38

Code Cleanup: Extract out screenspace to 3D logic for GP Sculpt

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

M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index b465503..ac42d64 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -608,27 +608,7 @@ static bool gp_brush_randomise_apply(tGP_BrushEditData *gso, bGPDstroke *gps, in
 	if (gps->flag & GP_STROKE_3DSPACE) {
 		/* 3D: Project to 3D space */
 		if (gso->sa->spacetype == SPACE_VIEW3D) {
-			View3D *v3d = gso->sa->spacedata.first;
-			RegionView3D *rv3d = gso->ar->regiondata;
-			float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d);
-			float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
-			
-			float dvec[3], out[3];
-			
-			float *mval_f = nco;
-			float mval_prj[2];
-			
-			if (ED_view3d_project_float_global(gso->ar, rvec, mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-				sub_v2_v2v2(mval_f, mval_prj, mval_f);
-				ED_view3d_win_to_delta(gso->ar, mval_f, dvec, zfac);
-				sub_v3_v3v3(out, rvec, dvec);
-			}
-			else {
-				zero_v3(out);
-			}
-			
-			//printf("  out vs pt = (%f, %f, %f)  -> (%f, %f, %f)\n", out[0], out[1], out[2], pt->x, pt->y, pt->z);
-			copy_v3_v3(&pt->x, out);
+			gp_point_xy_to_3d(&gso->gsc, gso->scene, nco, &pt->x);
 		}
 		else {
 			/* ERROR */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 4c758cb..79cf61b 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -96,6 +96,17 @@ void gp_point_conversion_init(struct bContext *C, GP_SpaceConversion *r_gsc);
 void gp_point_to_xy(GP_SpaceConversion *settings, struct bGPDstroke *gps, struct bGPDspoint *pt,
                     int *r_x, int *r_y);
 
+/**
+ * Convert a screenspace point to a 3D Grease Pencil coordinate.
+ *
+ * For use with editing tools where it is easier to perform the operations in 2D,
+ * and then later convert the transformed points back to 3D.
+ *
+ * \param screeN_co    The screenspace 2D coordinates to convert to 
+ * \param[out] r_out  The resulting 3D coordinates of the input point
+ */
+bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, Scene *scene, const float screen_co[2], float r_out[3]);
+
 /* Poll Callbacks ------------------------------------ */
 /* gpencil_utils.c */
 
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 0d7aac7..dbbc3d0 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -372,4 +372,36 @@ void gp_point_to_xy(GP_SpaceConversion *gsc, bGPDstroke *gps, bGPDspoint *pt,
 	}
 }
 
+/* Project screenspace coordinates to 3D-space
+ * NOTE: We include this as a utility function, since the standard method
+ *       involves quite a few steps, which are invariably always the same
+ *       for all GPencil operations. So, it's nicer to just centralise these.
+ * WARNING: Assumes that it is getting called in a 3D view only
+ */
+bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, Scene *scene, const float screen_co[2], float r_out[3])
+{
+	View3D *v3d = gso->sa->spacedata.first;
+	RegionView3D *rv3d = gso->ar->regiondata;
+	float *rvec = ED_view3d_cursor3d_get(scene, v3d);
+	float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
+	
+	float mval_f[2], mval_prj[2];
+	float dvec[3];
+	
+	copy_v2_v2(mval_f, screen_co);
+	
+	if (ED_view3d_project_float_global(gsc->ar, rvec, mval_prj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+		sub_v2_v2v2(mval_f, mval_prj, mval_f);
+		ED_view3d_win_to_delta(gso->ar, mval_f, dvec, zfac);
+		sub_v3_v3v3(r_out, rvec, dvec);
+		
+		return true;
+	}
+	else {
+		zero_v3(r_out);
+		
+		return false;
+	}
+}
+
 /* ******************************************************** */




More information about the Bf-blender-cvs mailing list