From 7ef0e6407e21acdcd9865651a12b40d6a3cb3c0e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 5 Sep 2007 05:50:15 +0000 Subject: [PATCH] Blender exporter: Finish triangle strip support --- mesh_export.py | 56 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/mesh_export.py b/mesh_export.py index 016db5bf..cdab35f3 100644 --- a/mesh_export.py +++ b/mesh_export.py @@ -56,7 +56,7 @@ class Face: self.edges=[] self.verts=[v for v in mf.verts] self.flag=False - + def __getattr__(self, attr): return getattr(self._mface, attr) @@ -104,6 +104,8 @@ class Exporter: self.out_file=sys.stdout else: self.out_file=file(fn, "w") + self.use_strips=True + self.use_degen_tris=True def find_smooth_group(self, face, sg): face.smooth_group=sg @@ -136,19 +138,12 @@ class Exporter: result=[v2, v1] else: result=[v1, v2] - - print edge.key - print [v.index for v in result] while 1: face.flag=True - print "face =",[v.index for v in face.verts] - print [e.key for e in face.edges] for i in range(2, len(face.verts)): v=face.get_following_vertex(result[-2], result[-1]) - print v.index result.append(v) - print [v.index for v in result] i1=result[-2].index i2=result[-1].index @@ -193,29 +188,42 @@ class Exporter: smooth_groups.append(sg) self.find_smooth_group(f, sg) - strips=[] - """XXX Stripping and smoothing are currently imcompatible for sg in smooth_groups: - for f in sg.faces: - if not f.flag: - strip=self.create_strip(f) - if strip: - strips.append(strip)""" - - for i in mesh.verts: - print i.co + sg.find_vertices() - #print [v.index for v in strips[0]] + strips=[] + if self.use_strips: + for sg in smooth_groups: + for f in sg.faces: + if not f.flag: + strip=self.create_strip(f) + if strip: + strips.append(strip) + + if self.use_degen_tris: + big_strip=[] + for s in strips: + if big_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]) + f.flag=True + + strips=[big_strip] verts=[] for sg in smooth_groups: - sg.find_vertices() for v in sg.verts: v.index=len(verts) verts.append(v) - #print [v.index for v in strips[0]] - self.out_file.write("vertices NORMAL3_VERTEX3\n{\n") for v in verts: self.out_file.write("\tnormal3 %f %f %f;\n"%tuple(v.no)) @@ -223,8 +231,12 @@ class Exporter: self.out_file.write("};\n") for s in strips: self.out_file.write("batch TRIANGLE_STRIP\n{\n\tindices") + n=0 for v in s: self.out_file.write(" %u"%v.index) + n+=1; + if n%32==0: + self.out_file.write(";\n\tindices") self.out_file.write(";\n};\n") first=True -- 2.43.0