forked from millerhooks/close2mocap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblend_utils.py
61 lines (49 loc) · 2.06 KB
/
blend_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import bpy
def delete_unchanging_fcurves(action1, action2):
data_paths = []
for fc1, fc2 in zip(action1.fcurves, action2.fcurves):
if fc1.evaluate(0) == fc2.evaluate(0):
action1.fcurves.remove(fc1)
action2.fcurves.remove(fc2)
else:
data_paths.append(fc1.data_path + str(fc1.array_index))
return data_paths
def delete_data_paths_from_action(data_paths, action):
for fc in action.fcurves:
dp = fc.data_path + str(fc.array_index)
if not dp in data_paths:
action.fcurves.remove(fc)
def select_asset_in_browser(context, action, deselect=False):
''' select an asset in the asset browser '''
for space in context.spaces:
if hasattr(space, 'activate_asset_by_id'):
space.browse_mode = 'ASSETS'
space.activate_asset_by_id(action)
if deselect:
space.deselect_all()
def blend_between_poses(blend_factor, action, action1, arm):
''' apply a blend between two poses '''
old_area = bpy.context.area.type
arm.pose.apply_pose_from_action(action)
override = bpy.context.copy()
override['area'].type = 'FILE_BROWSER'
#select_asset_in_browser(override['area'], action1)
bpy.ops.poselib.blend_pose_asset(override, blend_factor=blend_factor)
bpy.ops.poselib.pose_asset_select_bones(override)
bpy.context.area.type = old_area
def keyframe_selected_bones(frame):
bones = bpy.context.selected_pose_bones
for bone in bones:
print(bone.name)
if bone.rotation_mode == 'QUATERNION':
rot_mode = 'rotation_quaternion'
else:
rot_mode = 'rotation_euler'
print(bone)
bone.keyframe_insert(data_path='location', frame=frame)
bone.keyframe_insert(data_path=rot_mode, frame=frame)
def add_track_with_action(animation_data, action):
track = animation_data.nla_tracks.new()
track.name = action.name
strip = track.strips.new(action.name, 1, action)
strip.blend_type = 'ADD'