Skip to content

Commit 0429a69

Browse files
angavriloveigen-value
authored andcommitted
Split the single utils.py file into a package of modules.
1 parent da965a5 commit 0429a69

File tree

13 files changed

+1841
-1579
lines changed

13 files changed

+1841
-1579
lines changed

utils.py

Lines changed: 0 additions & 1579 deletions
This file was deleted.

utils/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# These forwarding imports are for backwards compatibility with legacy code
2+
# that expects a single utils.py file. New code should import directly from
3+
# the modules that contain the utilities. Also, don't add more imports here.
4+
5+
from .errors import MetarigError
6+
7+
from .misc import angle_on_plane, linsrgb_to_srgb, gamma_correct, copy_attributes
8+
9+
from .naming import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, ROOT_NAME
10+
from .naming import strip_trailing_number, unique_name, org_name, strip_org, strip_mch, strip_def
11+
from .naming import org, make_original_name, mch, make_mechanism_name, deformer, make_deformer_name
12+
from .naming import insert_before_lr, random_id
13+
14+
from .bones import new_bone, copy_bone_simple, copy_bone, flip_bone, put_bone, make_nonscaling_child
15+
from .bones import align_bone_roll, align_bone_x_axis, align_bone_z_axis, align_bone_y_axis
16+
17+
from .widgets import WGT_PREFIX, WGT_LAYERS, obj_to_bone, create_widget, write_widget, create_circle_polygon
18+
19+
from .widgets_basic import create_line_widget, create_circle_widget, create_cube_widget, create_chain_widget
20+
from .widgets_basic import create_sphere_widget, create_limb_widget, create_bone_widget
21+
22+
from .widgets_special import create_compass_widget, create_root_widget
23+
from .widgets_special import create_neck_bend_widget, create_neck_tweak_widget
24+
25+
from .animation import get_keyed_frames, bones_in_frame, overwrite_prop_animation
26+
27+
from .glue import make_constraints_from_string
28+
29+
from .rig import RIG_DIR, METARIG_DIR, MODULE_NAME, outdated_types, upgradeMetarigTypes
30+
from .rig import get_rig_type, get_metarig_module, write_metarig
31+
from .rig import connected_children_names, has_connected_children
32+
33+
from .layers import get_layers

utils/animation.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#====================== BEGIN GPL LICENSE BLOCK ======================
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU General Public License
5+
# as published by the Free Software Foundation; either version 2
6+
# of the License, or (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program; if not, write to the Free Software Foundation,
15+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16+
#
17+
#======================= END GPL LICENSE BLOCK ========================
18+
19+
# <pep8 compliant>
20+
21+
22+
#=============================================
23+
# Keyframing functions
24+
#=============================================
25+
26+
27+
def get_keyed_frames(rig):
28+
frames = []
29+
if rig.animation_data:
30+
if rig.animation_data.action:
31+
fcus = rig.animation_data.action.fcurves
32+
for fc in fcus:
33+
for kp in fc.keyframe_points:
34+
if kp.co[0] not in frames:
35+
frames.append(kp.co[0])
36+
37+
frames.sort()
38+
39+
return frames
40+
41+
42+
def bones_in_frame(f, rig, *args):
43+
"""
44+
True if one of the bones listed in args is animated at frame f
45+
:param f: the frame
46+
:param rig: the rig
47+
:param args: bone names
48+
:return:
49+
"""
50+
51+
if rig.animation_data and rig.animation_data.action:
52+
fcus = rig.animation_data.action.fcurves
53+
else:
54+
return False
55+
56+
for fc in fcus:
57+
animated_frames = [kp.co[0] for kp in fc.keyframe_points]
58+
for bone in args:
59+
if bone in fc.data_path.split('"') and f in animated_frames:
60+
return True
61+
62+
return False
63+
64+
65+
def overwrite_prop_animation(rig, bone, prop_name, value, frames):
66+
act = rig.animation_data.action
67+
if not act:
68+
return
69+
70+
bone_name = bone.name
71+
curve = None
72+
73+
for fcu in act.fcurves:
74+
words = fcu.data_path.split('"')
75+
if words[0] == "pose.bones[" and words[1] == bone_name and words[-2] == prop_name:
76+
curve = fcu
77+
break
78+
79+
if not curve:
80+
return
81+
82+
for kp in curve.keyframe_points:
83+
if kp.co[0] in frames:
84+
kp.co[1] = value

0 commit comments

Comments
 (0)