X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fmesh.py;h=8f19676ac1127627e2a78771e949d89a9ce5b9c4;hb=c3ebbcb56c1ca9bb3022a7f49aab1da5e09150ba;hp=ac3f7c675605109266339bb4189571c7f54eaf2a;hpb=68488043ee491d117477a458f876e0d3f78e146e;p=libs%2Fgl.git diff --git a/blender/io_mspgl/mesh.py b/blender/io_mspgl/mesh.py index ac3f7c67..8f19676a 100644 --- a/blender/io_mspgl/mesh.py +++ b/blender/io_mspgl/mesh.py @@ -56,6 +56,7 @@ class Vertex: self.index = vertex.index self.co = mathutils.Vector(vertex.co) self.normal = mathutils.Vector(vertex.normal) + self.color = None self.flag = False self.edges = [] self.faces = [] @@ -69,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: @@ -83,7 +88,6 @@ class Face: self.normal = face.normal self.use_smooth = face.use_smooth self.material_index = face.material_index - self.uvs = [] self.flag = False def __cmp__(self, other): @@ -95,12 +99,8 @@ class Face: n = self.vertices.index(v) return [(n+i)%len(self.vertices) for i in range(len(self.vertices))] - def pivot_vertices(self, *vt): - flags = [(v in vt) for v in self.vertices] - l = len(self.vertices) - for i in range(l): - if flags[i] and not flags[(i+l-1)%l]: - return self.vertices[i:]+self.vertices[:i] + def get_loop_index(self, v): + return self.loop_indices[self.vertices.index(v)] def get_edge(self, v1, v2): key = make_edge_key(v1.index, v2.index) @@ -147,6 +147,12 @@ class UvLayer: self.hidden = True +class ColorLayer: + def __init__(self, l): + self.name = l.name + self.colors = [c.color[:] for c in l.data] + + class Mesh: def __init__(self, mesh): self.name = mesh.name @@ -160,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] @@ -170,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: @@ -192,6 +200,10 @@ class Mesh: if self.uv_layers[0].unit!=0: self.uv_layers = [] + self.colors = None + if mesh.vertex_colors: + self.colors = ColorLayer(mesh.vertex_colors[0]) + # Rewrite links between elements to point to cloned data, or create links # where they don't exist edge_map = {e.key: e for e in self.edges} @@ -234,12 +246,12 @@ class Mesh: # Merge materials and form a lookup from source material indices to the # merged material list - material_map = [] + material_atlas = [] for m in other.materials: if m in self.materials: - material_map.append(self.materials.index(m)) + material_atlas.append(self.materials.index(m)) else: - material_map.append(len(self.materials)) + material_atlas.append(len(self.materials)) self.materials.append(m) # Append data and adjust indices where necessary. Since the data is @@ -247,6 +259,15 @@ class Mesh: for i, u in enumerate(self.uv_layers): u.uvs += other.uv_layers[i].uvs + if self.colors: + if other.colors: + self.colors.colors += other.colors.colors + else: + self.colors.colors += [(1.0, 1.0, 1.0, 1.0)]*len(other.loops) + elif other.colors: + self.colors = ColorLayer(other.colors.name) + self.colors.colors = [(1.0, 1.0, 1.0, 1.0)]*len(self.loops)+other.colors.colors + offset = len(self.vertices) self.vertices += other.vertices for v in self.vertices[offset:]: @@ -261,7 +282,7 @@ class Mesh: f.index += offset f.loop_indices = range(f.loop_indices.start+offset, f.loop_indices.stop+offset) if other.materials: - f.material_index = material_map[f.material_index] + f.material_index = material_atlas[f.material_index] offset = len(self.edges) self.edges += other.edges @@ -356,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) @@ -363,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)