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_BYTE"))
22 if mesh.uv_layers and mesh.tangent_vecs:
23 st.append(Token("TANGENT3_BYTE"))
24 if mesh.vertices[0].color:
25 st.append(Token("COLOR4_UBYTE"))
27 for u in mesh.uv_layers:
28 size = str(len(u.uvs[0]))
29 min_val = min(*u.uvs[0])
30 max_val = max(*u.uvs[1])
32 min_val = min(min_val, *c)
33 max_val = max(max_val, *c)
34 uv_type = "USHORT" if min_val>=0.0 and max_val<=1.0 else "FLOAT"
36 st.append(Token("TEXCOORD{}_{}".format(size, uv_type)))
38 st.append(Token("TEXCOORD{}_{}_{}".format(size, u.unit, uv_type)))
39 if mesh.vertex_groups:
40 st.append(Token("GROUP{}_UBYTE".format(mesh.max_groups_per_vertex)))
41 st.append(Token("WEIGHT{}_USHORT".format(mesh.max_groups_per_vertex)))
42 st.append(Token("VERTEX3_FLOAT"))
46 uvs = [None]*len(mesh.uv_layers)
50 for v in mesh.vertices:
52 st.sub.append(Statement("normal", *v.normal))
55 st.sub.append(Statement("color", *v.color))
57 for i, u in enumerate(mesh.uv_layers):
60 st.sub.append(Statement("texcoord", *v.uvs[i]))
62 st.sub.append(Statement("multitexcoord", u.unit, *v.uvs[i]))
66 st.sub.append(Statement("tangent", *v.tan))
68 if mesh.vertex_groups:
69 v_group = [g.group for g in v.groups]
70 v_weight = [g.weight for g in v.groups]
72 st.sub.append(Statement("group", *v_group))
75 st.sub.append(Statement("weight", *v_weight))
77 st.sub.append(Statement("vertex", *v.co))
82 for s in mesh.vertex_sequence:
83 st = Statement("batch", Token("TRIANGLE_STRIP"))
84 for i in range(0, len(s), 32):
85 st.sub.append(Statement("indices", *(v.index for v in s[i:i+32])))
88 st = Statement("batch", Token('TRIANGLES'))
90 st.sub.append(Statement("indices", *(v.index for v in f.vertices)))
94 st = Statement("batch", Token('LINES'))
96 st.sub.append(Statement("indices", *(v.index for v in l.vertices)))
100 statements.append(Statement("winding", Token('COUNTERCLOCKWISE')))
102 progress.set_progress(1.0)