+ strip=mesh.create_strip(face, self.use_degen_tris and sum([len(s) for s in strips])%2, self.strip_debug)
+ if strip:
+ strips.append(strip)
+
+ if self.debug:
+ print "%d strips:"%len(strips)
+ for i in range(len(strips)):
+ print " %d: %d indices"%(i, len(strips[i]))
+ print "%d loose faces"%len([f for f in mesh.faces if not f.flag])
+ nind=sum([len(s) for s in strips])+sum([len(f.verts) for f in mesh.faces if not f.flag])
+ print "%d indices total"%nind
+
+ if self.use_degen_tris and strips:
+ big_strip=[]
+ for s in strips:
+ if big_strip:
+ big_strip+=[big_strip[-1], s[0]]
+ big_strip+=s
+
+ for f in mesh.faces:
+ if not f.flag:
+ if len(big_strip)%2:
+ order=(-1, -2, 0, 1)
+ else:
+ order=(0, 1, -1, -2)
+ if big_strip:
+ big_strip+=[big_strip[-1], f.verts[order[0]]]
+ big_strip+=[f.verts[i] for i in order[:len(f.verts)]]
+ f.flag=True
+
+ strips=[big_strip]
+
+ if self.debug:
+ nind=len(big_strip)
+ print "Big strip has %d indices"%len(big_strip)
+
+ if self.debug:
+ print "%.2f indices per triangle"%(float(nind)/max(ntris, 1))
+ print "Locality before optimization: "+" ".join(["%.3f"%self.get_locality(s) for s in strips])
+
+ if self.optimize_locality and self.use_strips and strips:
+ followers={}
+ for s in strips:
+ followers.update(self.get_followers(s))
+
+ verts2=[]
+ vert=strips[0][0]
+ while 1:
+ vert.flag=True
+ verts2.append(vert)
+
+ next=None
+ if vert.index in followers:
+ flw=followers[vert.index]
+ best=0
+ for n in flw:
+ if flw[n]>best and not mesh.verts[n].flag:
+ next=mesh.verts[n]
+ best=flw[n]+0.9/abs(vert.index-n)
+
+ if not next:
+ for v in mesh.verts:
+ if not v.flag:
+ next=v
+ break
+ if not next:
+ break
+
+ vert=next
+
+ mesh.verts=verts2
+
+ for i in range(len(mesh.verts)):
+ mesh.verts[i].index=i
+
+ if self.debug:
+ print "Locality after optimization: "+" ".join(["%.3f"%self.get_locality(s) for s in strips])
+
+ self.out_file.write("vertices NORMAL3")
+ if mesh.faceUV:
+ self.out_file.write("_TEXCOORD2")
+ self.out_file.write("_VERTEX3\n{\n")
+ norm=None
+ uv=None
+ for v in mesh.verts:
+ if v.no!=norm:
+ self.out_file.write("\tnormal3 %f %f %f;\n"%tuple(v.no))
+ norm=v.no
+ if v.uv!=uv:
+ self.out_file.write("\ttexcoord2 %f %f;\n"%tuple(v.uv))
+ uv=v.uv