[Bf-blender-cvs] [b7c8f44e794] greasepencil-object: Reproject the point while drawing

Antonio Vazquez noreply at git.blender.org
Mon May 22 21:04:12 CEST 2017


Commit: b7c8f44e7944cc98d0f06dc0b4e1a427236a24e7
Author: Antonio Vazquez
Date:   Mon May 22 21:03:56 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBb7c8f44e7944cc98d0f06dc0b4e1a427236a24e7

Reproject the point while drawing

If the point is not reprojected and the axis is locked, the thickness of the drawing stroke is different when the stroke is completed.

Reprojecting the stroke drawing buffer simulate the stroke thickness when it will be reprojected in 3D space and get better drawing feedback.

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

M	source/blender/draw/engines/gpencil/gpencil_geom.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 a24fba092cd..2ea30e3d77d 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -237,6 +237,8 @@ Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4], shor
 	View3D *v3d = draw_ctx->v3d;
 	ARegion *ar = draw_ctx->ar;
 	RegionView3D *rv3d = draw_ctx->rv3d;
+	ToolSettings *ts = scene->toolsettings;
+	Object *ob = draw_ctx->obact;
 
 	tGPspoint *points = gpd->sbuffer;
 	int totpoints = gpd->sbuffer_size;
@@ -256,9 +258,15 @@ Batch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, float matrix[4][4], shor
 	const tGPspoint *tpt = points;
 	bGPDspoint pt;
 	int idx = 0;
+	
+	/* get origin to reproject point */
+	float origin[3];
+	bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
+	ED_gp_get_drawing_reference(ts, 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);
+		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) {
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 1ae3dcabf29..a0007fe3c31 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1180,7 +1180,7 @@ void ED_gp_project_stroke_to_plane(Object *ob, RegionView3D *rv3d, bGPDstroke *g
 }
 
 /* reproject one points to a plane locked to axis to avoid stroke offset */
-void ED_gp_project_point_to_plane(Object *ob, RegionView3D *rv3d, const float origin[3], const int axis, char type, float pt[3])
+void ED_gp_project_point_to_plane(Object *ob, RegionView3D *rv3d, const float origin[3], const int axis, char type, bGPDspoint *pt)
 {
 	float plane_normal[3];
 	float vn[3];
@@ -1188,6 +1188,11 @@ void ED_gp_project_point_to_plane(Object *ob, RegionView3D *rv3d, const float or
 	float ray[3];
 	float rpoint[3];
 
+	/* no need reproject */
+	if (axis < 0) {
+		return;
+	}
+
 	/* normal vector for a plane locked to axis */
 	zero_v3(plane_normal);
 	plane_normal[axis] = 1.0f;
@@ -1200,15 +1205,15 @@ void ED_gp_project_point_to_plane(Object *ob, RegionView3D *rv3d, const float or
 
 	/* Reproject the points in the plane */
 	/* get a vector from the point with the current view direction of the viewport */
-	ED_view3d_global_to_vector(rv3d, pt, vn);
+	ED_view3d_global_to_vector(rv3d, &pt->x, vn);
 
 	/* calculate line extrem point to create a ray that cross the plane */
 	mul_v3_fl(vn, -50.0f);
-	add_v3_v3v3(ray, pt, vn);
+	add_v3_v3v3(ray, &pt->x, vn);
 
 	/* if the line never intersect, the point is not changed */
-	if (isect_line_plane_v3(rpoint, pt, ray, origin, plane_normal)) {
-		copy_v3_v3(pt, rpoint);
+	if (isect_line_plane_v3(rpoint, &pt->x, ray, origin, plane_normal)) {
+		copy_v3_v3(&pt->x, rpoint);
 	}
 }
 
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 01d64705e6f..86def7907fa 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -208,7 +208,7 @@ struct tGPencilSort *ED_gpencil_allocate_cache(struct tGPencilSort *cache, int *
 void ED_gpencil_add_to_cache(struct tGPencilSort *cache, struct RegionView3D *rv3d, struct Base *base, int *gp_cache_used);
 
 void ED_gp_project_stroke_to_plane(struct Object *ob, struct RegionView3D *rv3d, struct bGPDstroke *gps, const float origin[3], const int axis, char type);
-void ED_gp_project_point_to_plane(struct Object *ob, struct RegionView3D *rv3d, const float origin[3], const int axis, char type, float pt[3]);
+void ED_gp_project_point_to_plane(struct Object *ob, struct RegionView3D *rv3d, const float origin[3], const int axis, char type, struct bGPDspoint *pt);
 void ED_gp_get_drawing_reference(struct ToolSettings *ts, struct View3D *v3d, struct Scene *scene, struct Object *ob, struct bGPDlayer *gpl, char align_flag, float vec[3]);
 
 #endif /*  __ED_GPENCIL_H__ */




More information about the Bf-blender-cvs mailing list