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 def find_smooth_group(self, face, sg):
110 sg.faces.append(face)
116 other=e.other_face(cur)
117 if other and not other.smooth_group:
118 other.smooth_group=sg
119 sg.faces.append(other)
122 def create_strip(self, face):
125 other=e.other_face(face)
126 if other and other.smooth_group.index==face.smooth_group.index and not other.flag:
133 v1=face.get_following_vertex(edge.v1, edge.v2)
134 v2=face.get_following_vertex(v1)
135 if len(face.verts)==4:
141 print [v.index for v in result]
145 print "face =",[v.index for v in face.verts]
146 print [e.key for e in face.edges]
147 for i in range(2, len(face.verts)):
148 v=face.get_following_vertex(result[-2], result[-1])
151 print [v.index for v in result]
155 ekey=(min(i1, i2), max(i1, i2))
161 next=edge.other_face(face)
162 if next.smooth_group.index!=face.smooth_group.index or next.flag:
169 scene=Blender.Scene.GetCurrent()
171 obj=scene.getActiveObject()
172 if obj.getType()!="Mesh":
173 raise Exception, "Can only export Mesh data"
175 mesh=obj.getData(mesh=True)
177 faces=[Face(f) for f in mesh.faces]
179 edges=dict([(e.key, Edge(e)) for e in mesh.edges])
181 for e in f.edge_keys:
182 edges[e].faces.append(f)
183 f.edges.append(edges[e])
185 smooth_limit=math.cos(mesh.degr*math.pi/180)
186 for e in edges.itervalues():
187 e.check_smooth(smooth_limit)
191 if not f.smooth_group:
192 sg=SmoothGroup(len(smooth_groups))
193 smooth_groups.append(sg)
194 self.find_smooth_group(f, sg)
197 """XXX Stripping and smoothing are currently imcompatible
198 for sg in smooth_groups:
201 strip=self.create_strip(f)
203 strips.append(strip)"""
208 #print [v.index for v in strips[0]]
211 for sg in smooth_groups:
217 #print [v.index for v in strips[0]]
219 self.out_file.write("vertices NORMAL3_VERTEX3\n{\n")
221 self.out_file.write("\tnormal3 %f %f %f;\n"%tuple(v.no))
222 self.out_file.write("\tvertex3 %f %f %f;\n"%tuple(v.co))
223 self.out_file.write("};\n")
225 self.out_file.write("batch TRIANGLE_STRIP\n{\n\tindices")
227 self.out_file.write(" %u"%v.index)
228 self.out_file.write(";\n};\n")
234 self.out_file.write("batch TRIANGLES\n{\n")
236 for i in range(2, len(f.verts)):
237 self.out_file.write("\tindices %u %u %u;\n"%(f.verts[0].index, f.verts[i-1].index, f.verts[i].index))
239 self.out_file.write("};\n")
245 Blender.Window.FileSelector(self.export, "Export MSP GL mesh", Blender.sys.makename(ext='.mesh'))
247 def export(self, fn):
252 if __name__=="__main__":