[Bf-blender-cvs] [e9727767a2a] greasepencil-object: Calculate UVs while drawing

Antonio Vazquez noreply at git.blender.org
Wed Feb 21 19:59:26 CET 2018


Commit: e9727767a2a066985633bc6e0048e22907b1ca5b
Author: Antonio Vazquez
Date:   Wed Feb 21 19:59:18 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe9727767a2a066985633bc6e0048e22907b1ca5b

Calculate UVs while drawing

Now the UV while drawing is calculated using same logic used in final UV.

There will be differences between drawing and final due simplify and smooth postprocessing, but the look is more similar now.

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

M	source/blender/draw/engines/gpencil/gpencil_geom.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 0f6389912f9..0415086948e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -183,43 +183,6 @@ Gwn_Batch *DRW_gpencil_get_stroke_geom(bGPDframe *gpf, bGPDstroke *gps, short th
 	return GWN_batch_create_ex(GWN_PRIM_LINE_STRIP_ADJ, vbo, NULL, GWN_BATCH_OWNS_VBO);
 }
 
-/* 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 origin[3], 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;
-
-	copy_v3_v3(rvec, origin);
-
-	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);
-	}
-}
-
-/* convert 2d tGPspoint to 3d bGPDspoint */
-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, origin, p3d);
-	copy_v3_v3(&pt->x, p3d);
-
-	pt->pressure = tpt->pressure;
-	pt->strength = tpt->strength;
-	pt->uv_fac = tpt->uv_fac;
-	pt->uv_rot = tpt->uv_rot;
-}
-
 /* create batch geometry data for current buffer stroke shader */
 Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4], short thickness)
 {
@@ -257,13 +220,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, origin, tpt, &pt);
+		ED_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, origin, &points[1], &pt2);
+				ED_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, uvdata_id, thickness, gpd->scolor);
 			}
@@ -281,7 +244,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, origin, &points[totpoints - 2], &pt2);
+		ED_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, uvdata_id, thickness, gpd->scolor);
 	}
@@ -330,7 +293,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, origin, tpt, &pt);
+		ED_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 */
@@ -404,7 +367,7 @@ Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(bGPdata *gpd)
 		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, origin, tpt, &pt);
+				ED_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, gpd->sfill);
 				idx++;
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 8036fab96aa..59dd2823d2b 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -499,6 +499,7 @@ static short gp_stroke_addpoint(
 	tGPspoint *pt;
 	ToolSettings *ts = p->scene->toolsettings;
 	Object *obact = (Object *)p->ownerPtr.data;
+	View3D *v3d = p->sa->spacedata.first;
 	RegionView3D *rv3d = p->ar->regiondata;
 	PaletteColor *palcolor = p->palettecolor;
 
@@ -623,15 +624,30 @@ static short gp_stroke_addpoint(
 		pt->time = (float)(curtime - p->inittime);
 		
 		/* point uv */
-		if (gpd->sbuffer_size > 1) {
+		if (gpd->sbuffer_size > 0) {
+			float pixsize = palcolor->t_pixsize / 1000000.0f;
 			tGPspoint *ptb = (tGPspoint *)gpd->sbuffer + gpd->sbuffer_size - 2;
-			p->totpixlen += (float) len_v2v2_int(&pt->x, &ptb->x);
+			bGPDspoint spt, spt2;
+
+			/* get origin to reproject point */
+			float origin[3];
+			gp_get_3d_reference(p, origin);
+			/* reproject current */
+			ED_gpencil_tpoint_to_point(p->scene, p->ar, v3d, origin, pt, &spt);
+			ED_gp_project_point_to_plane(obact, rv3d, origin, ts->gp_sculpt.lock_axis - 1, ts->gpencil_src, &spt);
+			
+			/* reproject previous */
+			ED_gpencil_tpoint_to_point(p->scene, p->ar, v3d, origin, ptb, &spt2);
+			ED_gp_project_point_to_plane(obact, rv3d, origin, ts->gp_sculpt.lock_axis - 1, ts->gpencil_src, &spt2);
+
+			p->totpixlen += len_v3v3(&spt.x, &spt2.x) / pixsize;
 			pt->uv_fac = p->totpixlen;
 			if ((palcolor) && (palcolor->sima)) {
 				pt->uv_fac /= palcolor->sima->gen_x;
 			}
 		}
 		else {
+			p->totpixlen = 0.0f;
 			pt->uv_fac = 0.0f;
 		}
 
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 36038a6120b..72b04941730 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1531,6 +1531,43 @@ void ED_gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
 	}
 }
 
+/* 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 origin[3], 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;
+
+	copy_v3_v3(rvec, origin);
+
+	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);
+	}
+}
+
+/* convert 2d tGPspoint to 3d bGPDspoint */
+void ED_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, origin, p3d);
+	copy_v3_v3(&pt->x, p3d);
+
+	pt->pressure = tpt->pressure;
+	pt->strength = tpt->strength;
+	pt->uv_fac = tpt->uv_fac;
+	pt->uv_rot = tpt->uv_rot;
+}
+
 /* texture coordinate utilities */
 void ED_gpencil_calc_stroke_uv(bGPDstroke *gps)
 {
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 463808e996c..f3c3891a9b1 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -212,6 +212,7 @@ void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob);
 int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op);
 
 /* texture coordinate utilities */
+void ED_gpencil_tpoint_to_point(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, float origin[3], const struct tGPspoint *tpt, struct bGPDspoint *pt);
 void ED_gpencil_calc_stroke_uv(struct bGPDstroke *gps);
 
 #endif /*  __ED_GPENCIL_H__ */



More information about the Bf-blender-cvs mailing list