[Bf-blender-cvs] [25b6802aca4] greasepencil-object: GPencil: Drawing locked to 3D cursor (wip)
Antonioya
noreply at git.blender.org
Fri Mar 15 08:44:21 CET 2019
Commit: 25b6802aca4aa14f490547545221bed693711048
Author: Antonioya
Date: Fri Mar 15 08:43:39 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB25b6802aca4aa14f490547545221bed693711048
GPencil: Drawing locked to 3D cursor (wip)
Now it's possible to draw strokes attached to a plane locked to 3D cursor.
Still pending the lock in Sculpt mode.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_fill.c
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_primitive.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_sculpt_paint.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 70e679d4e72..e555375e593 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -270,7 +270,7 @@ GPUBatch *DRW_gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness)
for (int i = 0; i < totpoints; i++, tpt++) {
ED_gpencil_tpoint_to_point(ar, origin, tpt, &pt);
- ED_gp_project_point_to_plane(ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, &pt);
+ ED_gp_project_point_to_plane(scene, ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, &pt);
/* first point for adjacency (not drawn) */
if (i == 0) {
@@ -361,7 +361,7 @@ GPUBatch *DRW_gpencil_get_buffer_point_geom(bGPdata *gpd, short thickness)
for (int i = 0; i < totpoints; i++, tpt++) {
ED_gpencil_tpoint_to_point(ar, origin, tpt, &pt);
- ED_gp_project_point_to_plane(ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, &pt);
+ ED_gp_project_point_to_plane(scene, ob, rv3d, origin, ts->gp_sculpt.lock_axis - 1, &pt);
/* set point */
gpencil_set_stroke_point(
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index d3afe4e3cc4..04e78feb07f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -634,14 +634,30 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
e_data.batch_grid = DRW_gpencil_get_grid(ob);
/* define grid orientation */
- if (ts->gp_sculpt.lock_axis != GP_LOCKAXIS_VIEW) {
- copy_m4_m4(stl->storage->grid_matrix, ob->obmat);
- }
- else {
- /* align always to view */
- invert_m4_m4(stl->storage->grid_matrix, draw_ctx->rv3d->viewmat);
- /* copy ob location */
- copy_v3_v3(stl->storage->grid_matrix[3], ob->obmat[3]);
+ switch (ts->gp_sculpt.lock_axis) {
+ case GP_LOCKAXIS_VIEW:
+ {
+ /* align always to view */
+ invert_m4_m4(stl->storage->grid_matrix, draw_ctx->rv3d->viewmat);
+ /* copy ob location */
+ copy_v3_v3(stl->storage->grid_matrix[3], ob->obmat[3]);
+ break;
+ }
+ case GP_LOCKAXIS_CURSOR:
+ {
+ const View3DCursor *cursor = &scene->cursor;
+ float scale[3] = { 1.0f, 1.0f, 1.0f };
+ loc_eul_size_to_mat4(stl->storage->grid_matrix,
+ cursor->location,
+ cursor->rotation_euler,
+ scale);
+ break;
+ }
+ default:
+ {
+ copy_m4_m4(stl->storage->grid_matrix, ob->obmat);
+ break;
+ }
}
DRW_shgroup_call_add(
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 088282c0f02..a6feb6477a3 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3360,7 +3360,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
}
}
- ED_gp_project_point_to_plane(ob, rv3d, origin,
+ ED_gp_project_point_to_plane(scene, ob, rv3d, origin,
axis, &pt2);
copy_v3_v3(&pt->x, &pt2.x);
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index fad30561ea4..0d0ab46028c 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -1100,7 +1100,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
tgpf->scene, tgpf->ob, tgpf->gpl,
ts->gpencil_v3d_align, origin);
ED_gp_project_stroke_to_plane(
- tgpf->ob, tgpf->rv3d, gps, origin,
+ tgpf->scene, tgpf->ob, tgpf->rv3d, gps, origin,
tgpf->lock_axis - 1);
}
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 50a7d9d8703..e5c81d12d4e 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -398,7 +398,9 @@ static void gp_reproject_toplane(tGPsdata *p, bGPDstroke *gps)
/* get drawing origin */
gp_get_3d_reference(p, origin);
- ED_gp_project_stroke_to_plane(obact, rv3d, gps, origin, p->lock_axis - 1);
+ ED_gp_project_stroke_to_plane(
+ p->scene, obact, rv3d, gps,
+ origin, p->lock_axis - 1);
}
/* convert screen-coordinates to buffer-coordinates */
@@ -752,11 +754,11 @@ static short gp_stroke_addpoint(
gp_get_3d_reference(p, origin);
/* reproject current */
ED_gpencil_tpoint_to_point(p->ar, origin, pt, &spt);
- ED_gp_project_point_to_plane(obact, rv3d, origin, p->lock_axis - 1, &spt);
+ ED_gp_project_point_to_plane(p->scene, obact, rv3d, origin, p->lock_axis - 1, &spt);
/* reproject previous */
ED_gpencil_tpoint_to_point(p->ar, origin, ptb, &spt2);
- ED_gp_project_point_to_plane(obact, rv3d, origin, p->lock_axis - 1, &spt2);
+ ED_gp_project_point_to_plane(p->scene, obact, rv3d, origin, p->lock_axis - 1, &spt2);
p->totpixlen += len_v3v3(&spt.x, &spt2.x) / pixsize;
pt->uv_fac = p->totpixlen;
if ((gp_style) && (gp_style->sima)) {
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 3a2347d9177..e57b66839ef 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -928,11 +928,13 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
ts->gpencil_v3d_align, origin);
/* reproject current */
ED_gpencil_tpoint_to_point(tgpi->ar, origin, tpt, &spt);
- ED_gp_project_point_to_plane(tgpi->ob, tgpi->rv3d, origin, tgpi->lock_axis - 1, &spt);
+ ED_gp_project_point_to_plane(tgpi->scene, tgpi->ob, tgpi->rv3d,
+ origin, tgpi->lock_axis - 1, &spt);
/* reproject previous */
ED_gpencil_tpoint_to_point(tgpi->ar, origin, tptb, &spt2);
- ED_gp_project_point_to_plane(tgpi->ob, tgpi->rv3d, origin, tgpi->lock_axis - 1, &spt2);
+ ED_gp_project_point_to_plane(tgpi->scene, tgpi->ob, tgpi->rv3d,
+ origin, tgpi->lock_axis - 1, &spt2);
tgpi->totpixlen += len_v3v3(&spt.x, &spt2.x) / pixsize;
tpt->uv_fac = tgpi->totpixlen;
if ((gp_style) && (gp_style->sima)) {
@@ -990,7 +992,8 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
ED_gp_get_drawing_reference(tgpi->scene, tgpi->ob, tgpi->gpl,
ts->gpencil_v3d_align, origin);
ED_gp_project_stroke_to_plane(
- tgpi->ob, tgpi->rv3d, gps, origin, ts->gp_sculpt.lock_axis - 1);
+ tgpi->scene, tgpi->ob, tgpi->rv3d, gps,
+ origin, ts->gp_sculpt.lock_axis - 1);
}
/* if parented change position relative to parent object */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 5f703808d53..f7187e544c8 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -876,9 +876,11 @@ void ED_gp_get_drawing_reference(
char align_flag, float r_vec[3])
{
const float *fp = scene->cursor.location;
+ ToolSettings *ts = scene->toolsettings;
+ const int axis = ts->gp_sculpt.lock_axis;
/* if using a gpencil object at cursor mode, can use the location of the object */
- if (align_flag & GP_PROJECT_VIEWSPACE) {
+ if ((align_flag & GP_PROJECT_VIEWSPACE) && (axis != GP_LOCKAXIS_CURSOR)) {
if (ob && (ob->type == OB_GPENCIL)) {
/* fallback (no strokes) - use cursor or object location */
if (align_flag & GP_PROJECT_CURSOR) {
@@ -936,7 +938,9 @@ void ED_gpencil_project_stroke_to_view(bContext *C, bGPDlayer *gpl, bGPDstroke *
* Reproject all points of the stroke to a plane locked to axis to avoid stroke offset
*/
void ED_gp_project_stroke_to_plane(
- const Object *ob, const RegionView3D *rv3d, bGPDstroke *gps, const float origin[3], const int axis)
+ const Scene *scene, const Object *ob,
+ const RegionView3D *rv3d, bGPDstroke *gps,
+ const float origin[3], const int axis)
{
float plane_normal[3];
float vn[3];
@@ -952,13 +956,24 @@ void ED_gp_project_stroke_to_plane(
*/
ED_view3d_global_to_vector(rv3d, origin, plane_normal);
}
- else {
+ else if (axis < 3) {
plane_normal[axis] = 1.0f;
/* if object, apply object rotation */
if (ob && (ob->type == OB_GPENCIL)) {
mul_mat3_m4_v3(ob->obmat, plane_normal);
}
}
+ else {
+ const View3DCursor *cursor = &scene->cursor;
+ float scale[3] = { 1.0f, 1.0f, 1.0f };
+ plane_normal[2] = 1.0f;
+ float mat[4][4];
+ loc_eul_size_to_mat4(mat,
+ cursor->location,
+ cursor->rotation_euler,
+ scale);
+ mul_mat3_m4_v3(mat, plane_normal);
+ }
/* Reproject the points in the plane */
for (int i = 0; i < gps->totpoints; i++) {
@@ -983,7 +998,9 @@ void ED_gp_project_stroke_to_plane(
* \param[in, out] pt : Point to affect
*/
void ED_gp_project_point_to_plane(
- const Object *ob, const RegionView3D *rv3d, const float origin[3], const int axis, bGPDspoint *pt)
+ const Scene *scene, const Object *ob,
+ const RegionView3D *rv3d, const float origin[3],
+ const int axis, bGPDspoint *pt)
{
float plane_normal[3];
float vn[3];
@@ -999,14 +1016,24 @@ void ED_gp_project_point_to_plane(
*/
ED_view3d_global_to_vector(rv3d, origin, plane_normal);
}
- else {
+ else if (axis < 3) {
plane_normal[axis] = 1.0f;
/* if object, apply object rotation */
if (ob && (ob->type == OB_GPENCIL)) {
mul_mat3_m4_v3(ob->obmat, plane_normal);
}
}
-
+ else {
+ const View3DCursor *cursor = &scene->cursor;
+ float scale[3] = { 1.0f, 1.0f, 1.0f };
+ plane_normal[2] = 1.0f;
+ float mat[4][4];
+ loc_eul_size_to_mat4(mat,
+ cursor->location,
+ cursor->rotation_euler,
+ scale);
+ mul_mat3_m4_v3(mat, plane_normal);
+ }
/* Reproject the points in the plane */
/* get a vector from the point with the current view direction of the viewport */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index e331032bd6e..fdbb8556891 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -225,9 +225,11 @@ void ED_gpencil_add_defaults(struct bContext *C, struct Object *
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list