-
Notifications
You must be signed in to change notification settings - Fork 51
/
animprop.py
133 lines (127 loc) · 5.27 KB
/
animprop.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from mu import Mu
import sys
from pprint import pprint
def check_clip(clip, props, clips, path):
for curve in clip.curves:
props.add(curve.property)
if clip.name not in clips:
clips[clip.name] = {}
curves = clips[clip.name]
if curve.path not in curves:
curves[curve.path] = {}
properties = curves[curve.path]
if not hasattr(curve, "keys") or not curve.keys:
properties[curve.property] = ["0 static", []]
else:
count = len(curve.keys)
properties[curve.property] = [f"{count} static", [None] * count]
initValue = curve.keys[0].value
for i, k in enumerate(curve.keys):
properties[curve.property][1][i] = k.value
if k.value != initValue or k.tangent[0] or k.tangent[1]:
properties[curve.property][0] = f"{count} animated"
def check_obj(obj, props, anims, path, mu):
if path:
path = path + "/"
path = path + obj.transform.name
mu.objects[path] = obj
for o in obj.children:
check_obj(o, props, anims, path, mu)
if hasattr(obj, "animation"):
anims[path] = {}
for clip in obj.animation.clips:
check_clip(clip, props, anims[path], path)
def find_props(fname, props, anims):
mu = Mu()
mu.objects = {}
if not mu.read(fname):
print("could not read: " + fname)
raise
check_obj(mu.obj, props, anims, "", mu)
return mu
def nice(tup):
return "(" + ", ".join(map(lambda t:f"{t:6.3f}", tup)) + ")"
for f in sys.argv[1:]:
props = set()
anims = {}
mu = find_props(f, props, anims)
#pprint(mu.objects)
if not props:
continue
print(f)
props = list(props)
props.sort()
for p in props:
print(p)
objs = list(anims.keys())
objs.sort()
for o in objs:
print(f"{o}")
clips = list(anims[o].keys())
clips.sort()
"""for c in clips:
print(f" {c}")
paths = list(anims[o][c].keys())
paths.sort()
for p in paths:
print(f" {p}")
props = list(anims[o][c][p].keys())
props.sort()
for pr in props:
print(f" {pr}: {anims[o][c][p][pr][0]}")"""
for c in clips:
print(f" {c}")
paths = list(anims[o][c].keys())
paths.sort()
for p in paths:
propset = anims[o][c][p]
if not p:
path = o
else:
path = "/".join([o, p])
obj = mu.objects[path]
loc = obj.transform.localPosition
rot = obj.transform.localRotation
scale = obj.transform.localScale
#put back into unity format
loc = [loc[0],loc[2],loc[1]]
rot = [-rot[1],-rot[3],-rot[2],rot[0]]
scale = [scale[0],scale[2],scale[1]]
print(f" {p}")
print(f" {obj.transform.name}")
print(f" {nice(loc)} {nice(rot)} {nice(scale)}")
count = 0
for pr in propset:
count = max(count, len(propset[pr][1]))
for i in range(count):
if ("m_LocalPosition.x" in propset
and i < len(propset["m_LocalPosition.x"][1])):
loc[0] = propset["m_LocalPosition.x"][1][i]
if ("m_LocalPosition.y" in propset
and i < len(propset["m_LocalPosition.y"][1])):
loc[1] = propset["m_LocalPosition.y"][1][i]
if ("m_LocalPosition.z" in propset
and i < len(propset["m_LocalPosition.z"][1])):
loc[2] = propset["m_LocalPosition.z"][1][i]
if ("m_LocalScale.x" in propset
and i < len(propset["m_LocalScale.x"][1])):
scale[0] = propset["m_LocalScale.x"][1][i]
if ("m_LocalScale.y" in propset
and i < len(propset["m_LocalScale.y"][1])):
scale[1] = propset["m_LocalScale.y"][1][i]
if ("m_LocalScale.z" in propset
and i < len(propset["m_LocalScale.z"][1])):
scale[2] = propset["m_LocalScale.z"][1][i]
if ("m_LocalRotation.x" in propset
and i < len(propset["m_LocalRotation.x"][1])):
rot[0] = propset["m_LocalRotation.x"][1][i]
if ("m_LocalRotation.y" in propset
and i < len(propset["m_LocalRotation.y"][1])):
rot[1] = propset["m_LocalRotation.y"][1][i]
if ("m_LocalRotation.z" in propset
and i < len(propset["m_LocalRotation.z"][1])):
rot[2] = propset["m_LocalRotation.z"][1][i]
if ("m_LocalRotation.w" in propset
and i < len(propset["m_LocalRotation.w"][1])):
rot[3] = propset["m_LocalRotation.w"][1][i]
print(f" {i:4d} {nice(loc)} {nice(rot)} {nice(scale)}")