+ for e in self.edges:
+ e.check_smooth(smooth_limit)
+
+ progress.push_task("Sharp edges", 0.0, 0.7)
+ self.split_vertices(self.find_smooth_group, progress)
+
+ if self.smoothing!='BLENDER':
+ progress.set_task("Updating normals", 0.7, 1.0)
+ self.compute_normals(progress)
+
+ progress.pop_task()
+
+ def prepare_vertex_groups(self, obj):
+ for v in self.vertices:
+ if v.groups:
+ weight_sum = sum(g.weight for g in v.groups)
+ v.groups = sorted(v.groups, key=(lambda g: g.weight), reverse=True)[:self.max_groups_per_vertex]
+ weight_scale = weight_sum/sum(g.weight for g in v.groups)
+ for g in v.groups:
+ g.weight *= weight_scale
+
+ if obj.parent and obj.parent.type=="ARMATURE":
+ armature = obj.parent.data
+ bone_indices = {b.name: i for i, b in enumerate(armature.bones)}
+ group_index_map = {i: i for i in range(len(obj.vertex_groups))}
+ for g in first_obj.vertex_groups:
+ if g.name in bone_indices:
+ group_index_map[g.index] = bone_indices[g.name]
+
+ for v in self.vertices:
+ for g in v.groups:
+ g.group = group_index_map[g.group]
+
+ def prepare_uv(self, obj, progress):
+ if obj.material_tex and self.use_uv!='NONE':
+ layer = UvLayer("material_tex")
+
+ if self.use_uv=='UNIT0':
+ self.uv_layers = [layer]
+ layer.unit = 0
+ else:
+ self.uv_layers.append(layer)
+ layer.unit = max((u.unit+1 for u in self.uv_layers if u.unit is not None), default=0)
+
+ layer.uvs = [None]*len(self.loops)
+ for f in self.faces:
+ uv = mathutils.Vector(((f.material_index+0.5)/len(self.materials), 0.5))
+ for i in f.loop_indices:
+ layer.uvs[i] = uv
+
+ # Form a list of UV layers referenced by materials with the array atlas
+ # property set
+ array_uv_layers = [t.uv_layer for m in self.materials if m.array_atlas for t in m.texture_slots if t and t.texture_coords=='UV']
+ array_uv_layers = [u for u in self.uv_layers if u.name in array_uv_layers]
+
+ if array_uv_layers:
+ for f in self.faces:
+ layer = 0
+ if f.material_index<len(self.materials):
+ mat = self.materials[f.material_index]
+ if mat and mat.array_atlas:
+ layer = mat.array_layer
+
+ for l in array_uv_layers:
+ for i in f.loop_indices:
+ l.uvs[i] = mathutils.Vector((*l.uvs[i], layer))
+
+ # Copy UVs from layers to faces