[Bf-blender-cvs] [6726150803a] greasepencil-object: WIP: Fix problems with stroke location
Antonio Vazquez
noreply at git.blender.org
Fri Dec 29 18:26:14 CET 2017
Commit: 6726150803afd28f8632681fb0c0f4a0e190b896
Author: Antonio Vazquez
Date: Fri Dec 29 18:03:47 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB6726150803afd28f8632681fb0c0f4a0e190b896
WIP: Fix problems with stroke location
Still problems with reproject
===================================================================
M source/blender/editors/gpencil/gpencil_fill.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_primitive.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index 7611bf77248..7abd6d9da09 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -71,10 +71,15 @@
#include "gpencil_intern.h"
/* draw a given stroke using same thickness and color for all points */
-static void gp_draw_basic_stroke(const bGPDspoint *points, int totpoints,
- const float diff_mat[4][4], bool cyclic, float ink[4])
+static void gp_draw_basic_stroke(bGPDstroke *gps, const float diff_mat[4][4],
+ bool cyclic, float ink[4], int flag, float thershold)
{
+ bGPDspoint *points = gps->points;
+ int totpoints = gps->totpoints;
float fpt[3];
+ float col[4];
+
+ copy_v4_v4(col, ink);
/* if cyclic needs more vertex */
int cyclic_add = (cyclic) ? 1 : 0;
@@ -91,15 +96,24 @@ static void gp_draw_basic_stroke(const bGPDspoint *points, int totpoints,
const bGPDspoint *pt = points;
for (int i = 0; i < totpoints; i++, pt++) {
+
+ if (flag & GP_FILL_HIDE_LINES) {
+ float alpha = gps->palcolor->rgb[3] * pt->strength;
+ CLAMP(alpha, 0.0f, 1.0f);
+ col[3] = alpha <= thershold ? 0.0f : 1.0f;
+ }
+ else {
+ col[3] = 1.0f;
+ }
/* set point */
- immAttrib4fv(color, ink);
+ immAttrib4fv(color, col);
mul_v3_m4v3(fpt, diff_mat, &pt->x);
immVertex3fv(pos, fpt);
}
if (cyclic && totpoints > 2) {
/* draw line to first point to complete the cycle */
- immAttrib4fv(color, ink);
+ immAttrib4fv(color, col);
mul_v3_m4v3(fpt, diff_mat, &points->x);
immVertex3fv(pos, fpt);
}
@@ -109,8 +123,14 @@ static void gp_draw_basic_stroke(const bGPDspoint *points, int totpoints,
}
/* loop all layers */
-static void gp_draw_datablock(Scene *scene, Object *ob, bGPdata *gpd, float ink[4])
+static void gp_draw_datablock(tGPDfill *tgpf, float ink[4])
{
+ Scene *scene = tgpf->scene;
+ Object *ob = tgpf->ob;
+ bGPdata *gpd = tgpf->gpd;
+
+ glEnable(GL_BLEND);
+
float diff_mat[4][4];
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* calculate parent position */
@@ -138,23 +158,22 @@ static void gp_draw_datablock(Scene *scene, Object *ob, bGPdata *gpd, float ink[
}
/* 3D Lines - OpenGL primitives-based */
- gp_draw_basic_stroke(gps->points, gps->totpoints,
- diff_mat, gps->flag & GP_STROKE_CYCLIC, ink);
+ gp_draw_basic_stroke(gps, diff_mat, gps->flag & GP_STROKE_CYCLIC, ink,
+ tgpf->flag, tgpf->threshold);
}
}
+
+ glDisable(GL_BLEND);
}
/* draw strokes in offscreen buffer */
static void gp_render_offscreen(tGPDfill *tgpf)
{
- Scene *scene = tgpf->scene;
- Object *ob = tgpf->ob;
- bGPdata *gpd = (bGPdata *)ob->data;
const char *viewname = "GP";
bool is_ortho = false;
float winmat[4][4];
- if (!gpd) {
+ if (!tgpf->gpd) {
return;
}
@@ -203,7 +222,7 @@ static void gp_render_offscreen(tGPDfill *tgpf)
/* draw strokes */
float ink[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
- gp_draw_datablock(scene, ob, gpd, ink);
+ gp_draw_datablock(tgpf, ink);
/* restore size */
tgpf->ar->winx = bwinx;
@@ -561,8 +580,9 @@ static void gpencil_stroke_from_stack(tGPDfill *tgpf)
point2D.y = v[1];
/* convert screen-coordinates to 3D coordinates */
- gp_stroke_convertcoords_tpoint(tgpf->scene, tgpf->ar, tgpf->v3d, &point2D, r_out);
+ gp_stroke_convertcoords_tpoint(tgpf->scene, tgpf->ar, tgpf->v3d, tgpf->ob, tgpf->gpl, &point2D, r_out);
copy_v3_v3(&pt->x, r_out);
+
/* if parented change position relative to parent object */
gp_apply_parent_point(tgpf->ob, tgpf->gpd, tgpf->gpl, pt);
@@ -586,7 +606,6 @@ static void gpencil_stroke_from_stack(tGPDfill *tgpf)
}
#if 0
-
/* simplify stroke using Ramer-Douglas-Peucker algorithm */
BKE_gpencil_simplify_stroke(tgpf->gpl, gps, 0.2f);
#endif
@@ -597,12 +616,8 @@ static void gpencil_stroke_from_stack(tGPDfill *tgpf)
bGPDspoint *tpt = gps->points;
ED_gp_get_drawing_reference(tgpf->v3d, tgpf->scene, tgpf->ob, tgpf->gpl,
ts->gpencil_v3d_align, origin);
-
- for (int i = 0; i < gps->totpoints; i++, tpt++) {
- ED_gp_project_point_to_plane(tgpf->ob, tgpf->rv3d, origin,
- ts->gp_sculpt.lock_axis - 1,
- ts->gpencil_src, tpt);
- }
+ ED_gp_project_stroke_to_plane(tgpf->ob, tgpf->rv3d, gps, origin,
+ tgpf->lock_axis - 1, ts->gpencil_src);
}
}
@@ -627,14 +642,11 @@ static void gpencil_fill_status_indicators(tGPDfill *tgpf)
/* draw boundary lines to see fill limits */
static void gpencil_draw_boundary_lines(const bContext *UNUSED(C), tGPDfill *tgpf)
{
- Scene *scene = tgpf->scene;
- Object *ob = tgpf->ob;
- bGPdata *gpd = (bGPdata *)ob->data;
- if (!gpd) {
+ if (!tgpf->gpd) {
return;
}
float ink[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
- gp_draw_datablock(scene, ob, gpd, ink);
+ gp_draw_datablock(tgpf, ink);
}
/* Drawing callback for modal operator in 3d mode */
@@ -682,6 +694,8 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *op)
tgpf->eval_ctx = bmain->eval_ctx;
tgpf->rv3d = tgpf->ar->regiondata;
tgpf->v3d = tgpf->sa->spacedata.first;
+ tgpf->graph = CTX_data_depsgraph(C);
+ tgpf->win = CTX_wm_window(C);
/* set GP datablock */
tgpf->gpd = gpd;
@@ -694,7 +708,8 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *op)
tgpf->lock_axis = ts->gp_sculpt.lock_axis;
- tgpf->threshold = 0.1f;
+ tgpf->threshold = 0.01f;
+ tgpf->oldkey = -1;
/* return context data for running operator */
return tgpf;
}
@@ -805,19 +820,33 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (ELEM(event->type, ESCKEY)) {
estate = OPERATOR_CANCELLED;
}
- if (ELEM(event->type, HKEY)) {
- /* Just toggle lines */
- tgpf->flag ^= GP_FILL_HIDE_LINES;
- }
- if (ELEM(event->type, AKEY)) {
- tgpf->threshold -= 0.1f;
+ /* avoid double press */
+ if (tgpf->oldkey != event->type) {
+ if (ELEM(event->type, HKEY)) {
+ /* Just toggle lines */
+ tgpf->flag ^= GP_FILL_HIDE_LINES;
+ estate = OPERATOR_RUNNING_MODAL;
+ }
+ if (ELEM(event->type, AKEY)) {
+ tgpf->threshold -= 0.01f;
+ estate = OPERATOR_RUNNING_MODAL;
+ }
+ if (ELEM(event->type, ZKEY)) {
+ tgpf->threshold += 0.01f;
+ estate = OPERATOR_RUNNING_MODAL;
+ }
+
+ CLAMP(tgpf->threshold, 0.0f, 1.0f);
+ gpencil_fill_status_indicators(tgpf);
+ tgpf->oldkey = event->type;
+ float ink[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
+ /* update */
+ gp_draw_datablock(tgpf, ink);
+ WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
}
- if (ELEM(event->type, ZKEY)) {
- tgpf->threshold += 0.1f;
+ else {
+ tgpf->oldkey = -1;
}
-
- CLAMP(tgpf->threshold, 0.0f, 1.0f);
- gpencil_fill_status_indicators(tgpf);
}
if ELEM(event->type, RIGHTMOUSE) {
estate = OPERATOR_CANCELLED;
@@ -855,11 +884,11 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* create stroke and reproject */
gpencil_stroke_from_stack(tgpf);
- /* delete temp image */
+#if 0 /* delete temp image */
if (tgpf->ima) {
BKE_image_free(tgpf->ima);
}
-
+#endif
/* free temp stack data */
if (tgpf->stack) {
BLI_stack_free(tgpf->stack);
@@ -888,7 +917,6 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
break;
case OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH:
- /* event doesn't need to be handled */
break;
}
@@ -910,5 +938,5 @@ void GPENCIL_OT_fill(wmOperatorType *ot)
ot->cancel = gpencil_fill_cancel;
/* flags */
- ot->flag = OPTYPE_BLOCKING;
+ ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING;
}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 220b44e7c18..8a9a33250b0 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -98,7 +98,7 @@ void gp_apply_parent_point(struct Object *obact, bGPdata *gpd, bGPDlayer *gpl, b
bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, struct Scene *scene, const float screen_co[2], float r_out[3]);
/* helper to convert 2d to 3d */
-void gp_stroke_convertcoords_tpoint(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, const struct tGPspoint *point2D, float out[3]);
+void gp_stroke_convertcoords_tpoint(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct Object *ob, bGPDlayer *gpl, const struct tGPspoint *point2D, float out[3]);
/* Poll Callbacks ------------------------------------ */
/* gpencil_utils.c */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index b43f9e2ea0f..2ba68d1c0d8 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -243,7 +243,7 @@ static void gp_primitive_rectangle(tGPDprimitive *tgpi, bGPDstroke *gps)
pt = &gps->points[i];
/* convert screen-coordinates to 3D coordinates */
- gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->v3d, &point2D, r_out);
+ gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->v3d, tgpi->ob, tgpi->gpl, &point2D, r_out);
copy_v3_v3(&pt->x, r_out);
/* if parented change position relative to parent object */
gp_apply_parent_point(tgpi->ob, tgpi->gpd, tgpi->gpl, pt);
@@ -296,7 +296,7 @@ static void gp_primitive_circle(tGPDprimitive *tgpi, bGPDstroke *gps)
pt = &gps->points[i];
/* convert screen-coordinates to 3D coordinates */
- gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->v3d, &point2D, r_out);
+ gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->v3d, tgpi->ob, tgpi->gpl, &point2D, r_out);
copy_v3_v3(&pt->x, r_out);
/* if parented change position relative to parent object */
gp_apply_parent_point(tgpi->ob, tgpi->gpd, tgpi->gpl, pt);
@@ -410,7 +410,9 @@ static bool gp_primitive_set_init_values(bContext *C, wmOperator *op, tGPDprimit
tgpi->ar = CTX_wm_region(C);
tgpi->rv3d = tgpi->ar->regiondata;
tgpi->v3d = tgpi->sa->spacedata.first;
-
+ tgpi->graph = CTX_data_depsgraph(C);
+ tgpi->win = CTX_wm_window(C);
+
/* set current frame number */
tgpi->cframe = tgpi->scene->r.cfra;
diff --git a/source/blender/e
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list