- for f in mesh.faces:
- f.flag = False
-
- while 1:
- best = 5
- face = None
- for f in mesh.faces:
- if f.flag:
- continue
- score = 0
- for e in f.edges:
- other = e.other_face(f)
- if other and not other.flag:
- score += 1
- if score>0 and score<best:
- face = f
- best = score
-
- if not face:
- break
-
- 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])