Include utility to merge materials by diffuse colour to clean up bad IFC files

This commit is contained in:
Dion Moult
2019-10-04 17:26:15 +10:00
parent 75f254d162
commit adeb3dea61
+34
View File
@@ -0,0 +1,34 @@
import bpy
import pprint
print('# Start')
cleaned_materials = {}
n = 0
for m in bpy.data.materials:
r = m.diffuse_color[0]
g = m.diffuse_color[1]
b = m.diffuse_color[2]
key = str(r) + '-' + str(g) + '-' + str(b)
cleaned_materials[key] = {'name': 'name{}'.format(n)}
n += 1
pprint.pprint(cleaned_materials)
print(len(bpy.data.materials.keys()))
print(len(cleaned_materials.keys()))
for rgb, data in cleaned_materials.items():
m = bpy.data.materials.new(data['name'])
print(rgb)
m.diffuse_color = (
float(rgb.split('-')[0]),
float(rgb.split('-')[1]),
float(rgb.split('-')[2]),
1)
data['material'] = m
for o in bpy.context.selected_objects:
m = o.material_slots[0].material
r = m.diffuse_color[0]
g = m.diffuse_color[1]
b = m.diffuse_color[2]
key = str(r) + '-' + str(g) + '-' + str(b)
o.material_slots[0].material = cleaned_materials[key]['material']