statements.append(st)
- if mesh.use_strips:
- for s in mesh.vertex_sequence:
- st = Statement("batch", Token("TRIANGLE_STRIP"))
- for i in range(0, len(s), 32):
- st.sub.append(Statement("indices", *(v.index for v in s[i:i+32])))
- statements.append(st)
- else:
- st = Statement("batch", Token('TRIANGLES'))
- for f in mesh.faces:
- st.sub.append(Statement("indices", *(v.index for v in f.vertices)))
- statements.append(st)
-
- if mesh.lines:
- st = Statement("batch", Token('LINES'))
- for l in mesh.lines:
- st.sub.append(Statement("indices", *(v.index for v in l.vertices)))
+ for b in mesh.batches:
+ st = Statement("batch", Token(b.primitive_type))
+ for i in range(0, len(b.vertices), 32):
+ st.sub.append(Statement("indices", *(v.index for v in b.vertices[i:i+32])))
statements.append(st)
task.set_progress(1.0)
self.weight = 0.0
+class Batch:
+ def __init__(self, pt):
+ self.primitive_type = pt
+ self.vertices = []
+
+
class Face:
def __init__(self, face):
self.index = face.index
self.use_uv = mesh.use_uv
self.tangent_uvtex = mesh.tangent_uvtex
self.use_strips = mesh.use_strips
+ self.use_lines = mesh.use_lines
self.vertex_groups = mesh.vertex_groups
# Clone basic data
if normal_prop and normal_prop.texture:
self.tangent_vecs = True
- self.vertex_sequence = []
+ self.batches = []
def transform(self, matrix):
for v in self.vertices:
self.reorder_faces(subtask)
subtask = task.task("Building sequence", 1.0)
+ if self.use_strips:
+ self.build_tristrip_sequence(subtask)
+ else:
+ self.build_triangle_sequence(subtask)
+
+ if self.use_lines:
+ self.build_line_sequence()
+
+ self.reorder_vertices()
+
+ def build_tristrip_sequence(self, task):
sequence = None
for i, f in enumerate(self.faces):
if sequence:
sequence += to_add
if not sequence:
- sequence = f.vertices[:]
- self.vertex_sequence.append(sequence)
+ self.batches.append(Batch("TRIANGLE_STRIP"))
+ sequence = self.batches[-1].vertices
+ sequence += f.vertices
+
+ task.set_progress(i/len(self.faces))
+
+ def build_triangle_sequence(self, task):
+ batch = Batch("TRIANGLES")
+ for f in self.faces:
+ batch.vertices += f.vertices
+ self.batches.append(batch)
- subtask.set_progress(i/len(self.faces))
+ def build_line_sequence(self):
+ batch = Batch("LINES")
+ for l in self.lines:
+ batch.vertices += l.vertices
+ self.batches.append(batch)
self.reorder_vertices()
v.index = -1
reordered_vertices = []
- for s in self.vertex_sequence:
- for v in s:
+ for b in self.batches:
+ for v in b.vertices:
if v.index<0:
v.index = len(reordered_vertices)
reordered_vertices.append(v)