[Bf-blender-cvs] [24c6476daf6] greasepencil-object: Extract function to be shared in other modules

Antonio Vazquez noreply at git.blender.org
Thu Dec 28 19:46:16 CET 2017


Commit: 24c6476daf6f55eef6a658d29025ea5620df28f9
Author: Antonio Vazquez
Date:   Thu Dec 28 16:25:40 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB24c6476daf6f55eef6a658d29025ea5620df28f9

Extract function to be shared in other modules

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 6d34dc33d59..220b44e7c18 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -39,10 +39,13 @@
 struct bGPdata;
 struct bGPDstroke;
 struct bGPDspoint;
+struct tGPspoint;
 
 struct GHash;
 
+struct Scene;
 struct ARegion;
+struct View3D;
 struct View2D;
 struct wmOperatorType;
 
@@ -94,6 +97,9 @@ void gp_apply_parent_point(struct Object *obact, bGPdata *gpd, bGPDlayer *gpl, b
 
 bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, struct Scene *scene, const float screen_co[2], float r_out[3]);
 
+/* helper to convert 2d to 3d */
+void gp_stroke_convertcoords_tpoint(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, const struct tGPspoint *point2D, float out[3]);
+
 /* Poll Callbacks ------------------------------------ */
 /* gpencil_utils.c */
 
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 965bac3904d..71496e7dc8c 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -224,33 +224,6 @@ static void gpencil_primitive_status_indicators(tGPDprimitive *tgpi)
 
 }
 
-/* helper to convert 2d to 3d */
-static void gpencil_stroke_convertcoords(Scene *scene, ARegion *ar, View3D *v3d, const tGPspoint *point2D, float out[3])
-{
-	float mval_f[2];
-	ARRAY_SET_ITEMS(mval_f, point2D->x, point2D->y);
-	float mval_prj[2];
-	float rvec[3], dvec[3];
-	float zfac;
-
-	/* Current method just converts each point in screen-coordinates to
-	* 3D-coordinates using the 3D-cursor as reference.
-	*/
-	const float *cursor = ED_view3d_cursor3d_get(scene, v3d);
-	copy_v3_v3(rvec, cursor);
-
-	zfac = ED_view3d_calc_zfac(ar->regiondata, rvec, NULL);
-
-	if (ED_view3d_project_float_global(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(ar, mval_f, dvec, zfac);
-		sub_v3_v3v3(out, rvec, dvec);
-	}
-	else {
-		zero_v3(out);
-	}
-}
-
 /* create a rectangle */
 static void gp_primitive_rectangle(tGPDprimitive *tgpi, bGPDstroke *gps)
 {
@@ -270,7 +243,7 @@ static void gp_primitive_rectangle(tGPDprimitive *tgpi, bGPDstroke *gps)
 
 		pt = &gps->points[i];
 		/* convert screen-coordinates to 3D coordinates */
-		gpencil_stroke_convertcoords(tgpi->scene, tgpi->ar, tgpi->v3d, &point2D, r_out);
+		gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->v3d, &point2D, r_out);
 		copy_v3_v3(&pt->x, r_out);
 		/* if parented change position relative to parent object */
 		gp_apply_parent_point(tgpi->ob, tgpi->gpd, tgpi->gpl, pt);
@@ -326,7 +299,7 @@ static void gp_primitive_circle(tGPDprimitive *tgpi, bGPDstroke *gps)
 
 		pt = &gps->points[i];
 		/* convert screen-coordinates to 3D coordinates */
-		gpencil_stroke_convertcoords(tgpi->scene, tgpi->ar, tgpi->v3d, &point2D, r_out);
+		gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->v3d, &point2D, r_out);
 		copy_v3_v3(&pt->x, r_out);
 		/* if parented change position relative to parent object */
 		gp_apply_parent_point(tgpi->ob, tgpi->gpd, tgpi->gpl, pt);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 2db97c13e43..e903253ee75 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1414,3 +1414,30 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob)
 	}
 	CTX_DATA_END;
 }
+
+/* helper to convert tGPspoint (2d) to 3d */
+void gp_stroke_convertcoords_tpoint(Scene *scene, ARegion *ar, View3D *v3d, const tGPspoint *point2D, float out[3])
+{
+	float mval_f[2];
+	ARRAY_SET_ITEMS(mval_f, point2D->x, point2D->y);
+	float mval_prj[2];
+	float rvec[3], dvec[3];
+	float zfac;
+
+	/* Current method just converts each point in screen-coordinates to
+	* 3D-coordinates using the 3D-cursor as reference.
+	*/
+	const float *cursor = ED_view3d_cursor3d_get(scene, v3d);
+	copy_v3_v3(rvec, cursor);
+
+	zfac = ED_view3d_calc_zfac(ar->regiondata, rvec, NULL);
+
+	if (ED_view3d_project_float_global(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(ar, mval_f, dvec, zfac);
+		sub_v3_v3v3(out, rvec, dvec);
+	}
+	else {
+		zero_v3(out);
+	}
+}



More information about the Bf-blender-cvs mailing list