forked from taniwha/io_object_mu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.py
175 lines (149 loc) · 5.67 KB
/
dump.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# vim:ts=4:et
# ##### 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 #####
from mu import Mu
import sys
def dump_dict(thing, mu, level, dump_funcs):
for a in thing:
attr = thing[a]
n = attr.__class__.__name__
if n in dump_funcs:
dump_funcs[n](a, mu, attr, level)
else:
print(("%s%s = " % (" " * level, a)) + str(attr))
def dump_thing(thing, mu, level, exclude, dump_funcs):
for a in dir(thing):
if a[0] == "_" or a in ["read", "write"] or a in exclude:
continue
attr = getattr(thing, a)
n = attr.__class__.__name__
if type(attr) is dict and attr:
print(("%s%s = {" % (" " * level, a)))
dump_dict(attr, mu, level + 1, dump_funcs)
print(("%s}" % (" " * level,)))
else:
if n in dump_funcs:
dump_funcs[n](a, mu, attr, level)
else:
print(("%s%s = " % (" " * level, a)) + str(attr))
def dump_textures(mu):
print("Textures")
for i, tex in enumerate(mu.textures):
print (i, tex.name, tex.type)
def dump_mattex(name, mu, mt, level):
print("%s%s %d %s %s" %
(" " * level, name, mt.index, str(mt.scale), str(mt.offset)))
mat_dump_funcs = {
'MuMatTex': dump_mattex
}
def dump_materials(mu):
print("Materials")
for i, mat in enumerate(mu.materials):
print(i, mat.name)
dump_thing(mat, mu, 1, [], mat_dump_funcs);
def dump_renderer(name, mu, rend, level):
print("%s Renderer: %s = " % (" " * level, name))
dump_thing(rend, mu, level, [], {})
def dump_list(name, mu, lst, level):
print("%s %s[%d]" % (" " * level, name, len(lst)))
for l in lst:
print("%s %s" % (" " * (level + 1), str(l)))
mesh_dump_funcs = {
"list": dump_list,
}
def dump_mesh(name, mu, mesh, level):
print("%s Mesh: %s = %s" % (" " * level, name, str(mesh)))
#dump_thing(mesh, mu, level, [], mesh_dump_funcs)
sharedmesh_dump_funcs = {
"list": dump_list,
"MuMesh": dump_mesh,
}
def dump_skinnedmeshrenderer(name, mu, mesh, level):
print("%s SkinnedMeshRenderer: %s = %s" % (" " * level, name, str(mesh)))
#dump_thing(mesh, mu, level + 1, [], sharedmesh_dump_funcs)
def dump_light(name, mu, mesh, level):
print("%s Light: %s" % (" " * level, name))
dump_thing(mesh, mu, level, [], mesh_dump_funcs)
def dump_friction(name, mu, col, level):
print("%s Friction: %s = " % (" " * level, name))
dump_thing(col, mu, level + 1, [], {})
def dump_spring(name, mu, col, level):
print("%s Spring: %s = " % (" " * level, name))
dump_thing(col, mu, level + 1, [], {})
collider_dump_funcs = {
"MuFriction": dump_friction,
"MuSpring": dump_spring,
}
def dump_collider(name, mu, col, level):
print("%s Collider: %s = " % (" " * level, name))
dump_thing(col, mu, level + 1, [], collider_dump_funcs)
def dump_key(name, mu, key, level):
print("%s Key: %s = " % (" " * level, name))
dump_thing(key, mu, level, [], {})
def dump_curve(name, mu, curve, level):
print("%s Curve: %s = " % (" " * level, name))
dump_thing(curve, mu, level, ["keys"], {})
for i, key in enumerate(curve.keys):
dump_key("key", mu, key, level + 1)
def dump_clip(name, mu, clip, level):
print("%s Clip: %s = " % (" " * level, name))
dump_thing(clip, mu, level, ["curves", "name"], {})
for i, curve in enumerate(clip.curves):
dump_curve("curve", mu, curve, level + 1)
def dump_animation(name, mu, ani, level):
print("%s Animation: %s = " % (" " * level, name))
dump_thing(ani, mu, level, ["clips", "name"], {})
for i, clip in enumerate(ani.clips):
dump_clip(clip.name, mu, clip, level + 1)
object_dump_funcs={
"MuRenderer": dump_renderer,
"MuMesh": dump_mesh,
"MuSkinnedMeshRenderer": dump_skinnedmeshrenderer,
"MuLight": dump_light,
"MuColliderMesh": dump_collider,
"MuColliderSphere": dump_collider,
"MuColliderCapsule": dump_collider,
"MuColliderBox": dump_collider,
"MuColliderWheel": dump_collider,
"MuAnimation": dump_animation,
}
def dump_object(mu, obj, level=0):
trans = obj.transform
print("%s%s" % (" " * level, trans.name))
print("%s lp %s" % (" " * level, str(trans.localPosition)))
print("%s lr %s" % (" " * level, str(trans.localRotation)))
print("%s ls %s" % (" " * level, str(trans.localScale)))
if hasattr(obj, "tag_and_layer"):
tl = obj.tag_and_layer
print("%s %s %d" % (" " * level, tl.tag, tl.layer))
dump_thing(obj, mu, level, ["transform", "tag_and_layer", "children"],
object_dump_funcs)
for child in obj.children:
dump_object(mu, child, level + 1)
def dump(fname):
mu = Mu()
if not mu.read(fname):
print("could not read: " + fname)
raise
print(mu.version)
dump_textures(mu)
dump_materials(mu)
dump_object(mu, mu.obj)
for f in sys.argv[1:]:
print(f)
dump(f)