[Bf-blender-cvs] [5b33f88e9a6] greasepencil-object: New function to reproject a point
Antonio Vazquez
noreply at git.blender.org
Mon May 22 21:04:10 CEST 2017
Commit: 5b33f88e9a6844839ea65a6ded647d4f0aac855b
Author: Antonio Vazquez
Date: Mon May 22 20:30:06 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5b33f88e9a6844839ea65a6ded647d4f0aac855b
New function to reproject a point
This function will be used while drawing in draw manager gpencil engine
===================================================================
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 684b501717a..1ae3dcabf29 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1179,6 +1179,39 @@ 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])
+{
+ float plane_normal[3];
+ float vn[3];
+
+ float ray[3];
+ float rpoint[3];
+
+ /* normal vector for a plane locked to axis */
+ zero_v3(plane_normal);
+ plane_normal[axis] = 1.0f;
+ /* if object, apply object rotation */
+ if (type & GP_TOOL_SOURCE_OBJECT) {
+ if (ob && ob->type == OB_GPENCIL) {
+ mul_mat3_m4_v3(ob->obmat, plane_normal);
+ }
+ }
+
+ /* 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);
+
+ /* calculate line extrem point to create a ray that cross the plane */
+ mul_v3_fl(vn, -50.0f);
+ add_v3_v3v3(ray, pt, 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);
+ }
+}
+
/* get drawing reference for conversion or projection of the stroke */
void ED_gp_get_drawing_reference(ToolSettings *ts, View3D *v3d, Scene *scene, Object *ob, bGPDlayer *gpl, char align_flag, float vec[3])
{
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 4c6764db1a3..01d64705e6f 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -208,6 +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_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