[Bf-blender-cvs] [cfa7daf3a99] greasepencil-object: Fix problem with buffer when cursor outside camera view

Antonio Vazquez noreply at git.blender.org
Thu Jan 18 11:58:36 CET 2018


Commit: cfa7daf3a9974dcff703bc133407a775f7954f13
Author: Antonio Vazquez
Date:   Thu Jan 18 11:58:17 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBcfa7daf3a9974dcff703bc133407a775f7954f13

Fix problem with buffer when cursor outside camera view

Before, the stroke buffer was converted using the 3D cursor location, but if the camera moves and the cursor was on back of camera, the stroke buffer was not visible while painting.

Now, the conversion is done using the origin of the object and this avoid this problem.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_geom.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index b3877fd8fdb..9091a0fcc98 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -872,7 +872,7 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
 					}
 					stl->g_data->shgrps_drawing_fill = DRW_shgroup_create(e_data->gpencil_drawing_fill_sh, psl->drawing_pass);
 					stl->g_data->tot_sh++;
-					stl->g_data->batch_buffer_fill = DRW_gpencil_get_buffer_fill_geom(gpd->sbuffer, gpd->sbuffer_size, gpd->sfill);
+					stl->g_data->batch_buffer_fill = DRW_gpencil_get_buffer_fill_geom(gpd, gpd->sbuffer, gpd->sbuffer_size, gpd->sfill);
 					DRW_shgroup_call_add(stl->g_data->shgrps_drawing_fill, stl->g_data->batch_buffer_fill, stl->storage->unit_matrix);
 				}
 			}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 2d0bb090e95..2d9421f731f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -319,7 +319,7 @@ struct Gwn_Batch *DRW_gpencil_get_fill_geom(struct bGPDstroke *gps, const float
 struct Gwn_Batch *DRW_gpencil_get_edit_geom(struct bGPDstroke *gps, float alpha, short dflag);
 struct Gwn_Batch *DRW_gpencil_get_edlin_geom(struct bGPDstroke *gps, float alpha, short dflag);
 struct Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
-struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(const struct tGPspoint *points, int totpoints, float ink[4]);
+struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(struct bGPdata *gpd, const struct tGPspoint *points, int totpoints, float ink[4]);
 struct Gwn_Batch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
 
 struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height);
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index ca6508e039f..02b0b524de6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -166,7 +166,7 @@ Gwn_Batch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, bGPDstroke *gps, short th
 }
 
 /* helper to convert 2d to 3d for simple drawing buffer */
-static void gpencil_stroke_convertcoords(Scene *scene, ARegion *ar, View3D *v3d, const tGPspoint *point2D, float out[3])
+static void gpencil_stroke_convertcoords(Scene *scene, ARegion *ar, View3D *v3d, const tGPspoint *point2D, float origin[3], float out[3])
 {
 	float mval_f[2];
 	ARRAY_SET_ITEMS(mval_f, point2D->x, point2D->y);
@@ -174,11 +174,7 @@ static void gpencil_stroke_convertcoords(Scene *scene, ARegion *ar, View3D *v3d,
 	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);
+	copy_v3_v3(rvec, origin);
 
 	zfac = ED_view3d_calc_zfac(ar->regiondata, rvec, NULL);
 
@@ -193,11 +189,11 @@ static void gpencil_stroke_convertcoords(Scene *scene, ARegion *ar, View3D *v3d,
 }
 
 /* convert 2d tGPspoint to 3d bGPDspoint */
-static void gpencil_tpoint_to_point(Scene *scene, ARegion *ar, View3D *v3d, const tGPspoint *tpt, bGPDspoint *pt)
+static void gpencil_tpoint_to_point(Scene *scene, ARegion *ar, View3D *v3d, float origin[3], const tGPspoint *tpt, bGPDspoint *pt)
 {
 	float p3d[3];
 	/* conversion to 3d format */
-	gpencil_stroke_convertcoords(scene, ar, v3d, tpt, p3d);
+	gpencil_stroke_convertcoords(scene, ar, v3d, tpt, origin, p3d);
 	copy_v3_v3(&pt->x, p3d);
 
 	pt->pressure = tpt->pressure;
@@ -240,13 +236,13 @@ Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4],
 	ED_gp_get_drawing_reference(v3d, scene, ob, gpl, ts->gpencil_v3d_align, origin);
 
 	for (int i = 0; i < totpoints; i++, tpt++) {
-		gpencil_tpoint_to_point(scene, ar, v3d, tpt, &pt);
+		gpencil_tpoint_to_point(scene, ar, v3d, origin, tpt, &pt);
 		ED_gp_project_point_to_plane(ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, ts->gpencil_src, &pt);
 
 		/* first point for adjacency (not drawn) */
 		if (i == 0) {
 			if (totpoints > 1) {
-				gpencil_tpoint_to_point(scene, ar, v3d, &points[1], &pt2);
+				gpencil_tpoint_to_point(scene, ar, v3d, origin, &points[1], &pt2);
 				gpencil_set_stroke_point(vbo, matrix, &pt2, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
 			}
 			else {
@@ -261,7 +257,7 @@ Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4],
 
 	/* last adjacency point (not drawn) */
 	if (totpoints > 2) {
-		gpencil_tpoint_to_point(scene, ar, v3d, &points[totpoints - 2], &pt2);
+		gpencil_tpoint_to_point(scene, ar, v3d, origin, &points[totpoints - 2], &pt2);
 		gpencil_set_stroke_point(vbo, matrix, &pt2, idx, pos_id, color_id, thickness_id, thickness, gpd->scolor);
 	}
 	else {
@@ -307,7 +303,7 @@ Gwn_Batch *DRW_gpencil_get_buffer_point_geom(bGPdata *gpd, float matrix[4][4], s
 	ED_gp_get_drawing_reference(v3d, scene, ob, gpl, ts->gpencil_v3d_align, origin);
 
 	for (int i = 0; i < totpoints; i++, tpt++) {
-		gpencil_tpoint_to_point(scene, ar, v3d, tpt, &pt);
+		gpencil_tpoint_to_point(scene, ar, v3d, origin, tpt, &pt);
 		ED_gp_project_point_to_plane(ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, ts->gpencil_src, &pt);
 
 		/* set point */
@@ -319,7 +315,7 @@ Gwn_Batch *DRW_gpencil_get_buffer_point_geom(bGPdata *gpd, float matrix[4][4], s
 }
 
 /* create batch geometry data for current buffer fill shader */
-Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(const tGPspoint *points, int totpoints, float ink[4])
+Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(bGPdata *gpd, const tGPspoint *points, int totpoints, float ink[4])
 {
 	if (totpoints < 3) {
 		return NULL;
@@ -329,6 +325,14 @@ Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(const tGPspoint *points, int totpoin
 	Scene *scene = draw_ctx->scene;
 	View3D *v3d = draw_ctx->v3d;
 	ARegion *ar = draw_ctx->ar;
+	RegionView3D *rv3d = draw_ctx->rv3d;
+	ToolSettings *ts = scene->toolsettings;
+	Object *ob = draw_ctx->obact;
+
+	/* get origin to reproject point */
+	float origin[3];
+	bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
+	ED_gp_get_drawing_reference(v3d, scene, ob, gpl, ts->gpencil_v3d_align, origin);
 
 	int tot_triangles = totpoints - 2;
 	/* allocate memory for temporary areas */
@@ -366,7 +370,7 @@ Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(const tGPspoint *points, int totpoin
 		for (int i = 0; i < tot_triangles; i++) {
 			for (int j = 0; j < 3; j++) {
 				tpt = &points[tmp_triangles[i][j]];
-				gpencil_tpoint_to_point(scene, ar, v3d, tpt, &pt);
+				gpencil_tpoint_to_point(scene, ar, v3d, origin, tpt, &pt);
 				GWN_vertbuf_attr_set(vbo, pos_id, idx, &pt.x);
 				GWN_vertbuf_attr_set(vbo, color_id, idx, ink);
 				idx++;



More information about the Bf-blender-cvs mailing list