[Bf-blender-cvs] [2829f877459] greasepencil-experimental: GPencil: Add runtime data to dereference pointers to original data
Antonioya
noreply at git.blender.org
Wed May 8 20:26:24 CEST 2019
Commit: 2829f87745965f99ba127e61b996e563189f1574
Author: Antonioya
Date: Sun May 5 16:56:29 2019 +0200
Branches: greasepencil-experimental
https://developer.blender.org/rB2829f87745965f99ba127e61b996e563189f1574
GPencil: Add runtime data to dereference pointers to original data
This will be required for modifiers in Edit mode.
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_select.c
M source/blender/makesdna/DNA_gpencil_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 993d4ee8386..7d1d30cf07f 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -285,4 +285,9 @@ float BKE_gpencil_multiframe_falloff_calc(
extern void (*BKE_gpencil_batch_cache_dirty_tag_cb)(struct bGPdata *gpd);
extern void (*BKE_gpencil_batch_cache_free_cb)(struct bGPdata *gpd);
+/* derived data functions */
+struct bGPDframe *BKE_gpencil_derivedframe_get(struct Object *ob,
+ struct bGPDlayer *gpl,
+ struct bGPDframe *gpf);
+
#endif /* __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index c82b2c377fa..bb25c9333e8 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1970,3 +1970,23 @@ bool BKE_gpencil_trim_stroke(bGPDstroke *gps)
}
return intersect;
}
+
+/** Get derived frame with modifiers applied */
+bGPDframe *BKE_gpencil_derivedframe_get(Object *ob, bGPDlayer *gpl, bGPDframe *gpf)
+{
+ GpencilBatchCache *cache = ob->runtime.gpencil_cache;
+ bGPdata *gpd = (bGPdata *)ob->data;
+ if (cache == NULL) {
+ return gpf;
+ }
+ int derived_idx = BLI_findindex(&gpd->layers, gpl);
+
+ /* if not derived data return original data */
+ if (derived_idx < 0) {
+ return gpf;
+ }
+
+ bGPDframe *derived_gpf = &cache->derived_array[derived_idx];
+
+ return derived_gpf;
+}
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 4b6c913785d..21771d7d668 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1123,8 +1123,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache,
}
/* edit points (only in edit mode and not play animation not render) */
- if ((draw_ctx->obact == ob) && (src_gps) && (!playing) && (!is_render) &&
- (!cache_ob->is_dup_ob)) {
+ if ((draw_ctx->obact == ob) && (!playing) && (!is_render) && (!cache_ob->is_dup_ob)) {
if ((gpl->flag & GP_LAYER_LOCKED) == 0) {
if (!stl->g_data->shgrps_edit_line) {
stl->g_data->shgrps_edit_line = DRW_shgroup_create(e_data->gpencil_line_sh,
@@ -1137,7 +1136,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache,
DRW_shgroup_uniform_vec2(stl->g_data->shgrps_edit_point, "Viewport", viewport_size, 1);
}
- gpencil_add_editpoints_vertexdata(cache, ob, gpd, gpl, derived_gpf, src_gps);
+ gpencil_add_editpoints_vertexdata(cache, ob, gpd, gpl, derived_gpf, gps);
}
}
@@ -1364,6 +1363,15 @@ static void gpencil_copy_frame(bGPDframe *gpf, bGPDframe *derived_gpf)
for (bGPDstroke *gps_src = gpf->strokes.first; gps_src; gps_src = gps_src->next) {
/* make copy of source stroke */
bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src);
+
+ /* Save original pointers for using in edit and select operators. */
+ gps_dst->runtime.gps_orig = gps_src;
+ bGPDspoint *pt_src = gps_src->points;
+ bGPDspoint *pt_dst = gps_dst->points;
+ for (int i = 0; i < gps_src->totpoints; i++, pt_dst++, pt_src++) {
+ pt_dst->runtime.pt_orig = pt_src;
+ }
+
BLI_addtail(&derived_gpf->strokes, gps_dst);
}
}
@@ -1945,7 +1953,9 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data *e_data,
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(draw_ctx->depsgraph);
Scene *scene = draw_ctx->scene;
- bGPdata *gpd = (bGPdata *)ob->data;
+ /* Use original data to shared in edit/transform operators */
+ bGPdata *gpd_eval = (bGPdata *)ob->data;
+ bGPdata *gpd = (bGPdata *)DEG_get_original_id(&gpd_eval->id);
View3D *v3d = draw_ctx->v3d;
int cfra_eval = (int)DEG_get_ctime(draw_ctx->depsgraph);
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index c8d2547ad51..a730ea313eb 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -632,6 +632,55 @@ struct GP_EditableStrokes_Iter {
} \
(void)0
+/**
+ * Iterate over all editable strokes using derived data in the current context,
+ * stopping on each usable layer + stroke pair (i.e. gpl and gps)
+ * to perform some operations on the stroke.
+ *
+ * \param gpl: The identifier to use for the layer of the stroke being processed.
+ * Choose a suitable value to avoid name clashes.
+ * \param gps: The identifier to use for current stroke being processed.
+ * Choose a suitable value to avoid name clashes.
+ */
+#define GP_DERIVED_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) \
+ { \
+ struct GP_EditableStrokes_Iter gpstroke_iter = {{{0}}}; \
+ Depsgraph *depsgraph_ = CTX_data_depsgraph(C); \
+ Object *obact_ = CTX_data_active_object(C); \
+ bGPdata *gpd_ = CTX_data_gpencil_data(C); \
+ const bool is_multiedit_ = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \
+ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { \
+ bGPDframe *init_gpf_ = gpl->actframe; \
+ if (is_multiedit_) { \
+ init_gpf_ = gpl->frames.first; \
+ } \
+ for (bGPDframe *gpf_ = init_gpf_; gpf_; gpf_ = gpf_->next) { \
+ if ((gpf_ == gpl->actframe) || ((gpf_->flag & GP_FRAME_SELECT) && is_multiedit_)) { \
+ ED_gpencil_parent_location(depsgraph_, obact_, gpd_, gpl, gpstroke_iter.diff_mat); \
+ /* get derived frame with modifiers applied */ \
+ bGPDframe *derived_gpf_ = BKE_gpencil_derivedframe_get(obact_, gpl, gpl->actframe); \
+ /* loop over strokes */ \
+ for (bGPDstroke *gps = derived_gpf_->strokes.first; gps; gps = gps->next) { \
+ /* skip strokes that are invalid for current view */ \
+ if (ED_gpencil_stroke_can_use(C, gps) == false) \
+ continue; \
+ /* check if the color is editable */ \
+ if (ED_gpencil_stroke_color_use(obact_, gpl, gps) == false) \
+ continue; \
+ /* ... Do Stuff With Strokes ... */
+
+#define GP_DERIVED_STROKES_END(gpstroke_iter) \
+ } \
+ } \
+ if (!is_multiedit_) { \
+ break; \
+ } \
+ } \
+ } \
+ CTX_DATA_END; \
+ } \
+ (void)0
+
/* ****************************************************** */
#endif /* __GPENCIL_INTERN_H__ */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index ba806022d3e..52d0774d4ac 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -1328,7 +1328,8 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
/* First Pass: Find stroke point which gets hit */
/* XXX: maybe we should go from the top of the stack down instead... */
- GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
+ GP_DERIVED_STROKES_BEGIN(gpstroke_iter, C, gpl, gps)
+ {
bGPDspoint *pt;
int i;
@@ -1357,7 +1358,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
}
}
}
- GP_EDITABLE_STROKES_END(gpstroke_iter);
+ GP_DERIVED_STROKES_END(gpstroke_iter);
/* Abort if nothing hit... */
if (ELEM(NULL, hit_stroke, hit_point)) {
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index bb38311cbac..82fca695558 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -51,6 +51,11 @@ typedef struct bGPDcontrolpoint {
int size;
} bGPDcontrolpoint;
+typedef struct bGPDspoint_Runtime {
+ /** Original point (used to dereference evaluated data) */
+ struct bGPDspoint *pt_orig;
+} bGPDspoint_Runtime;
+
/* Grease-Pencil Annotations - 'Stroke Point'
* -> Coordinates may either be 2d or 3d depending on settings at the time
* -> Coordinates of point on stroke, in proportions of window size
@@ -72,6 +77,10 @@ typedef struct bGPDspoint {
float uv_fac;
/** Uv rotation for dot mode. */
float uv_rot;
+
+ /** Runtime data */
+ char _pad2[4];
+ bGPDspoint_Runtime runtime;
} bGPDspoint;
/* bGPDspoint->flag */
@@ -157,15 +166,21 @@ typedef enum eGPDpalette_Flag {
/* Runtime temp data for bGPDstroke */
typedef struct bGPDstroke_Runtime {
- /* runtime final colors (result of original colors and modifiers) */
+ /** runtime final colors (result of original colors and modifiers) */
float tmp_stroke_rgba[4];
+
+ /** runtime final fill colors (result of original colors and modifiers) */
float tmp_fill_rgba[4];
- /* temporary layer name only used during copy/paste to put the stroke in the original layer */
+ /** temporary layer name only used during copy/paste to put the stroke in the original layer */
char tmp_layerinfo[128];
/** Runtime falloff factor (only for transform). */
float multi_frame_falloff;
+ char _pad[4];
+
+ /** Original stroke (used to dereference evaluated data) */
+ struct bGPDstroke *gps_orig;
} bGPDstroke_Runtime;
/* Grease-Pencil Annotations - 'Stroke'
@@ -211,7 +226,6 @@ typedef struct bGPDstroke {
void *_pad3;
bGPDstroke_Runtime runtime;
- char _pad2[4];
} bGPDstroke;
/* bGPDstroke->flag */
More information about the Bf-blender-cvs
mailing list