4 http://www.metaseq.net/metaseq/format.html
\r
10 import pymeshio.common
\r
11 import pymeshio.mqo.loader
\r
17 class Material(object):
\r
29 tex: cp932 windows file path
\r
32 "name", "shader", "color", "diffuse",
\r
33 "ambient", "emit", "specular", "power",
\r
36 def __init__(self, name):
\r
39 self.color=pymeshio.common.RGBA(0.5, 0.5, 0.5, 1.0)
\r
47 def getName(self): return self.name
\r
48 def getTexture(self): return self.tex
\r
50 def parse(self, line):
\r
53 leftParenthesis=line.find("(", offset)
\r
54 if leftParenthesis==-1:
\r
56 key=line[offset:leftParenthesis]
\r
57 rightParenthesis=line.find(")", leftParenthesis+1)
\r
58 if rightParenthesis==-1:
\r
59 raise ValueError("assert")
\r
61 param=line[leftParenthesis+1:rightParenthesis]
\r
63 self.shader=int(param)
\r
65 self.color=pymeshio.common.RGBA(*[float(e) for e in param.split()])
\r
67 self.diffuse=float(param)
\r
69 self.ambient=float(param)
\r
71 self.emit=float(param)
\r
73 self.specular=float(param)
\r
75 self.power=float(param)
\r
77 self.tex=param[1:-1]
\r
80 "%s#parse" % self.name,
\r
81 "unknown key: %s" % key
\r
84 offset=rightParenthesis+2
\r
87 return "<Material %s shader: %d [%f, %f, %f, %f] %f>" % (
\r
88 self.name, self.shader,
\r
89 self.color[0], self.color[1], self.color[2], self.color[3],
\r
98 depth: object hierarchy
\r
106 facet: smoothing threshold
\r
116 __slots__=["name", "depth", "folding",
\r
117 "scale", "rotation", "translation",
\r
118 "visible", "locking", "shading", "facet",
\r
119 "color", "color_type", "mirror", "mirror_axis",
\r
120 "vertices", "faces", "edges", "smoothing",
\r
123 def __init__(self, name):
\r
130 self.scale=[1, 1, 1]
\r
131 self.rotation=[0, 0, 0]
\r
132 self.translation=[0, 0, 0]
\r
137 self.color=[1, 1, 1]
\r
142 def getName(self): return self.name
\r
144 def addVertex(self, x, y, z):
\r
145 self.vertices.append(pymeshio.common.Vector3(x, y, z))
\r
147 def addFace(self, face):
\r
148 if face.index_count==2:
\r
149 self.edges.append(face)
\r
151 self.faces.append(face)
\r
154 return "<Object %s, %d vertices, %d faces>" % (
\r
155 self.name, len(self.vertices), len(self.faces))
\r
158 class Face(object):
\r
162 index_count: 2 or 3 or 4
\r
163 indices: index x index_count
\r
165 col: vertex_color x index_count
\r
166 uv: Vector2 x index_count
\r
170 "indices", "material_index", "col", "uv",
\r
172 def __init__(self, index_count, line):
\r
173 if index_count<2 or index_count>4:
\r
174 raise ValueError("invalid vertex count: %d" % index_count)
\r
175 self.material_index=0
\r
177 self.uv=[pymeshio.common.Vector2(0, 0)]*4
\r
178 self.index_count=index_count
\r
181 leftParenthesis=line.find("(", offset)
\r
182 if leftParenthesis==-1:
\r
184 key=line[offset:leftParenthesis]
\r
185 rightParenthesis=line.find(")", leftParenthesis+1)
\r
186 if rightParenthesis==-1:
\r
187 raise ValueError("assert")
\r
188 params=line[leftParenthesis+1:rightParenthesis].split()
\r
190 self.indices=[int(e) for e in params]
\r
192 self.material_index=int(params[0])
\r
194 uv_list=[float(e) for e in params]
\r
196 for i in range(0, len(uv_list), 2):
\r
197 self.uv.append(pymeshio.common.Vector2(uv_list[i], uv_list[i+1]))
\r
202 d, m=divmod(d, 256)
\r
205 d, m=divmod(d, 256)
\r
208 d, m=divmod(d, 256)
\r
211 d, m=divmod(d, 256)
\r
214 print("Face#__init__:unknown key: %s" % key)
\r
216 offset=rightParenthesis+2
\r
218 def getIndex(self, i): return self.indices[i]
\r
219 def getUV(self, i): return self.uv[i] if i<len(self.uv) else pymeshio.common.Vector2(0, 0)
\r
222 class Model(object):
\r
223 def __init__(self):
\r
224 self.has_mikoto=False
\r
230 def __init__(self):
\r
233 def read(self, path):
\r
234 model=pymeshio.mqo.loader.load(path)
\r
236 self.has_mikoto=model.has_mikoto
\r
237 self.materials=model.materials
\r
238 self.objects=model.objects
\r