- def assign_texture_units(self):
- # Assign texture units for any non-hidden UV layers that lack one
- units = [u.unit for u in self.uv_layers if u.unit is not None]
- if units:
- free_unit = max(units)+1
- else:
- free_unit = 0
- for u in self.uv_layers:
- if u.unit is None:
- if not u.hidden:
- u.unit = free_unit
- free_unit += 1
-
- def generate_material_uv(self):
- self.uv_layers.append(FakeUvLayer("material_tex"))
- self.assign_texture_units()
+ progress.set_progress(i/face_count)
+
+ def prepare_smoothing(self, progress):
+ smooth_limit = -1
+ if self.smoothing=='NONE':
+ for f in self.faces:
+ f.use_smooth = False
+
+ smooth_limit = 1
+ elif self.use_auto_smooth:
+ smooth_limit = math.cos(self.auto_smooth_angle)
+
+ 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, progress):
+ # 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