4 http://www.metaseq.net/metaseq/format.html
\r
10 import pymeshio.common
\r
11 import pymeshio.mqo.loader
\r
18 class Material(object):
\r
30 tex: cp932 windows file path
\r
33 "name", "shader", "color", "diffuse",
\r
34 "ambient", "emit", "specular", "power",
\r
37 def __init__(self, name):
\r
40 self.color=pymeshio.common.RGBA(0.5, 0.5, 0.5, 1.0)
\r
48 def getName(self): return self.name
\r
49 def getTexture(self): return self.tex
\r
51 def parse(self, line):
\r
54 leftParenthesis=line.find("(", offset)
\r
55 if leftParenthesis==-1:
\r
57 key=line[offset:leftParenthesis]
\r
58 rightParenthesis=line.find(")", leftParenthesis+1)
\r
59 if rightParenthesis==-1:
\r
60 raise ValueError("assert")
\r
62 param=line[leftParenthesis+1:rightParenthesis]
\r
64 self.shader=int(param)
\r
66 self.color=pymeshio.common.RGBA(*[float(e) for e in param.split()])
\r
68 self.diffuse=float(param)
\r
70 self.ambient=float(param)
\r
72 self.emit=float(param)
\r
74 self.specular=float(param)
\r
76 self.power=float(param)
\r
78 self.tex=param[1:-1]
\r
81 "%s#parse" % self.name,
\r
82 "unknown key: %s" % key
\r
85 offset=rightParenthesis+2
\r
88 return "<Material %s shader: %d [%f, %f, %f, %f] %f>" % (
\r
89 self.name, self.shader,
\r
90 self.color[0], self.color[1], self.color[2], self.color[3],
\r
99 depth: object hierarchy
\r
107 facet: smoothing threshold
\r
117 __slots__=["name", "depth", "folding",
\r
118 "scale", "rotation", "translation",
\r
119 "visible", "locking", "shading", "facet",
\r
120 "color", "color_type", "mirror", "mirror_axis",
\r
121 "vertices", "faces", "edges", "smoothing",
\r
124 def __init__(self, name):
\r
131 self.scale=[1, 1, 1]
\r
132 self.rotation=[0, 0, 0]
\r
133 self.translation=[0, 0, 0]
\r
138 self.color=[1, 1, 1]
\r
143 def getName(self): return self.name
\r
145 def addVertex(self, x, y, z):
\r
146 self.vertices.append(pymeshio.common.Vector3(x, y, z))
\r
148 def addFace(self, face):
\r
149 if face.index_count==2:
\r
150 self.edges.append(face)
\r
152 self.faces.append(face)
\r
155 return "<Object %s, %d vertices, %d faces>" % (
\r
156 self.name, len(self.vertices), len(self.faces))
\r
159 class Face(object):
\r
163 index_count: 2 or 3 or 4
\r
164 indices: index x index_count
\r
166 col: vertex_color x index_count
\r
167 uv: Vector2 x index_count
\r
171 "indices", "material_index", "col", "uv",
\r
173 def __init__(self, index_count, line):
\r
174 if index_count<2 or index_count>4:
\r
175 raise ValueError("invalid vertex count: %d" % index_count)
\r
176 self.material_index=0
\r
178 self.uv=[pymeshio.common.Vector2(0, 0)]*4
\r
179 self.index_count=index_count
\r
182 leftParenthesis=line.find("(", offset)
\r
183 if leftParenthesis==-1:
\r
185 key=line[offset:leftParenthesis]
\r
186 rightParenthesis=line.find(")", leftParenthesis+1)
\r
187 if rightParenthesis==-1:
\r
188 raise ValueError("assert")
\r
189 params=line[leftParenthesis+1:rightParenthesis].split()
\r
191 self.indices=[int(e) for e in params]
\r
193 self.material_index=int(params[0])
\r
195 uv_list=[float(e) for e in params]
\r
197 for i in range(0, len(uv_list), 2):
\r
198 self.uv.append(pymeshio.common.Vector2(uv_list[i], uv_list[i+1]))
\r
203 d, m=divmod(d, 256)
\r
206 d, m=divmod(d, 256)
\r
209 d, m=divmod(d, 256)
\r
212 d, m=divmod(d, 256)
\r
215 print("Face#__init__:unknown key: %s" % key)
\r
217 offset=rightParenthesis+2
\r
219 def getIndex(self, i): return self.indices[i]
\r
220 def getUV(self, i): return self.uv[i] if i<len(self.uv) else pymeshio.common.Vector2(0, 0)
\r
223 class Model(object):
\r
224 def __init__(self):
\r
225 self.has_mikoto=False
\r
231 def __init__(self):
\r
234 def read(self, path):
\r
235 warnings.warn("'pymeshio.mqo.IO.read' will be replaced by 'pymeshio.mqo.loader.load'")
\r
236 model=pymeshio.mqo.loader.load_from_file(path)
\r
238 self.has_mikoto=model.has_mikoto
\r
239 self.materials=model.materials
\r
240 self.objects=model.objects
\r