]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/mesh.py
Fix and improve vertex group support
[libs/gl.git] / blender / io_mspgl / mesh.py
index da5e76aaf34ed259d48ff5f3a0b872c32f36cdda..d9ae6b760ff545c8043269bb9e120b597f8b05f7 100644 (file)
@@ -70,8 +70,12 @@ class Vertex:
 
 class VertexGroup:
        def __init__(self, group):
-               self.group = group.group
-               self.weight = group.weight
+               if group:
+                       self.group = group.group
+                       self.weight = group.weight
+               else:
+                       self.group = 0
+                       self.weight = 0.0
 
 
 class Face:
@@ -162,8 +166,9 @@ class Mesh:
 
                # Clone basic data
                self.vertices = [Vertex(v) for v in mesh.vertices]
-               for v in self.vertices:
-                       v.groups = [VertexGroup(g) for g in v.groups]
+               if self.vertex_groups:
+                       for v in self.vertices:
+                               v.groups = [VertexGroup(g) for g in v.groups]
 
                self.faces = [Face(f) for f in mesh.polygons]
                self.edges = [Edge(e) for e in mesh.edges]
@@ -172,6 +177,7 @@ class Mesh:
 
                self.use_auto_smooth = mesh.use_auto_smooth
                self.auto_smooth_angle = mesh.auto_smooth_angle
+               self.max_groups_per_vertex = mesh.max_groups_per_vertex
 
                # Clone only the desired UV layers
                if mesh.use_uv=='NONE' or not mesh.uv_layers:
@@ -371,6 +377,9 @@ class Mesh:
                progress.pop_task()
 
        def prepare_vertex_groups(self, obj):
+               if not self.vertex_groups:
+                       return
+
                for v in self.vertices:
                        if v.groups:
                                weight_sum = sum(g.weight for g in v.groups)
@@ -378,6 +387,8 @@ class Mesh:
                                weight_scale = weight_sum/sum(g.weight for g in v.groups)
                                for g in v.groups:
                                        g.weight *= weight_scale
+                       while len(v.groups)<self.max_groups_per_vertex:
+                               v.groups.append(VertexGroup(None))
 
                if obj.parent and obj.parent.type=="ARMATURE":
                        armature = obj.parent.data