for g in v.groups:
g.group = group_index_map[g.group]
+ def apply_material_map(self, material_map):
+ for m in self.materials:
+ if m not in material_map.materials:
+ raise Exception("Material map is not compatible with Mesh")
+
+ if self.use_uv=='NONE':
+ return
+
+ layer = UvLayer("material_map")
+ 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_map.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
self._mesh = None
-def create_mesh_from_object(context, obj, progress):
+def create_mesh_from_object(context, obj, progress, *, material_map=None):
if obj.type!="MESH":
raise Exception("Object is not a mesh")
mesh.name = obj.data.name
+ if material_map:
+ mesh.apply_material_map(material_map)
+
progress.set_task("Triangulating", 0.2, 0.3)
mesh.prepare_triangles(progress)
progress.set_task("Smoothing", 0.3, 0.5)