+ 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, task):
+ # 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))
+
+ # 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:
+ raise Exception("Invalid configuration on mesh {}: No tangent UV layer".format(self.name))
+
+ prog_count = len(self.uv_layers)
+ if tangent_layer_index>=0:
+ prog_count += 1
+ task.set_slices(prog_count)
+
+ if tangent_layer_index>=0:
+ subtask = task.next_slice("Computing tangents")
+ self.split_vertices(self.find_uv_group, subtask, tangent_layer_index)
+ subtask = task.next_slice(self.tangent_uvtex)
+ self.compute_tangents(tangent_layer_index, subtask)
+
+ # Split by the remaining UV layers
+ for i, u in enumerate(self.uv_layers):
+ if i==tangent_layer_index:
+ continue
+
+ subtask = task.next_slice(u.name)
+ self.split_vertices(self.find_uv_group, subtask, i)
+
+ # 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, task):
+ if not self.colors:
+ return
+
+ self.split_vertices(self.find_color_group, task)