]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_mesh.py
Fix and improve vertex group support
[libs/gl.git] / blender / io_mspgl / export_mesh.py
index 0d27a71cdf6c2b1e57121a2e064bec4d5067b9bb..68d93cbc525b9b3872e209c58a33bb7548ca0cba 100644 (file)
@@ -77,7 +77,8 @@ class MeshExporter:
                                st.append(Token("TANGENT3"))
                                st.append(Token("BINORMAL3"))
                if mesh.vertex_groups:
-                       st.append(Token("GENERIC{}_0".format(mesh.max_groups_per_vertex*2)))
+                       st.append(Token("GROUP{}".format(mesh.max_groups_per_vertex)))
+                       st.append(Token("WEIGHT{}".format(mesh.max_groups_per_vertex)))
                st.append(Token("VERTEX3"))
 
                normal = None
@@ -86,6 +87,7 @@ class MeshExporter:
                tan = None
                bino = None
                group = None
+               weight = None
                for v in mesh.vertices:
                        if v.normal!=normal:
                                st.sub.append(Statement("normal", *v.normal))
@@ -108,13 +110,14 @@ class MeshExporter:
                                        st.sub.append(Statement("binormal", *v.bino))
                                        bino = v.bino
                        if mesh.vertex_groups:
-                               group_attr = [(group_index_map[g.group], g.weight*v.group_weight_scale) for g in v.groups[:mesh.max_groups_per_vertex]]
-                               while len(group_attr)<mesh.max_groups_per_vertex:
-                                       group_attr.append((0, 0.0))
-                               group_attr = list(itertools.chain(*group_attr))
-                               if group_attr!=group:
-                                       st.sub.append(Statement("generic", 0, *group_attr))
-                                       group = group_attr
+                               v_group = [g.group for g in v.groups]
+                               v_weight = [g.weight for g in v.groups]
+                               if v_group!=group:
+                                       st.sub.append(Statement("group", *v_group))
+                                       group = v_group
+                               if v_weight!=weight:
+                                       st.sub.append(Statement("weight", *v_weight))
+                                       weight = v_weight
                        st.sub.append(Statement("vertex", *v.co))
 
                statements.append(st)