mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 14:48:02 +00:00
Introduce defaultdict instead of checks
This commit is contained in:
@@ -43,6 +43,7 @@ if "bpy" in locals():
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
import mathutils
|
||||||
|
from collections import defaultdict
|
||||||
from bpy.props import StringProperty, IntProperty, BoolProperty
|
from bpy.props import StringProperty, IntProperty, BoolProperty
|
||||||
from bpy_extras.io_utils import ImportHelper
|
from bpy_extras.io_utils import ImportHelper
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
if not valid_file:
|
if not valid_file:
|
||||||
return False
|
return False
|
||||||
print("Done reading file")
|
print("Done reading file")
|
||||||
id_to_object = {}
|
id_to_object = defaultdict(list)
|
||||||
id_to_parent = {}
|
id_to_parent = {}
|
||||||
id_to_matrix = {}
|
id_to_matrix = {}
|
||||||
openings = []
|
openings = []
|
||||||
@@ -82,6 +83,7 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
print("Creating geometry...")
|
print("Creating geometry...")
|
||||||
collection = bpy.data.collections.new(f"{bpy.path.basename(filename)}")
|
collection = bpy.data.collections.new(f"{bpy.path.basename(filename)}")
|
||||||
bpy.context.scene.collection.children.link(collection)
|
bpy.context.scene.collection.children.link(collection)
|
||||||
|
|
||||||
if process_relations:
|
if process_relations:
|
||||||
rel_collection = bpy.data.collections.new("Relations")
|
rel_collection = bpy.data.collections.new("Relations")
|
||||||
collection.children.link(rel_collection)
|
collection.children.link(rel_collection)
|
||||||
@@ -178,8 +180,6 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
bob.hide_viewport = bob.hide_render = True
|
bob.hide_viewport = bob.hide_render = True
|
||||||
bob.display_type = 'WIRE'
|
bob.display_type = 'WIRE'
|
||||||
|
|
||||||
if ob.id not in id_to_object:
|
|
||||||
id_to_object[ob.id] = []
|
|
||||||
id_to_object[ob.id].append(bob)
|
id_to_object[ob.id].append(bob)
|
||||||
|
|
||||||
if ob.parent_id > 0:
|
if ob.parent_id > 0:
|
||||||
@@ -201,45 +201,43 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
|
|
||||||
if process_relations:
|
if process_relations:
|
||||||
print("Processing relations...")
|
print("Processing relations...")
|
||||||
|
while len(id_to_parent_temp):
|
||||||
|
id, parent_id = id_to_parent_temp.popitem()
|
||||||
|
|
||||||
while len(id_to_parent_temp) and process_relations:
|
if parent_id in id_to_object:
|
||||||
id, parent_id = id_to_parent_temp.popitem()
|
bob = id_to_object[parent_id][0]
|
||||||
|
|
||||||
if parent_id in id_to_object:
|
|
||||||
bob = id_to_object[parent_id][0]
|
|
||||||
else:
|
|
||||||
parent_ob = iterator.getObject(parent_id)
|
|
||||||
if parent_ob.id == -1:
|
|
||||||
bob = None
|
|
||||||
else:
|
else:
|
||||||
m = parent_ob.transformation.matrix.data
|
parent_ob = iterator.getObject(parent_id)
|
||||||
nm = parent_ob.name if len(parent_ob.name) and use_names \
|
if parent_ob.id == -1:
|
||||||
else parent_ob.guid
|
bob = None
|
||||||
bob = bpy.data.objects.new(nm, None)
|
else:
|
||||||
|
m = parent_ob.transformation.matrix.data
|
||||||
|
nm = parent_ob.name if len(parent_ob.name) and use_names \
|
||||||
|
else parent_ob.guid
|
||||||
|
bob = bpy.data.objects.new(nm, None)
|
||||||
|
|
||||||
mat = mathutils.Matrix((
|
mat = mathutils.Matrix((
|
||||||
[m[0], m[1], m[2], 0],
|
[m[0], m[1], m[2], 0],
|
||||||
[m[3], m[4], m[5], 0],
|
[m[3], m[4], m[5], 0],
|
||||||
[m[6], m[7], m[8], 0],
|
[m[6], m[7], m[8], 0],
|
||||||
[m[9], m[10], m[11], 1]))
|
[m[9], m[10], m[11], 1]))
|
||||||
if transpose_matrices:
|
if transpose_matrices:
|
||||||
mat.transpose()
|
mat.transpose()
|
||||||
id_to_matrix[parent_ob.id] = mat
|
id_to_matrix[parent_ob.id] = mat
|
||||||
|
|
||||||
rel_collection.objects.link(bob)
|
rel_collection.objects.link(bob)
|
||||||
|
|
||||||
bob.ifc_id = parent_ob.id
|
bob.ifc_id = parent_ob.id
|
||||||
bob.ifc_name, bob.ifc_type, bob.ifc_guid = \
|
bob.ifc_name, bob.ifc_type, bob.ifc_guid = \
|
||||||
parent_ob.name, parent_ob.type, parent_ob.guid
|
parent_ob.name, parent_ob.type, parent_ob.guid
|
||||||
|
|
||||||
if parent_ob.parent_id > 0:
|
if parent_ob.parent_id > 0:
|
||||||
id_to_parent[parent_id] = parent_ob.parent_id
|
id_to_parent[parent_id] = parent_ob.parent_id
|
||||||
id_to_parent_temp[parent_id] = parent_ob.parent_id
|
id_to_parent_temp[parent_id] = parent_ob.parent_id
|
||||||
if parent_id not in id_to_object: id_to_object[parent_id] = []
|
id_to_object[parent_id].append(bob)
|
||||||
id_to_object[parent_id].append(bob)
|
if bob:
|
||||||
if bob:
|
for ob in id_to_object[id]:
|
||||||
for ob in id_to_object[id]:
|
ob.parent = bob
|
||||||
ob.parent = bob
|
|
||||||
|
|
||||||
id_to_matrix_temp = dict(id_to_matrix)
|
id_to_matrix_temp = dict(id_to_matrix)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user