+ uv = material_atlas.get_material_uv(self.materials[f.material_index])
+ for i in f.loop_indices:
+ layer.uvs[i] = uv
+
+ 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))
+
+ prog_count = len(self.uv_layers)
+ prog_step = 0
+
+ # Split by the UV layer used for tangent vectors first so connectivity
+ # remains intact for tangent vector computation
+ tangent_layer_index = -1
+ if self.tangent_vecs:
+ if self.tangent_uvtex:
+ uv_names = [u.name for u in self.uv_layers]
+ if self.tangent_uvtex in uv_names:
+ tangent_layer_index = uv_names.index(self.tangent_uvtex)
+ elif self.uv_layers[0].unit==0:
+ tangent_layer_index = 0
+
+ if tangent_layer_index>=0:
+ prog_count += 1
+ progress.push_task_slice("Computing tangents", 0, prog_count)
+ self.split_vertices(self.find_uv_group, progress, tangent_layer_index)
+ progress.set_task_slice(self.tangent_uvtex, 1, prog_count)
+ self.compute_tangents(tangent_layer_index, progress)
+ progress.pop_task()
+ prog_step = 2
+ else:
+ raise Exception("Tangent UV layer not found")
+
+ # Split by the remaining UV layers
+ for i, u in enumerate(self.uv_layers):
+ if i==tangent_layer_index:
+ continue
+
+ progress.push_task_slice(u.name, prog_step, prog_count)
+ self.split_vertices(self.find_uv_group, progress, i)
+ progress.pop_task()
+ prog_step += 1
+
+ # Copy UVs from layers to vertices
+ for v in self.vertices:
+ if v.faces:
+ # All faces still connected to the vertex have the same UV value
+ f = v.faces[0]
+ i = f.get_loop_index(v)
+ v.uvs = [u.uvs[i] for u in self.uv_layers]
+ else:
+ v.uvs = [(0.0, 0.0)]*len(self.uv_layers)
+
+ def prepare_colors(self, progress):
+ if not self.colors:
+ return
+
+ self.split_vertices(self.find_color_group, progress)
+
+ for v in self.vertices:
+ if v.faces:
+ f = v.faces[0]
+ v.color = self.colors.colors[f.get_loop_index(v)]
+ else:
+ v.color = (1.0, 1.0, 1.0, 1.0)