I have many objects created by importing some .wrl
files and joining several meshes toghether. The result is a set of blender objects, each with a long list of materials from its submeshes. However, these - nearly a thousand - materials are only ten different colors or so...
I know that I can manually create ten "master materials" and assign each mesh to the proper color (following the manual: reusing-existing-materials), but it is really annoying...
Is there a way to automatically "skim" the materials to ends up with a small list of colors reused by all the submeshes of the objects?
I mean something like this:
list_of_unique_materials = []
for material in bpy.data.materials:
if material.users:
if not **material in list_of_unique_materials**:
list_of_unique_materials.append(material)
else:
**reuse the same material in the list**
where I'm not really sure about how to implement the code inside the asterisks...
Many thanks!
EDIT: Example
What I have now (len(bpy.data.materials) >> 805
):
- Object1
- Mesh.001: Material.001
- Mesh.002: Material.002
- Mesh.003: Material.003 (same as Material.001)
- Mesh.004: Material.004
- ...
- Object2
- Mesh.101: Material.101 (same as Material.001)
- Mesh.102: Material.102 (same as Material.002)
- Mesh.103: Material.103 (same as Material.002)
- Mesh.104: Material.104 (same as Material.004)
- ...
- ...
What I would like (len(bpy.data.materials) >> 12
):
- Object1
- Mesh.001: Material.001
- Mesh.002: Material.002
- Mesh.003: Material.001
- Mesh.004: Material.004
- ...
- Object2
- Mesh.101: Material.001
- Mesh.102: Material.002
- Mesh.103: Material.002
- Mesh.104: Material.004
- ...
- ...
This is due to the .wrl
importer which has named with a new identifier every single color of the meshes that I have imported (and the total number of distinct colors in the meshes is no more than 12).