5 Name: 'MSP GL Mesh (.mesh)...'
15 def __init__(self, me):
20 def __getattr__(self, attr):
21 return getattr(self._medge, attr)
23 def check_smooth(self, limit):
24 if len(self.faces)!=2:
27 d=Blender.Mathutils.DotVecs(self.faces[0].no, self.faces[1].no)
28 if (d>limit and self.faces[0].smooth and self.faces[1].smooth) or d>0.999:
31 def other_face(self, f):
32 if f.index==self.faces[0].index:
33 if len(self.faces)>=2:
42 def __init__(self, mv):
43 if mv.__class__==Vertex:
48 def __getattr__(self, attr):
49 return getattr(self._mvert, attr)
53 def __init__(self, mf):
55 self.smooth_group=None
57 self.verts=[v for v in mf.verts]
60 def __getattr__(self, attr):
61 return getattr(self._mface, attr)
63 def get_following_vertex(self, *vt):
65 indices=[v.index for v in vt]
67 if v.index in indices:
79 def __init__(self, index):
84 def find_vertices(self):
87 for i in range(len(f.verts)):
89 if v.index not in vert_map:
97 f.verts[i]=vert_map[v.index]
101 def __init__(self, fn):
104 self.out_file=sys.stdout
106 self.out_file=file(fn, "w")
108 self.use_degen_tris=True
110 def find_smooth_group(self, face, sg):
112 sg.faces.append(face)
118 other=e.other_face(cur)
119 if other and not other.smooth_group:
120 other.smooth_group=sg
121 sg.faces.append(other)
124 def create_strip(self, face):
127 other=e.other_face(face)
128 if other and other.smooth_group.index==face.smooth_group.index and not other.flag:
135 v1=face.get_following_vertex(edge.v1, edge.v2)
136 v2=face.get_following_vertex(v1)
137 if len(face.verts)==4:
144 for i in range(2, len(face.verts)):
145 v=face.get_following_vertex(result[-2], result[-1])
150 ekey=(min(i1, i2), max(i1, i2))
156 next=edge.other_face(face)
157 if next.smooth_group.index!=face.smooth_group.index or next.flag:
164 scene=Blender.Scene.GetCurrent()
166 obj=scene.getActiveObject()
167 if obj.getType()!="Mesh":
168 raise Exception, "Can only export Mesh data"
170 mesh=obj.getData(mesh=True)
172 faces=[Face(f) for f in mesh.faces]
174 edges=dict([(e.key, Edge(e)) for e in mesh.edges])
176 for e in f.edge_keys:
177 edges[e].faces.append(f)
178 f.edges.append(edges[e])
180 smooth_limit=math.cos(mesh.degr*math.pi/180)
181 for e in edges.itervalues():
182 e.check_smooth(smooth_limit)
186 if not f.smooth_group:
187 sg=SmoothGroup(len(smooth_groups))
188 smooth_groups.append(sg)
189 self.find_smooth_group(f, sg)
191 for sg in smooth_groups:
196 for sg in smooth_groups:
199 strip=self.create_strip(f)
203 if self.use_degen_tris:
207 big_strip+=[big_strip[-1], s[0]]
213 big_strip+=[big_strip[-1], f.verts[0]]
214 big_strip+=[f.verts[i] for i in (0, 1, -1)]
216 big_strip.append(f.verts[-2])
222 for sg in smooth_groups:
227 self.out_file.write("vertices NORMAL3_VERTEX3\n{\n")
229 self.out_file.write("\tnormal3 %f %f %f;\n"%tuple(v.no))
230 self.out_file.write("\tvertex3 %f %f %f;\n"%tuple(v.co))
231 self.out_file.write("};\n")
233 self.out_file.write("batch TRIANGLE_STRIP\n{\n\tindices")
236 self.out_file.write(" %u"%v.index)
239 self.out_file.write(";\n\tindices")
240 self.out_file.write(";\n};\n")
246 self.out_file.write("batch TRIANGLES\n{\n")
248 for i in range(2, len(f.verts)):
249 self.out_file.write("\tindices %u %u %u;\n"%(f.verts[0].index, f.verts[i-1].index, f.verts[i].index))
251 self.out_file.write("};\n")
257 Blender.Window.FileSelector(self.export, "Export MSP GL mesh", Blender.sys.makename(ext='.mesh'))
259 def export(self, fn):
264 if __name__=="__main__":