mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
Include utility to merge materials by diffuse colour to clean up bad IFC files
This commit is contained in:
@@ -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']
|
||||||
Reference in New Issue
Block a user