diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-11 21:16:46 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-11 21:20:21 +0300 |
commit | ebc44aae9897607a7d19a642d1a2fdffa2b24400 (patch) | |
tree | 43191d4c9a91688403d63e79c76b61c509c060b0 /source/blender | |
parent | 83d35c25d0fcc9b095ef1a0e1c5c290bb04d3017 (diff) |
Python API: expose more keyframing flags for use in keyframe_insert.
Expose REPLACE and CYCLE_AWARE, and add AVAILABLE for completeness.
These flags are generic and safe to use, and necessary to match
the behavior of certain UI options.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/animation/keyframing.c | 8 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_anim_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_animation.c | 37 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_anim.c | 12 |
5 files changed, 52 insertions, 8 deletions
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index a0433b49b16..97d85d25d66 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -1307,8 +1307,8 @@ static bool insert_keyframe_fcurve_value(Main *bmain, * - if we're replacing keyframes only, DO NOT create new F-Curves if they do not exist yet * but still try to get the F-Curve if it exists... */ - FCurve *fcu = verify_fcurve( - bmain, act, group, ptr, rna_path, array_index, (flag & INSERTKEY_REPLACE) == 0); + bool can_create_curve = (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) == 0; + FCurve *fcu = verify_fcurve(bmain, act, group, ptr, rna_path, array_index, can_create_curve); /* we may not have a F-Curve when we're replacing only... */ if (fcu) { @@ -1432,7 +1432,7 @@ short insert_keyframe(Main *bmain, /* Key the entire array. */ if (array_index == -1 || force_all) { /* In force mode, if any of the curves succeeds, drop the replace mode and restart. */ - if (force_all && (flag & INSERTKEY_REPLACE) != 0) { + if (force_all && (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) != 0) { int exclude = -1; for (array_index = 0; array_index < value_count; array_index++) { @@ -1455,7 +1455,7 @@ short insert_keyframe(Main *bmain, } if (exclude != -1) { - flag &= ~INSERTKEY_REPLACE; + flag &= ~(INSERTKEY_REPLACE | INSERTKEY_AVAILABLE); for (array_index = 0; array_index < value_count; array_index++) { if (array_index != exclude) { diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index fbb720ad0b1..ecf587301c7 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -970,6 +970,8 @@ typedef enum eInsertKeyFlags { INSERTKEY_DRIVER = (1 << 8), /** for cyclic FCurves, adjust key timing to preserve the cycle period and flow */ INSERTKEY_CYCLE_AWARE = (1 << 9), + /** don't create new F-Curves (implied by INSERTKEY_REPLACE) */ + INSERTKEY_AVAILABLE = (1 << 10), } eInsertKeyFlags; /* ************************************************ */ diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 119186ff748..02aaef44a1f 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -96,6 +96,7 @@ extern const EnumPropertyItem rna_enum_keyblock_type_items[]; extern const EnumPropertyItem rna_enum_keyingset_path_grouping_items[]; extern const EnumPropertyItem rna_enum_keying_flag_items[]; +extern const EnumPropertyItem rna_enum_keying_flag_items_api[]; extern const EnumPropertyItem rna_enum_keyframe_paste_offset_items[]; extern const EnumPropertyItem rna_enum_keyframe_paste_merge_items[]; diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index 15429ec6b5e..5970149273e 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -72,6 +72,43 @@ const EnumPropertyItem rna_enum_keying_flag_items[] = { {0, NULL, 0, NULL, NULL}, }; +/* Contains additional flags suitable for use in Python API functions. */ +const EnumPropertyItem rna_enum_keying_flag_items_api[] = { + {INSERTKEY_NEEDED, + "INSERTKEY_NEEDED", + 0, + "Only Needed", + "Only insert keyframes where they're needed in the relevant F-Curves"}, + {INSERTKEY_MATRIX, + "INSERTKEY_VISUAL", + 0, + "Visual Keying", + "Insert keyframes based on 'visual transforms'"}, + {INSERTKEY_XYZ2RGB, + "INSERTKEY_XYZ_TO_RGB", + 0, + "XYZ=RGB Colors", + "Color for newly added transformation F-Curves (Location, Rotation, Scale) " + "and also Color is based on the transform axis"}, + {INSERTKEY_REPLACE, + "INSERTKEY_REPLACE", + 0, + "Replace Existing", + "Only replace existing keyframes"}, + {INSERTKEY_AVAILABLE, + "INSERTKEY_AVAILABLE", + 0, + "Only Available", + "Don't create F-Curves when they don't already exist"}, + {INSERTKEY_CYCLE_AWARE, + "INSERTKEY_CYCLE_AWARE", + 0, + "Cycle Aware Keying", + "When inserting into a curve with cyclic extrapolation, remap the keyframe inside " + "the cycle time range, and if changing an end key, also update the other one"}, + {0, NULL, 0, NULL, NULL}, +}; + #ifdef RNA_RUNTIME # include "BLI_math_base.h" diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 79c31c8caad..710ae0433e0 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -263,8 +263,9 @@ static int pyrna_struct_keyframe_parse(PointerRNA *ptr, /* flag may be null (no option currently for remove keyframes e.g.). */ if (r_options) { - if (pyoptions && (pyrna_set_to_enum_bitfield( - rna_enum_keying_flag_items, pyoptions, r_options, error_prefix) == -1)) { + if (pyoptions && + (pyrna_set_to_enum_bitfield( + rna_enum_keying_flag_items_api, pyoptions, r_options, error_prefix) == -1)) { return -1; } @@ -299,8 +300,11 @@ char pyrna_struct_keyframe_insert_doc[] = "F-Curves.\n" " - ``INSERTKEY_VISUAL`` Insert keyframes based on 'visual transforms'.\n" " - ``INSERTKEY_XYZ_TO_RGB`` Color for newly added transformation F-Curves (Location, " - "Rotation, Scale)\n" - " and also Color is based on the transform axis.\n" + "Rotation, Scale) is based on the transform axis.\n" + " - ``INSERTKEY_REPLACE`` Only replace already exising keyframes.\n" + " - ``INSERTKEY_AVAILABLE`` Only insert into already existing F-Curves.\n" + " - ``INSERTKEY_CYCLE_AWARE`` Take cyclic extrapolation into account " + "(Cycle-Aware Keying option).\n" " :type flag: set\n" " :return: Success of keyframe insertion.\n" " :rtype: boolean\n"; |