3 ======================
\r
4 Metasequioa MQO format
\r
5 ======================
\r
9 * http://www.metaseq.net/metaseq/format.html
\r
13 * textencoding: bytes(cp932)
\r
14 * coordinate: right handed y-up
\r
16 * face: edge(2), triangle(3), quadrangle(4)
\r
17 * backculling: enable
\r
25 from .. import common
\r
31 class Material(object):
\r
43 tex: cp932 windows file path
\r
46 "name", "shader", "color", "diffuse",
\r
47 "ambient", "emit", "specular", "power",
\r
50 def __init__(self, name):
\r
53 self.color=common.RGBA(0.5, 0.5, 0.5, 1.0)
\r
61 def getName(self): return self.name
\r
62 def getTexture(self): return self.tex
\r
64 def parse(self, line):
\r
67 leftParenthesis=line.find(b"(", offset)
\r
68 if leftParenthesis==-1:
\r
70 key=line[offset:leftParenthesis]
\r
71 rightParenthesis=line.find(b")", leftParenthesis+1)
\r
72 if rightParenthesis==-1:
\r
73 raise ValueError("assert")
\r
75 param=line[leftParenthesis+1:rightParenthesis]
\r
77 self.shader=int(param)
\r
79 self.color=common.RGBA(*[float(e) for e in param.split()])
\r
81 self.diffuse=float(param)
\r
83 self.ambient=float(param)
\r
85 self.emit=float(param)
\r
87 self.specular=float(param)
\r
89 self.power=float(param)
\r
91 self.tex=param[1:-1]
\r
94 "%s#parse" % self.name,
\r
95 "unknown key: %s" % key
\r
98 offset=rightParenthesis+2
\r
101 return "<Material %s shader: %d [%f, %f, %f, %f] %f>" % (
\r
102 self.name, self.shader,
\r
103 self.color[0], self.color[1], self.color[2], self.color[3],
\r
112 depth: object hierarchy
\r
120 facet: smoothing threshold
\r
130 __slots__=["name", "depth", "folding",
\r
131 "scale", "rotation", "translation",
\r
132 "visible", "locking", "shading", "facet",
\r
133 "color", "color_type", "mirror", "mirror_axis",
\r
134 "vertices", "faces", "edges", "smoothing",
\r
137 def __init__(self, name):
\r
144 self.scale=[1, 1, 1]
\r
145 self.rotation=[0, 0, 0]
\r
146 self.translation=[0, 0, 0]
\r
151 self.color=[1, 1, 1]
\r
156 def getName(self): return self.name
\r
158 def addVertex(self, x, y, z):
\r
159 self.vertices.append(common.Vector3(x, y, z))
\r
161 def addFace(self, face):
\r
162 if face.index_count==2:
\r
163 self.edges.append(face)
\r
165 self.faces.append(face)
\r
168 return "<Object %s, %d vertices, %d faces>" % (
\r
169 self.name, len(self.vertices), len(self.faces))
\r
172 class Face(object):
\r
176 index_count: 2 or 3 or 4
\r
177 indices: index x index_count
\r
179 col: vertex_color x index_count
\r
180 uv: Vector2 x index_count
\r
184 "indices", "material_index", "col", "uv",
\r
186 def __init__(self, index_count, line):
\r
187 if index_count<2 or index_count>4:
\r
188 raise ValueError("invalid vertex count: %d" % index_count)
\r
189 self.material_index=0
\r
191 self.uv=[common.Vector2(0, 0)]*4
\r
192 self.index_count=index_count
\r
195 leftParenthesis=line.find(b"(", offset)
\r
196 if leftParenthesis==-1:
\r
198 key=line[offset:leftParenthesis]
\r
199 rightParenthesis=line.find(b")", leftParenthesis+1)
\r
200 if rightParenthesis==-1:
\r
201 raise ValueError("assert")
\r
202 params=line[leftParenthesis+1:rightParenthesis].split()
\r
204 self.indices=[int(e) for e in params]
\r
206 self.material_index=int(params[0])
\r
208 uv_list=[float(e) for e in params]
\r
210 for i in range(0, len(uv_list), 2):
\r
211 self.uv.append(common.Vector2(uv_list[i], uv_list[i+1]))
\r
216 d, m=divmod(d, 256)
\r
219 d, m=divmod(d, 256)
\r
222 d, m=divmod(d, 256)
\r
225 d, m=divmod(d, 256)
\r
228 print("Face#__init__:unknown key: %s" % key)
\r
230 offset=rightParenthesis+2
\r
232 def getIndex(self, i): return self.indices[i]
\r
233 def getUV(self, i): return self.uv[i] if i<len(self.uv) else common.Vector2(0, 0)
\r
236 class Model(object):
\r
237 def __init__(self):
\r
238 self.has_mikoto=False
\r