]> git.tdb.fi Git - libs/gl.git/commitdiff
Use more compact data types when exporting meshes
authorMikko Rasa <tdb@tdb.fi>
Wed, 15 Sep 2021 14:58:23 +0000 (17:58 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 15 Sep 2021 18:34:11 +0000 (21:34 +0300)
blender/io_mspgl/export_mesh.py

index 2a8dbe0057062411541507d1faf6fad0509e9812..7bb4e224c58a099ef13a571fc8db5f597f57a764 100644 (file)
@@ -18,22 +18,28 @@ class MeshExporter:
                resource = Resource(mesh.name+".mesh", "mesh")
                statements = resource.statements
 
-               st = Statement("vertices", Token("NORMAL3"))
+               st = Statement("vertices", Token("NORMAL3_BYTE"))
+               if mesh.uv_layers and mesh.tangent_vecs:
+                       st.append(Token("TANGENT3_BYTE"))
                if mesh.vertices[0].color:
                        st.append(Token("COLOR4_UBYTE"))
                if mesh.uv_layers:
                        for u in mesh.uv_layers:
                                size = str(len(u.uvs[0]))
+                               min_val = min(*u.uvs[0])
+                               max_val = max(*u.uvs[1])
+                               for c in u.uvs:
+                                       min_val = min(min_val, *c)
+                                       max_val = max(max_val, *c)
+                               uv_type = "USHORT" if min_val>=0.0 and max_val<=1.0 else "FLOAT"
                                if u.unit==0:
-                                       st.append(Token("TEXCOORD"+size))
+                                       st.append(Token("TEXCOORD{}_{}".format(size, uv_type)))
                                else:
-                                       st.append(Token("TEXCOORD{}_{}".format(size, u.unit)))
-                       if mesh.tangent_vecs:
-                               st.append(Token("TANGENT3"))
+                                       st.append(Token("TEXCOORD{}_{}_{}".format(size, u.unit, uv_type)))
                if mesh.vertex_groups:
-                       st.append(Token("GROUP{}".format(mesh.max_groups_per_vertex)))
-                       st.append(Token("WEIGHT{}".format(mesh.max_groups_per_vertex)))
-               st.append(Token("VERTEX3"))
+                       st.append(Token("GROUP{}_UBYTE".format(mesh.max_groups_per_vertex)))
+                       st.append(Token("WEIGHT{}_USHORT".format(mesh.max_groups_per_vertex)))
+               st.append(Token("VERTEX3_FLOAT"))
 
                normal = None
                color = None