1
2 """
3 ======================
4 Metasequioa MQO format
5 ======================
6
7 file format
8 ~~~~~~~~~~~
9 * http://www.metaseq.net/metaseq/format.html
10
11 specs
12 ~~~~~
13 * textencoding: bytes(cp932)
14 * coordinate: right handed y-up
15 * uv origin:
16 * face: edge(2), triangle(3), quadrangle(4)
17 * backculling: enable
18
19 """
20
21 import os
22 import sys
23 import math
24 import warnings
25 from .. import common
26
27
28 """
29 MQO loader
30 """
32 """mqo material
33
34 Attributes:
35 name: cp932
36 shader:
37 color: rgba
38 diffuse:
39 ambient:
40 emit:
41 specular:
42 power:
43 tex: cp932 windows file path
44 """
45 __slots__=[
46 "name", "shader", "color", "diffuse",
47 "ambient", "emit", "specular", "power",
48 "tex",
49 ]
60
62 - def getTexture(self): return self.tex
63
65 offset=0
66 while True:
67 leftParenthesis=line.find(b"(", offset)
68 if leftParenthesis==-1:
69 break
70 key=line[offset:leftParenthesis]
71 rightParenthesis=line.find(b")", leftParenthesis+1)
72 if rightParenthesis==-1:
73 raise ValueError("assert")
74
75 param=line[leftParenthesis+1:rightParenthesis]
76 if key==b"shader":
77 self.shader=int(param)
78 elif key==b"col":
79 self.color=common.RGBA(*[float(e) for e in param.split()])
80 elif key==b"dif":
81 self.diffuse=float(param)
82 elif key==b"amb":
83 self.ambient=float(param)
84 elif key==b"emi":
85 self.emit=float(param)
86 elif key==b"spc":
87 self.specular=float(param)
88 elif key==b"power":
89 self.power=float(param)
90 elif key==b"tex":
91 self.tex=param[1:-1]
92 else:
93 print(
94 "%s#parse" % self.name,
95 "unknown key: %s" % key
96 )
97
98 offset=rightParenthesis+2
99
105
106
108 """mqo object
109
110 Attributes:
111 name: cp932
112 depth: object hierarchy
113 folding:
114 scale:
115 rotation:
116 translation:
117 visible:
118 locking:
119 shading:
120 facet: smoothing threshold
121 color:
122 color_type:
123 mirror: mirroring
124 mirror_axis:
125 vertices:
126 faces:
127 edges:
128 smoothing:
129 """
130 __slots__=["name", "depth", "folding",
131 "scale", "rotation", "translation",
132 "visible", "locking", "shading", "facet",
133 "color", "color_type", "mirror", "mirror_axis",
134 "vertices", "faces", "edges", "smoothing",
135 ]
136
155
157
160
166
168 return "<Object %s, %d vertices, %d faces>" % (
169 self.name, len(self.vertices), len(self.faces))
170
171
173 """mqo face
174
175 Attributes:
176 index_count: 2 or 3 or 4
177 indices: index x index_count
178 material_index:
179 col: vertex_color x index_count
180 uv: Vector2 x index_count
181 """
182 __slots__=[
183 "index_count",
184 "indices", "material_index", "col", "uv",
185 ]
187 if index_count<2 or index_count>4:
188 raise ValueError("invalid vertex count: %d" % index_count)
189 self.material_index=0
190 self.col=[]
191 self.uv=[common.Vector2(0, 0)]*4
192 self.index_count=index_count
193 offset=0
194 while True:
195 leftParenthesis=line.find(b"(", offset)
196 if leftParenthesis==-1:
197 break
198 key=line[offset:leftParenthesis]
199 rightParenthesis=line.find(b")", leftParenthesis+1)
200 if rightParenthesis==-1:
201 raise ValueError("assert")
202 params=line[leftParenthesis+1:rightParenthesis].split()
203 if key==b"V":
204 self.indices=[int(e) for e in params]
205 elif key==b"M":
206 self.material_index=int(params[0])
207 elif key==b"UV":
208 uv_list=[float(e) for e in params]
209 self.uv=[]
210 for i in range(0, len(uv_list), 2):
211 self.uv.append(common.Vector2(uv_list[i], uv_list[i+1]))
212 elif key==b"COL":
213 for n in params:
214 d=int(n)
215
216 d, m=divmod(d, 256)
217 self.col.append(m)
218
219 d, m=divmod(d, 256)
220 self.col.append(m)
221
222 d, m=divmod(d, 256)
223 self.col.append(m)
224
225 d, m=divmod(d, 256)
226 self.col.append(m)
227 else:
228 print("Face#__init__:unknown key: %s" % key)
229
230 offset=rightParenthesis+2
231
234
235
241