-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathimport_sequence.py
More file actions
84 lines (73 loc) · 3.75 KB
/
import_sequence.py
File metadata and controls
84 lines (73 loc) · 3.75 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This file is currently unused
import bpy
def import_sequence(is_dsq, shape, seq):
if is_dsq:
name = shape.names[seq.nameIndex]
else:
name = seq.name
act = bpy.data.actions.new(name)
flags = ["priority {}".format(seq.priority)]
if seq.flags & Sequence.Cyclic:
flags.append("cyclic")
if seq.flags & Sequence.Blend:
flags.append("blend")
# sequences_text.append(name + ": " + ", ".join(flags))
if is_dsq:
nodes = shape.nodes
rotations = shape.rotations
else:
nodes = tuple(map(lambda n: shape.names[n.name], shape.nodes))
rotations = shape.node_rotations
if seq.flags & Sequence.UniformScale:
scales = tuple(map(lambda s: (s, s, s), shape.uniform_scales))
elif seq.flags & Sequence.AlignedScale:
scales = shape.aligned_scales
elif seq.flags & Sequence.ArbitraryScale:
print("Warning: Arbitrary scale animation not implemented")
break
else:
print("Warning: Invalid scale flags found in sequence")
break
nodes_translation = tuple(map(lambda p: p[0], filter(lambda p: p[1], zip(nodes, seq.translationMatters))))
nodes_rotation = tuple(map(lambda p: p[0], filter(lambda p: p[1], zip(nodes, seq.rotationMatters))))
nodes_scale = tuple(map(lambda p: p[0], filter(lambda p: p[1], zip(nodes, seq.scaleMatters))))
for matters_index, node_name in enumerate(nodes_translation):
data_path = 'pose.bones["{}"].location'.format(node_name)
fcus = tuple(map(lambda array_index: act.fcurves.new(data_path, array_index), range(3)))
for frame_index in range(seq.numKeyframes):
array = translations[seq.baseTranslation + matters_index * seq.numKeyframes + frame_index]
for array_index, fcu in enumerate(fcus):
fcu.keyframe_points.add(1)
key = fcu.keyframe_points[-1]
key.interpolation = "LINEAR"
key.co = (1 + frame_index, array[array_index])
for matters_index, node_name in enumerate(nodes_rotation):
data_path = 'pose.bones["{}"].rotation_quaternion'.format(node_name)
fcus = tuple(map(lambda array_index: act.fcurves.new(data_path, array_index), range(4)))
for frame_index in range(seq.numKeyframes):
array = rotations[seq.baseRotation + matters_index * seq.numKeyframes + frame_index]
for array_index, fcu in enumerate(fcus):
fcu.keyframe_points.add(1)
key = fcu.keyframe_points[-1]
key.interpolation = "LINEAR"
key.co = (1 + frame_index, array[array_index])
for matters_index, node_name in enumerate(nodes_scale):
data_path = 'pose.bones["{}"].scale'.format(node_name)
fcus = tuple(map(lambda array_index: act.fcurves.new(data_path, array_index), range(3)))
for frame_index in range(seq.numKeyframes):
array = scales[seq.baseScale + matters_index * seq.numKeyframes + frame_index]
for array_index, fcu in enumerate(fcus):
fcu.keyframe_points.add(1)
key = fcu.keyframe_points[-1]
key.interpolation = "LINEAR"
key.co = (1 + frame_index, array[array_index])
# if seq.flags & Sequence.Blend:
# if reference_frame is None:
# return fail(operator, "Missing 'reference' marker for blend animation '{}'".format(name))
# ref_vec = Vector(evaluate_all(curves, reference_frame))
# vec = ref_vec + vec
# if seq.flags & Sequence.Blend:
# if reference_frame is None:
# return fail(operator, "Missing 'reference' marker for blend animation '{}'".format(name))
# ref_rot = Quaternion(evaluate_all(curves, reference_frame))
# rot = ref_rot * rot