5 Name: 'MSP GL Mesh (.mesh)...'
16 def __init__(self, me):
21 def __getattr__(self, attr):
22 return getattr(self._medge, attr)
24 def check_smooth(self, limit):
25 if len(self.faces)!=2:
28 d=Blender.Mathutils.DotVecs(self.faces[0].no, self.faces[1].no)
29 if (d>limit and self.faces[0].smooth and self.faces[1].smooth) or d>0.999:
32 def other_face(self, f):
33 if f.index==self.faces[0].index:
34 if len(self.faces)>=2:
43 def __init__(self, mv):
44 if mv.__class__==Vertex:
49 def __getattr__(self, attr):
50 return getattr(self._mvert, attr)
54 def __init__(self, mf):
56 self.smooth_group=None
58 self.verts=[v for v in mf.verts]
61 def __getattr__(self, attr):
62 return getattr(self._mface, attr)
64 def get_following_vertex(self, *vt):
66 indices=[v.index for v in vt]
68 if v.index in indices:
80 def __init__(self, index):
85 def find_vertices(self):
88 for i in range(len(f.verts)):
90 if v.index not in vert_map:
98 f.verts[i]=vert_map[v.index]
102 def __init__(self, fn):
105 self.out_file=sys.stdout
107 self.out_file=file(fn, "w")
109 self.use_degen_tris=True
111 def find_smooth_group(self, face, sg):
113 sg.faces.append(face)
119 other=e.other_face(cur)
120 if other and not other.smooth_group:
121 other.smooth_group=sg
122 sg.faces.append(other)
125 def create_strip(self, face):
128 other=e.other_face(face)
129 if other and other.smooth_group.index==face.smooth_group.index and not other.flag:
136 v1=face.get_following_vertex(edge.v1, edge.v2)
137 v2=face.get_following_vertex(v1)
138 if len(face.verts)==4:
145 for i in range(2, len(face.verts)):
146 v=face.get_following_vertex(result[-2], result[-1])
151 ekey=(min(i1, i2), max(i1, i2))
157 next=edge.other_face(face)
158 if next.smooth_group.index!=face.smooth_group.index or next.flag:
165 scene=bpy.data.scenes.active
167 obj=scene.objects.active
168 if obj.getType()!="Mesh":
169 raise Exception, "Can only export Mesh data"
171 mesh=obj.getData(mesh=True)
173 faces=[Face(f) for f in mesh.faces]
175 edges=dict([(e.key, Edge(e)) for e in mesh.edges])
177 for e in f.edge_keys:
178 edges[e].faces.append(f)
179 f.edges.append(edges[e])
181 smooth_limit=math.cos(mesh.degr*math.pi/180)
182 for e in edges.itervalues():
183 e.check_smooth(smooth_limit)
187 if not f.smooth_group:
188 sg=SmoothGroup(len(smooth_groups))
189 smooth_groups.append(sg)
190 self.find_smooth_group(f, sg)
192 for sg in smooth_groups:
197 for sg in smooth_groups:
200 strip=self.create_strip(f)
204 if self.use_degen_tris:
208 big_strip+=[big_strip[-1], s[0]]
214 big_strip+=[big_strip[-1], f.verts[0]]
215 big_strip+=[f.verts[i] for i in (0, 1, -1)]
217 big_strip.append(f.verts[-2])
223 for sg in smooth_groups:
228 self.out_file.write("vertices NORMAL3_VERTEX3\n{\n")
230 self.out_file.write("\tnormal3 %f %f %f;\n"%tuple(v.no))
231 self.out_file.write("\tvertex3 %f %f %f;\n"%tuple(v.co))
232 self.out_file.write("};\n")
234 self.out_file.write("batch TRIANGLE_STRIP\n{\n\tindices")
237 self.out_file.write(" %u"%v.index)
240 self.out_file.write(";\n\tindices")
241 self.out_file.write(";\n};\n")
247 self.out_file.write("batch TRIANGLES\n{\n")
249 for i in range(2, len(f.verts)):
250 self.out_file.write("\tindices %u %u %u;\n"%(f.verts[0].index, f.verts[i-1].index, f.verts[i].index))
252 self.out_file.write("};\n")
258 Blender.Window.FileSelector(self.export, "Export MSP GL mesh", Blender.sys.makename(ext='.mesh'))
260 def export(self, fn):
265 if __name__=="__main__":