- def apply_material_atlas(self, material_atlas):
- for m in self.materials:
- if m.name not in material_atlas.material_names:
- raise Exception("Material atlas {} is not compatible with Mesh {}".format(material_atlas.name, self.name))
-
- if self.use_uv=='NONE':
- return
-
- layer = UvLayer("material_atlas")
- if self.use_uv=='UNIT0':
- self.uv_layers = [layer]
- layer.unit = 0
- else:
- self.uv_layers.append(layer)
- used_units = [u.unit for u in self.uv_layers]
- layer.unit = next(i for i in itertools.count() if i not in used_units)
- self.uv_layers.sort(key=lambda u: u.unit)
-
- layer.uvs = [(0.0, 0.0)]*len(self.loops)
- for f in self.faces:
- uv = material_atlas.get_material_uv(self.materials[f.material_index])
- for i in f.loop_indices:
- layer.uvs[i] = uv
-