GPencil: Show only first frame if current frame is equals or greater than current frame

Previously, the first frame was displayed from frame 0, but now, the first frame is only displayed when the current frame is equal or greater than the keyframe number.

The previous system was logical when the grease pencil was not an object, but now it seems more logical to display the keyframe if the current frame is equal to or greater than the keyframe number.

Reviewed By: mendio, pepeland

Differential Revision: https://developer.blender.org/D7851
This commit is contained in:
Antonio Vazquez 2020-06-08 09:01:07 +02:00
parent 917ab4fbf9
commit 11ba9eec70
Notes: blender-bot 2023-02-14 03:59:42 +01:00
Referenced by commit fbf6eb509a, Fix T77869: GPencil material preview not visible before frame 2
Referenced by issue #85035, Grease pencil frames not rendered in background mode
Referenced by issue #78637, GPencil; Strokes disappear when new strokes are drawn
Referenced by issue #77869, GPencil: Material Preview Is Not Shown
3 changed files with 43 additions and 3 deletions

View File

@ -1011,6 +1011,12 @@ bGPDframe *BKE_gpencil_layer_frame_get(bGPDlayer *gpl, int cframe, eGP_GetFrame_
}
}
/* Don't select first frame if greater than current frame. */
if ((gpl->actframe != NULL) && (gpl->actframe == gpl->frames.first) &&
(gpl->actframe->framenum > cframe)) {
gpl->actframe = NULL;
}
/* return */
return gpl->actframe;
}
@ -1878,6 +1884,7 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
bGPdata *gpd = (bGPdata *)ob->data;
const bool is_multiedit = GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
const bool is_onion = do_onion && ((gpd->flag & GP_DATA_STROKE_WEIGHTMODE) == 0);
const bool is_drawing = (gpd->runtime.sbuffer_used > 0);
/* Onion skinning. */
const bool onion_mode_abs = (gpd->onion_mode == GP_ONION_MODE_ABSOLUTE);
@ -1886,6 +1893,8 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
const short onion_keytype = gpd->onion_keytype;
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
/* Reset by layer. */
bool is_before_first = false;
bGPDframe *act_gpf = gpl->actframe;
bGPDframe *sta_gpf = act_gpf;
@ -1924,6 +1933,16 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
}
}
else if (is_onion && (gpl->onion_flag & GP_LAYER_ONIONSKIN)) {
/* Special cases when cframe is before first frame. */
bGPDframe *gpf_first = gpl->frames.first;
if ((gpf_first != NULL) && (act_gpf != NULL) && (gpf_first->framenum > act_gpf->framenum)) {
is_before_first = true;
}
if ((gpf_first != NULL) && (act_gpf == NULL)) {
act_gpf = gpf_first;
is_before_first = true;
}
if (act_gpf) {
bGPDframe *last_gpf = gpl->frames.last;
@ -1938,6 +1957,10 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
int delta = (onion_mode_abs) ? (gpf->framenum - cfra) :
(gpf->runtime.frameid - act_gpf->runtime.frameid);
if (is_before_first) {
delta++;
}
if (onion_mode_sel) {
is_in_range = (gpf->flag & GP_FRAME_SELECT) != 0;
}
@ -1957,7 +1980,9 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
gpf->runtime.onion_id = (is_wrong_keytype || !is_in_range) ? INT_MAX : delta;
}
/* Active frame is always shown. */
act_gpf->runtime.onion_id = 0;
if (!is_before_first || is_drawing) {
act_gpf->runtime.onion_id = 0;
}
}
sta_gpf = gpl->frames.first;
@ -1977,10 +2002,15 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
/* Draw multiedit/onion skinning first */
for (bGPDframe *gpf = sta_gpf; gpf && gpf != end_gpf; gpf = gpf->next) {
if (gpf->runtime.onion_id == INT_MAX || gpf == act_gpf) {
if ((gpf->runtime.onion_id == INT_MAX || gpf == act_gpf) && (!is_before_first)) {
continue;
}
/* Only do once for frame before first. */
if (is_before_first && gpf == act_gpf) {
is_before_first = false;
}
if (layer_cb) {
layer_cb(gpl, gpf, NULL, thunk);
}
@ -1995,8 +2025,8 @@ void BKE_gpencil_visible_stroke_iter(ViewLayer *view_layer,
/* Draw Active frame on top. */
/* Use evaluated frame (with modifiers for active stroke)/ */
act_gpf = gpl->actframe;
act_gpf->runtime.onion_id = 0;
if (act_gpf) {
act_gpf->runtime.onion_id = 0;
if (layer_cb) {
layer_cb(gpl, act_gpf, NULL, thunk);
}

View File

@ -2127,7 +2127,12 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
add_frame_mode = GP_GETFRAME_ADD_NEW;
}
bool need_tag = p->gpl->actframe == NULL;
p->gpf = BKE_gpencil_layer_frame_get(p->gpl, CFRA, add_frame_mode);
/* Only if there wasn't an active frame, need update. */
if (need_tag) {
DEG_id_tag_update(&p->gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
}
if (p->gpf == NULL) {
p->status = GP_STATUS_ERROR;

View File

@ -1308,7 +1308,12 @@ static void gpencil_primitive_interaction_end(bContext *C,
add_frame_mode = GP_GETFRAME_ADD_NEW;
}
bool need_tag = tgpi->gpl->actframe == NULL;
gpf = BKE_gpencil_layer_frame_get(tgpi->gpl, tgpi->cframe, add_frame_mode);
/* Only if there wasn't an active frame, need update. */
if (need_tag) {
DEG_id_tag_update(&tgpi->gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
}
/* prepare stroke to get transferred */
gps = tgpi->gpf->strokes.first;