]> git.tdb.fi Git - libs/gl.git/commitdiff
Adjust attribute order in mesh exporter and add padding if necessary
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 13:45:25 +0000 (15:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 13:48:20 +0000 (15:48 +0200)
blender/io_mspgl/export_mesh.py

index 7bb4e224c58a099ef13a571fc8db5f597f57a764..f54a05fd2a6c0b3f39844f16d294a0a57e6d0981 100644 (file)
@@ -18,28 +18,42 @@ class MeshExporter:
                resource = Resource(mesh.name+".mesh", "mesh")
                statements = resource.statements
 
-               st = Statement("vertices", Token("NORMAL3_BYTE"))
-               if mesh.uv_layers and mesh.tangent_vecs:
-                       st.append(Token("TANGENT3_BYTE"))
+               st = Statement("vertices", Token("VERTEX3_FLOAT"))
+               stride = 12
                if mesh.vertices[0].color:
                        st.append(Token("COLOR4_UBYTE"))
+                       stride += 4
                if mesh.uv_layers:
                        for u in mesh.uv_layers:
-                               size = str(len(u.uvs[0]))
+                               size = 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 uv_type=="FLOAT" and stride%4:
+                                       pad = 4-stride%4
+                                       st.append(Token("PADDING{}".format(pad)))
+                                       stride += pad
                                if u.unit==0:
                                        st.append(Token("TEXCOORD{}_{}".format(size, uv_type)))
                                else:
                                        st.append(Token("TEXCOORD{}_{}_{}".format(size, u.unit, uv_type)))
+                               stride += (2 if uv_type=="USHORT" else 4)*size
                if mesh.vertex_groups:
-                       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"))
+                       st.append(Token("GROUP{}_UBYTE".format(mesh.max_groups_per_vertex)))
+                       stride += 3*mesh.max_groups_per_vertex
+               st.append(Token("NORMAL3_BYTE"))
+               stride += 3
+               if mesh.uv_layers and mesh.tangent_vecs:
+                       st.append(Token("TANGENT3_BYTE"))
+                       stride += 3
+               if stride%4:
+                       pad = 4-stride%4
+                       st.append(Token("PADDING{}_UBYTE".format(pad)))
+                       stride += pad
 
                normal = None
                color = None