+ def prepare_sequence(self, progress):
+ progress.push_task("Reordering faces", 0.0, 0.5)
+ self.reorder_faces(progress)
+
+ progress.set_task("Building sequence", 0.5, 1.0)
+ sequence = None
+ for i, f in enumerate(self.faces):
+ if sequence:
+ if len(sequence)==3:
+ # Rotate the first three vertices so that the new face can be added
+ if sequence[0] in f.vertices and sequence[1] not in f.vertices:
+ sequence.append(sequence[0])
+ del sequence[0]
+ elif sequence[2] not in f.vertices and sequence[1] in f.vertices:
+ sequence.insert(0, sequence[-1])
+ del sequence[-1]
+
+ if sequence[-1] not in f.vertices:
+ sequence = None
+ else:
+ to_add = [v for v in f.vertices if v!=sequence[-1] and v!=sequence[-2]]
+ if len(to_add)==2:
+ if (f.vertices[1]==sequence[-1]) != (len(sequence)%2==1):
+ to_add.reverse()
+ sequence.append(sequence[-1])
+ sequence += to_add
+
+ if not sequence:
+ sequence = f.vertices[:]
+ self.vertex_sequence.append(sequence)
+
+ progress.set_progress(i/len(self.faces))
+
+ progress.pop_task()
+
+ self.reorder_vertices()
+
+ def reorder_faces(self, progress):
+ # Tom Forsyth's vertex cache optimization algorithm
+ # http://eelpi.gotdns.org/papers/fast_vert_cache_opt.html
+