7 self.show_progress = True
9 self.use_degen_tris = False
10 self.material_tex = False
12 def join_strips(self, strips):
17 # Generate glue elements, ensuring that the next strip begins at
19 glue = [big_strip[-1], s[0]]
29 def export(self, context, out_file, obj=None, progress=None):
31 obj = context.active_object
33 from .mesh import create_mesh_from_object
34 from .util import Progress
37 progress = Progress(self.show_progress and context)
38 progress.push_task("", 0.0, 0.9)
40 mesh = create_mesh_from_object(context, obj, progress)
45 strips = mesh.vertex_sequence
46 if self.use_degen_tris:
47 strips = [self.join_strips(strips)]
50 progress.set_task("Writing file", 0.9, 1.0)
52 from .outfile import open_output
53 out_file = open_output(out_file)
57 for u in mesh.uv_layers:
58 size = str(len(u.uvs[0]))
60 fmt.append("TEXCOORD"+size)
62 fmt.append("TEXCOORD%s_%d"%(size, u.unit))
64 fmt += ["TANGENT3", "BINORMAL3"]
65 if mesh.vertex_groups:
66 fmt.append("ATTRIB%d_5"%(mesh.max_groups_per_vertex*2))
68 out_file.begin("vertices", *fmt)
74 for v in mesh.vertices:
76 out_file.write("normal3", *v.normal)
78 for i, u in enumerate(mesh.uv_layers):
79 if v.uvs[i]!=uvs.get(i):
80 size = str(len(v.uvs[i]))
82 out_file.write("texcoord"+size, *v.uvs[i])
84 out_file.write("multitexcoord"+size, u.unit, *v.uvs[i])
88 out_file.write("tangent3", *v.tan)
91 out_file.write("binormal3", *v.bino)
93 if mesh.vertex_groups:
94 group_attr = [(group_index_map[g.group], g.weight*v.group_weight_scale) for g in v.groups[:mesh.max_groups_per_vertex]]
95 while len(group_attr)<mesh.max_groups_per_vertex:
96 group_attr.append((0, 0.0))
97 group_attr = list(itertools.chain(*group_attr))
99 out_file.write("attrib%d"%len(group_attr), 5, *group_attr)
101 out_file.write("vertex3", *v.co)
104 out_file.begin("batch", "TRIANGLE_STRIP")
108 indices.append(v.index)
110 out_file.write("indices", *indices)
113 out_file.write("indices", *indices)
117 out_file.begin("batch", "TRIANGLES")
119 for i in range(2, len(f.vertices)):
120 out_file.write("indices", f.vertices[0].index, f.vertices[i-1].index, f.vertices[i].index)
124 out_file.begin("batch", "LINES")
126 out_file.write("indices", l.vertices[0].index, l.vertices[1].index)
129 if mesh.winding_test:
130 out_file.write("winding", "COUNTERCLOCKWISE")