diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-02-16 13:57:57 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-03-14 14:39:16 +0300 |
commit | 36e8d00aec705b06008a0bc334fe266448b4f2c2 (patch) | |
tree | 02bf0290ec6423c611e3cd4ad49c69cb77acb67e /rigify/utils/animation.py | |
parent | eabb5cddf79e5fae3ca429242cf2c6f5a272920e (diff) |
Rigify: add support for user-defined rig packages and related utilities.
As suggested by @icappielo, and after discussion with @meta-androcto,
I start a public request to commit third-party contributions already
accepted to https://github.com/eigen-value/rigify/tree/rigify_0.6_beta
Specifically, this includes:
* User-defined rig package (feature set) support by @pioverfour.
This allows users to install pre-packaged rig sets via zip
files, which become accessible together with built-in rigs,
as discussed in T52758.
https://github.com/eigen-value/rigify/pull/1
* Modularization of python script generation, allowing rigs to
add their own utility functions and operators to the generated
script. This is critical to make custom rig support really
useful.
https://github.com/eigen-value/rigify/pull/5
* The utils.py file is split into multiple modules with a backward
compatibility proxy for old functions.
* Automatic verification that different rigs don't try to create
different rig settings with the same name to alleviate increased
risk of namespace conflicts with custom rigs.
https://github.com/eigen-value/rigify/pull/7
* New utility class that implements bone layer selection UI.
https://github.com/eigen-value/rigify/pull/6
* New utilities to replace copy & pasted boilerplate code for
creating custom properties, constraints and drivers.
https://github.com/eigen-value/rigify/pull/11
Some other random changes by MAD have likely slipped through.
These changes have already been extensively discussed and accepted
into the branch by @luciorossi, so I see no reason not to commit
them to the official repository to be tested during 2.8 beta.
Reviewers: icappiello
Differential Revision: https://developer.blender.org/D4364
Diffstat (limited to 'rigify/utils/animation.py')
-rw-r--r-- | rigify/utils/animation.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/rigify/utils/animation.py b/rigify/utils/animation.py new file mode 100644 index 00000000..ab99282f --- /dev/null +++ b/rigify/utils/animation.py @@ -0,0 +1,84 @@ +#====================== BEGIN GPL LICENSE BLOCK ====================== +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#======================= END GPL LICENSE BLOCK ======================== + +# <pep8 compliant> + + +#============================================= +# Keyframing functions +#============================================= + + +def get_keyed_frames(rig): + frames = [] + if rig.animation_data: + if rig.animation_data.action: + fcus = rig.animation_data.action.fcurves + for fc in fcus: + for kp in fc.keyframe_points: + if kp.co[0] not in frames: + frames.append(kp.co[0]) + + frames.sort() + + return frames + + +def bones_in_frame(f, rig, *args): + """ + True if one of the bones listed in args is animated at frame f + :param f: the frame + :param rig: the rig + :param args: bone names + :return: + """ + + if rig.animation_data and rig.animation_data.action: + fcus = rig.animation_data.action.fcurves + else: + return False + + for fc in fcus: + animated_frames = [kp.co[0] for kp in fc.keyframe_points] + for bone in args: + if bone in fc.data_path.split('"') and f in animated_frames: + return True + + return False + + +def overwrite_prop_animation(rig, bone, prop_name, value, frames): + act = rig.animation_data.action + if not act: + return + + bone_name = bone.name + curve = None + + for fcu in act.fcurves: + words = fcu.data_path.split('"') + if words[0] == "pose.bones[" and words[1] == bone_name and words[-2] == prop_name: + curve = fcu + break + + if not curve: + return + + for kp in curve.keyframe_points: + if kp.co[0] in frames: + kp.co[1] = value |