return getattr(self._mvert, attr)
def __cmp__(self, other):
+ if other is None:
+ return 1
return cmp(self.index, other.index)
def __str__(self):
return getattr(self._mface, attr)
def __cmp__(self, other):
+ if other is None:
+ return 1
return cmp(self.index, other.index)
def __str__(self):
verts=self.verts[:]
if reverse:
verts.reverse()
- indices=[u.index for u in vt]
- flags=[(v.index in indices) for v in verts]
+ flags=[(v in vt) for v in verts]
l=len(verts)
for i in range(l):
if flags[i] and not flags[(i+l-1)%l]:
def __getattr__(self, attr):
return getattr(self._mesh, attr)
- def split_vertices(self, debug=False):
+ def split_vertices(self, find_group_func, debug):
groups=[]
for v in self.verts:
for f in v.faces:
vg=[]
for f in v.faces:
if not f.flag:
- vg.append(self.find_group(v, f))
+ vg.append(find_group_func(v, f))
groups.append(vg)
if debug:
print " Splitting edge %s with faces %s"%(e.key, e.faces)
- if not e.smooth:
- if len(e.faces)>=2:
- k=e.faces.index(f)
- e.faces.remove(f)
- e=Edge(e)
- f.edges[j]=e
- e.faces.append(f)
- else:
- del self.edges[e.key]
+ if e.other_face(f) not in g and len(e.faces)>=2:
+ k=e.faces.index(f)
+ e.faces.remove(f)
+ e=Edge(e)
+ f.edges[j]=e
+ e.faces.append(f)
+ else:
+ del self.edges[e.key]
if e.v1==self.verts[i]:
e.v1=v
e.v2=v
e.key=make_edge_key(e.v1.index, e.v2.index)
- if not e.smooth:
- self.edges[e.key]=e
+ self.edges[e.key]=e
self.verts[i].faces.remove(f)
f.verts[f.verts.index(self.verts[i])]=v
v.faces.append(f)
- def find_group(self, vert, face):
- face_indices=[f.index for f in vert.faces]
+ def split_smooth(self, debug=False):
+ self.split_vertices(self.find_smooth_group, debug)
+
+ def split_uv(self, debug=False):
+ self.split_vertices(self.find_uv_group, debug)
+ def find_smooth_group(self, vert, face):
face.flag=True
queue=[face]
for f in queue:
for e in f.edges:
other=e.other_face(f)
- if not other or other.index not in face_indices:
+ #if not other or other.index not in face_indices:
+ if other not in vert.faces:
continue
if e.smooth:
return queue
+ def find_uv_group(self, vert, face):
+ uv=face.uv[face.verts.index(vert)]
+ face.flag=True
+ group=[face]
+ for f in vert.faces:
+ if not f.flag and f.uv[f.verts.index(vert)]==uv:
+ f.flag=True
+ group.append(f)
+ return group
+
def compute_normals(self):
for v in self.verts:
if v.faces:
# XXX Should use edges to compute normal
v.no=Blender.Mathutils.Vector(0, 0, 1)
+ def compute_uv(self):
+ for v in self.verts:
+ if v.faces:
+ v.uv=v.faces[0].uv[v.faces[0].verts.index(v)]
+
def create_strip(self, face, reverse, debug):
edge=None
for e in face.edges:
self.export_lines=True
self.debug=False
self.strip_debug=False
- self.smooth_debug=False
+ self.split_debug=False
def get_locality(self, strip):
total=0
ntris=sum([len(f.verts)-2 for f in mesh.faces])
print "Starting with %d vertices, %d faces (%d triangles) and %d edges"%(len(mesh.verts), len(mesh.faces), ntris, len(mesh.edges))
- mesh.split_vertices(self.smooth_debug)
+ mesh.split_smooth(self.split_debug)
if self.debug:
- ntris=sum([len(f.verts)-2 for f in mesh.faces])
- print "After splitting %d vertices, %d faces (%d triangles) and %d edges"%(len(mesh.verts), len(mesh.faces), ntris, len(mesh.edges))
+ print "After smooth splitting %d vertices and %d edges"%(len(mesh.verts), len(mesh.edges))
mesh.compute_normals()
+ if mesh.faceUV:
+ mesh.split_uv(self.split_debug)
+ if self.debug:
+ print "After UV splitting %d vertices and %d edges"%(len(mesh.verts), len(mesh.edges))
+
+ mesh.compute_uv()
+
strips=[]
if self.use_strips:
for f in mesh.faces:
self.export_lines=Blender.Draw.Create(self.config.get('export_lines', False))
self.debug=Blender.Draw.Create(self.config.get('debug', False))
self.strip_debug=Blender.Draw.Create(self.config.get('strip_debug', False))
- self.smooth_debug=Blender.Draw.Create(self.config.get('smooth_debug', False))
+ self.split_debug=Blender.Draw.Create(self.config.get('split_debug', False))
ret=Blender.Draw.PupBlock("Export MSP GL mesh",
[("Use strips", self.use_strips, "Generage OpenGL triangle strips"),
("Use degen tris", self.use_degen_tris, "Use degenerate triangles to combine triangle strips"),
("Debugging options"),
("Debug", self.debug),
("Debug strips", self.strip_debug),
- ("Debug smoothing", self.smooth_debug)])
+ ("Debug splitting", self.split_debug)])
if ret:
dirname=self.temp_config.get("dirname", Blender.sys.dirname(Blender.Get("filename")))
obj=bpy.data.scenes.active.objects.active
self.config['export_lines']=self.export_lines.val
self.config['debug']=self.debug.val
self.config['strip_debug']=self.strip_debug.val
- self.config['smooth_debug']=self.smooth_debug.val
+ self.config['split_debug']=self.split_debug.val
Blender.Registry.SetKey('mspgl_export', self.config, True)
import os
exp.export_lines=self.export_lines.val
exp.debug=self.debug.val
exp.strip_debug=self.strip_debug.val
- exp.smooth_debug=self.smooth_debug.val
+ exp.split_debug=self.split_debug.val
exp.export()