From 18afcc17fc2c4d722504f2ad006d5066c720279c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 17 Oct 2007 11:47:16 +0000 Subject: [PATCH] Blender exporter: Fix big strip generation so that winding is retained --- mesh_export.py | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/mesh_export.py b/mesh_export.py index bafbf917..d63206dd 100644 --- a/mesh_export.py +++ b/mesh_export.py @@ -68,13 +68,16 @@ class Face: def __getattr__(self, attr): return getattr(self._mface, attr) - def get_vertices_from(self, *vt): + def get_vertices_from(self, reverse, *vt): + verts=self.verts[:] + if reverse: + verts.reverse() indices=[u.index for u in vt] - flags=[(v.index in indices) for v in self.verts] - l=len(self.verts) + flags=[(v.index in indices) for v in verts] + l=len(verts) for i in range(l): if flags[i] and not flags[(i+l-1)%l]: - return self.verts[i:]+self.verts[:i] + return verts[i:]+verts[:i] def get_edge(self, v1, v2): i1=v1.index @@ -184,7 +187,7 @@ class Exporter: sg.faces.append(other) queue.append(other) - def create_strip(self, face): + def create_strip(self, face, reverse): edge=None for e in face.edges: other=e.other_face(face) @@ -196,16 +199,16 @@ class Exporter: return None if self.strip_debug: - print "Starting strip from %s, edge %s"%([v.index for v in face.verts], (edge.v1.index, edge.v2.index)) + print "Starting strip from %s, edge %s, reverse=%s"%([v.index for v in face.verts], (edge.v1.index, edge.v2.index), reverse) - verts=face.get_vertices_from(edge.v1, edge.v2) + verts=face.get_vertices_from(reverse, edge.v1, edge.v2) if len(verts)==3: result=[verts[-1], verts[0]] else: result=[verts[-2], verts[-1]] while 1: - verts=face.get_vertices_from(*result[-2:]) + verts=face.get_vertices_from(reverse, *result[-2:]) k=len(result)%2 if self.strip_debug: print " Adding %s"%[v.index for v in verts] @@ -308,7 +311,7 @@ class Exporter: best=score if not face: break - strip=self.create_strip(face) + strip=self.create_strip(face, self.use_degen_tris and sum([len(s) for s in strips])%2) if strip: strips.append(strip) @@ -322,28 +325,23 @@ class Exporter: if self.use_degen_tris: big_strip=[] - while strips: - strip=None + for s in strips: if big_strip: - for i in range(len(strips)): - if strips[i][0].index==big_strip[-1].index: - strip=strips.pop(i) - break - if not strip: - strip=strips.pop(0) - if big_strip: - if strip[0].index!=big_strip[-1].index: - big_strip+=[big_strip[-1]] - big_strip+=[strip[0]] - big_strip+=strip + big_strip+=[big_strip[-1], s[0]] + big_strip+=s for f in faces: if not f.flag: if big_strip: big_strip+=[big_strip[-1], f.verts[0]] - big_strip+=[f.verts[i] for i in (0, 1, -1)] - if len(f.verts)==4: - big_strip.append(f.verts[-2]) + if len(big_strip)%2: + big_strip+=[f.verts[i] for i in (-1, -2, 0)] + if len(f.verts)==4: + big_strip.append(f.verts[1]) + else: + big_strip+=[f.verts[i] for i in (0, 1, -1)] + if len(f.verts)==4: + big_strip.append(f.verts[-2]) f.flag=True strips=[big_strip] @@ -416,6 +414,7 @@ class FrontEnd: exp=Exporter(fn) #exp.use_degen_tris=False #exp.debug=True + #exp.strip_debug=True exp.export() -- 2.45.2