From 5af716620ad362dbb119dd1682b19ed230ba7201 Mon Sep 17 00:00:00 2001 From: Antonioya Date: Wed, 24 Oct 2018 10:31:48 +0200 Subject: GP: Add new modes to Time Offset modifier --- source/blender/blenkernel/intern/gpencil_modifier.c | 9 +++++++-- .../blender/gpencil_modifiers/intern/MOD_gpenciltime.c | 17 +++++++++++++---- source/blender/makesdna/DNA_gpencil_modifier_types.h | 9 ++++++++- source/blender/makesrna/intern/rna_gpencil_modifier.c | 17 +++++++++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c index d5c1c831c2c..abf6268a9a3 100644 --- a/source/blender/blenkernel/intern/gpencil_modifier.c +++ b/source/blender/blenkernel/intern/gpencil_modifier.c @@ -480,6 +480,7 @@ int BKE_gpencil_time_modifier(Depsgraph *depsgraph, Scene *scene, Object *ob, GpencilModifierData *md; bGPdata *gpd = ob->data; const bool is_edit = GPENCIL_ANY_EDIT_MODE(gpd); + int nfra = cfra; for (md = ob->greasepencil_modifiers.first; md; md = md->next) { if (GPENCIL_MODIFIER_ACTIVE(md, is_render)) { @@ -490,13 +491,17 @@ int BKE_gpencil_time_modifier(Depsgraph *depsgraph, Scene *scene, Object *ob, } if (mti->remapTime) { - return mti->remapTime(md, depsgraph, scene, ob, gpl, cfra); + nfra = mti->remapTime(md, depsgraph, scene, ob, gpl, cfra); + /* if the frame number changed, don't evaluate more and return */ + if (nfra != cfra) { + return nfra; + } } } } /* if no time modifier, return original frame number */ - return cfra; + return nfra; } /* *************************************************** */ diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c index c72a20cc0e9..0096c6c00d5 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c @@ -71,8 +71,6 @@ static int remapTime( TimeGpencilModifierData *mmd = (TimeGpencilModifierData *)md; const int sfra = scene->r.sfra; const int efra = scene->r.efra; - const int nfra = cfra + mmd->offset; - const bool invgpl = mmd->flag & GP_SIMPLIFY_INVERT_LAYER; /* omit if filter by layer */ @@ -89,6 +87,16 @@ static int remapTime( } } + /* if fix mode, return predefined frame number */ + if (mmd->mode == GP_TIME_MODE_FIX) { + return mmd->offset; + } + + /* invert current frame number */ + if (mmd->mode == GP_TIME_MODE_REVERSE) { + cfra = efra - cfra + sfra; + } + /* apply frame scale */ cfra *= mmd->frame_scale; if (cfra > efra) { @@ -96,6 +104,8 @@ static int remapTime( } if (mmd->flag & GP_TIME_KEEP_LOOP) { + const int nfra = cfra + mmd->offset; + /* if the sum of the cfra is out scene frame range, recalc */ if (cfra + mmd->offset < sfra) { const int delta = abs(sfra - nfra); @@ -114,8 +124,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Time = { /* structName */ "TimeGpencilModifierData", /* structSize */ sizeof(TimeGpencilModifierData), /* type */ eGpencilModifierTypeType_Gpencil, - /* flags */ eGpencilModifierTypeFlag_Single | - eGpencilModifierTypeFlag_NoApply, + /* flags */ eGpencilModifierTypeFlag_NoApply, /* copyData */ copyData, diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h index 5d743350827..9d543ddbc78 100644 --- a/source/blender/makesdna/DNA_gpencil_modifier_types.h +++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h @@ -146,7 +146,7 @@ typedef struct TimeGpencilModifierData { int flag; /* flags */ int offset; float frame_scale; /* animation scale */ - char pad[4]; + int mode; } TimeGpencilModifierData; typedef enum eTimeGpencil_Flag { @@ -154,6 +154,13 @@ typedef enum eTimeGpencil_Flag { GP_TIME_KEEP_LOOP = (1 << 1), } eTimeGpencil_Flag; +typedef enum eTimeGpencil_Mode { + GP_TIME_MODE_NORMAL = 0, + GP_TIME_MODE_REVERSE = 1, + GP_TIME_MODE_FIX = 2 +} eTimeGpencil_Mode; + + typedef enum eModifyColorGpencil_Flag { GP_MODIFY_COLOR_BOTH = 0, GP_MODIFY_COLOR_STROKE = 1, diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c index bc0db0ddaea..0ef07b46309 100644 --- a/source/blender/makesrna/intern/rna_gpencil_modifier.c +++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c @@ -110,6 +110,13 @@ static const EnumPropertyItem rna_enum_gpencil_lockshift_items[] = { { 0, NULL, 0, NULL, NULL } }; +static const EnumPropertyItem rna_enum_time_mode_items[] = { + { GP_TIME_MODE_NORMAL, "NORMAL", 0, "Normal", "Apply offset in normal animation direction" }, + { GP_TIME_MODE_REVERSE, "REVERSE", 0, "Reverse", "Apply offset in reverse animation direction" }, + { GP_TIME_MODE_FIX, "FIX", 0, "Fix", "Keep frame and do not change with time" }, + { 0, NULL, 0, NULL, NULL } +}; + #endif #ifdef RNA_RUNTIME @@ -732,6 +739,12 @@ static void rna_def_modifier_gpenciltime(BlenderRNA *brna) RNA_def_struct_sdna(srna, "TimeGpencilModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_DISPLACE); + prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "mode"); + RNA_def_property_enum_items(prop, rna_enum_time_mode_items); + RNA_def_property_ui_text(prop, "Mode", ""); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + prop = RNA_def_property(srna, "layer", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "layername"); RNA_def_property_ui_text(prop, "Layer", "Layer name"); @@ -745,8 +758,8 @@ static void rna_def_modifier_gpenciltime(BlenderRNA *brna) prop = RNA_def_property(srna, "offset", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "offset"); RNA_def_property_range(prop, -INT_MAX, INT_MAX); - RNA_def_property_ui_text(prop, "Offset", - "Number of frames to offset original keyframe number"); + RNA_def_property_ui_text(prop, "Frame Offset", + "Number of frames to offset original keyframe number or frame to fix"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); prop = RNA_def_property(srna, "frame_scale", PROP_FLOAT, PROP_NONE); -- cgit v1.2.3