7 def export_mesh(self, context, mesh_or_obj, progress):
8 from .mesh import Mesh, create_mesh_from_object
10 if type(mesh_or_obj)==Mesh:
13 progress.push_task("", 0.0, 0.9)
14 mesh = create_mesh_from_object(context, mesh_or_obj, progress)
17 from .datafile import Resource, Statement, Token
18 resource = Resource(mesh.name+".mesh", "mesh")
19 statements = resource.statements
21 st = Statement("vertices", Token("NORMAL3"))
22 if mesh.vertices[0].color:
23 st.append(Token("COLOR4_UBYTE"))
25 for u in mesh.uv_layers:
26 size = str(len(u.uvs[0]))
28 st.append(Token("TEXCOORD"+size))
30 st.append(Token("TEXCOORD{}_{}".format(size, u.unit)))
32 st.append(Token("TANGENT3"))
33 if mesh.vertex_groups:
34 st.append(Token("GROUP{}".format(mesh.max_groups_per_vertex)))
35 st.append(Token("WEIGHT{}".format(mesh.max_groups_per_vertex)))
36 st.append(Token("VERTEX3"))
40 uvs = [None]*len(mesh.uv_layers)
44 for v in mesh.vertices:
46 st.sub.append(Statement("normal", *v.normal))
49 st.sub.append(Statement("color", *v.color))
51 for i, u in enumerate(mesh.uv_layers):
54 st.sub.append(Statement("texcoord", *v.uvs[i]))
56 st.sub.append(Statement("multitexcoord", u.unit, *v.uvs[i]))
60 st.sub.append(Statement("tangent", *v.tan))
62 if mesh.vertex_groups:
63 v_group = [g.group for g in v.groups]
64 v_weight = [g.weight for g in v.groups]
66 st.sub.append(Statement("group", *v_group))
69 st.sub.append(Statement("weight", *v_weight))
71 st.sub.append(Statement("vertex", *v.co))
76 for s in mesh.vertex_sequence:
77 st = Statement("batch", Token("TRIANGLE_STRIP"))
78 for i in range(0, len(s), 32):
79 st.sub.append(Statement("indices", *(v.index for v in s[i:i+32])))
82 st = Statement("batch", Token('TRIANGLES'))
84 st.sub.append(Statement("indices", *(v.index for v in f.vertices)))
88 st = Statement("batch", Token('LINES'))
90 st.sub.append(Statement("indices", *(v.index for v in l.vertices)))
94 statements.append(Statement("winding", Token('COUNTERCLOCKWISE')))
96 progress.set_progress(1.0)