Skip to content

Commit 259cfa8

Browse files
committed
Support for styled items in the Blender addon and make use of material indices
1 parent 3f048ef commit 259cfa8

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/ifcblender/io_import_scene_ifc/__init__.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def import_ifc(filename, use_names, process_relations):
8080

8181
f = ob.mesh.faces
8282
v = ob.mesh.verts
83-
m = ob.matrix
83+
mats = ob.mesh.materials
84+
matids = ob.mesh.material_ids
85+
m = ob.matrix
8486
t = ob.type[0:21]
8587
nm = ob.name if len(ob.name) and use_names else ob.guid
8688

@@ -91,12 +93,29 @@ def import_ifc(filename, use_names, process_relations):
9193

9294
me = bpy.data.meshes.new('mesh%d' % ob.mesh.id)
9395
me.from_pydata(verts, [], faces)
94-
if t in bpy.data.materials:
95-
mat = bpy.data.materials[t]
96-
mat.use_fake_user = True
97-
else:
98-
mat = bpy.data.materials.new(t)
99-
me.materials.append(mat)
96+
97+
def add_material(mname, props):
98+
if mname in bpy.data.materials:
99+
mat = bpy.data.materials[mname]
100+
mat.use_fake_user = True
101+
else:
102+
mat = bpy.data.materials.new(mname)
103+
for k,v in props.items():
104+
setattr(mat, k, v)
105+
me.materials.append(mat)
106+
107+
needs_default = -1 in matids
108+
if needs_default: add_material(t, {})
109+
110+
for mat in mats:
111+
props = {}
112+
if mat.has_diffuse: props['diffuse_color'] = mat.diffuse
113+
if mat.has_specular: props['specular_color'] = mat.specular
114+
if mat.has_transparency and mat.transparency > 0:
115+
props['alpha'] = 1.0 - mat.transparency
116+
props['use_transparency'] = True
117+
if mat.has_specularity: props['specular_hardness'] = mat.specularity
118+
add_material(mat.name, props)
100119

101120
bob = bpy.data.objects.new(nm, me)
102121
mat = mathutils.Matrix(([m[0], m[1], m[2], 0],
@@ -128,6 +147,11 @@ def import_ifc(filename, use_names, process_relations):
128147
if ob.parent_id > 0:
129148
id_to_parent[ob.id] = ob.parent_id
130149

150+
me.calc_tessface()
151+
152+
for face, matid in zip(me.tessfaces, matids):
153+
face.material_index = matid + (1 if needs_default else 0)
154+
131155
progress = IfcImport.Progress() // 2
132156
if progress > old_progress:
133157
print("\r[" + "#" * progress + " " * (50 - progress) + "]", end="")

src/ifcwrap/IfcPython.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
specular = property(specular)
116116
transparency = property(transparency)
117117
specularity = property(specularity)
118+
name = property(name)
118119
def __repr__(self): return "Material"
119120
%}
120121
};

0 commit comments

Comments
 (0)