mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 14:07:43 +00:00
Fix bug where imported materials that duplicated a name could be incorrectly assigned
This commit is contained in:
@@ -5,6 +5,7 @@ import ifcopenshell.util.selector
|
|||||||
import bpy
|
import bpy
|
||||||
import bmesh
|
import bmesh
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import threading
|
import threading
|
||||||
import json
|
import json
|
||||||
@@ -105,7 +106,7 @@ class MaterialCreator():
|
|||||||
return
|
return
|
||||||
if len(obj.material_slots) == 1:
|
if len(obj.material_slots) == 1:
|
||||||
return
|
return
|
||||||
slots = [s.name for s in obj.material_slots]
|
slots = [self.canonicalise_material_name(s.name) for s in obj.material_slots]
|
||||||
material_to_slot = {}
|
material_to_slot = {}
|
||||||
for i, material in enumerate(mesh['ios_materials']):
|
for i, material in enumerate(mesh['ios_materials']):
|
||||||
if material == 'NULLMAT':
|
if material == 'NULLMAT':
|
||||||
@@ -119,6 +120,9 @@ class MaterialCreator():
|
|||||||
else 0) for mat_id in mesh['ios_material_ids']]
|
else 0) for mat_id in mesh['ios_material_ids']]
|
||||||
mesh.polygons.foreach_set('material_index', material_index)
|
mesh.polygons.foreach_set('material_index', material_index)
|
||||||
|
|
||||||
|
def canonicalise_material_name(self, name):
|
||||||
|
return re.sub(r'\.[0-9]{3}', '', name)
|
||||||
|
|
||||||
def parse_material(self, element):
|
def parse_material(self, element):
|
||||||
for association in element.HasAssociations:
|
for association in element.HasAssociations:
|
||||||
if association.is_a('IfcRelAssociatesMaterial'):
|
if association.is_a('IfcRelAssociatesMaterial'):
|
||||||
|
|||||||
Reference in New Issue
Block a user