mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
bim.load_linked_project - move processing chunk code to common method
This commit is contained in:
@@ -1545,18 +1545,8 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
ci = 0
|
ci = 0
|
||||||
if iterator.initialize():
|
|
||||||
while True:
|
|
||||||
shape = iterator.get()
|
|
||||||
results.add(self.file.by_id(shape.id))
|
|
||||||
geometry = shape.geometry
|
|
||||||
|
|
||||||
# Elements with a lot of geometry benefit from instancing to save memory
|
def process_chunk() -> None:
|
||||||
if ifcopenshell.util.shape.get_faces(geometry).shape[0] > 333: # 333 tris
|
|
||||||
self.process_occurrence(shape)
|
|
||||||
if not iterator.next():
|
|
||||||
if not chunked_verts:
|
|
||||||
break
|
|
||||||
mats = np.concatenate(chunked_materials)
|
mats = np.concatenate(chunked_materials)
|
||||||
midx = np.concatenate(chunked_material_ids)
|
midx = np.concatenate(chunked_material_ids)
|
||||||
mats, mapping = np.unique(mats, axis=0, return_inverse=True)
|
mats, mapping = np.unique(mats, axis=0, return_inverse=True)
|
||||||
@@ -1572,7 +1562,7 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
blender_mats[mat] = blender_mat
|
blender_mats[mat] = blender_mat
|
||||||
mat_results.append(blender_mat)
|
mat_results.append(blender_mat)
|
||||||
|
|
||||||
# The left over chunk
|
# Create object for current chunk.
|
||||||
self.create_object(
|
self.create_object(
|
||||||
np.concatenate(chunked_verts),
|
np.concatenate(chunked_verts),
|
||||||
np.concatenate(chunked_faces),
|
np.concatenate(chunked_faces),
|
||||||
@@ -1581,7 +1571,21 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
chunked_guids,
|
chunked_guids,
|
||||||
chunked_guid_ids,
|
chunked_guid_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if iterator.initialize():
|
||||||
|
while True: # Main loop.
|
||||||
|
shape = iterator.get()
|
||||||
|
results.add(self.file.by_id(shape.id))
|
||||||
|
geometry = shape.geometry
|
||||||
|
|
||||||
|
# Elements with a lot of geometry benefit from instancing to save memory
|
||||||
|
if ifcopenshell.util.shape.get_faces(geometry).shape[0] > 333: # 333 tris
|
||||||
|
self.process_occurrence(shape)
|
||||||
|
if not iterator.next():
|
||||||
|
if not chunked_verts:
|
||||||
break
|
break
|
||||||
|
process_chunk()
|
||||||
|
break # Break from main loop.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ci += 1
|
ci += 1
|
||||||
@@ -1626,30 +1630,7 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
|
|
||||||
if offset > chunk_size:
|
if offset > chunk_size:
|
||||||
has_processed_chunk = True
|
has_processed_chunk = True
|
||||||
|
process_chunk()
|
||||||
mats = np.concatenate(chunked_materials)
|
|
||||||
midx = np.concatenate(chunked_material_ids)
|
|
||||||
mats, mapping = np.unique(mats, axis=0, return_inverse=True)
|
|
||||||
midx = mapping[midx]
|
|
||||||
|
|
||||||
mat_results = []
|
|
||||||
for mat in mats:
|
|
||||||
mat = tuple(mat)
|
|
||||||
blender_mat = blender_mats.get(mat, None)
|
|
||||||
if not blender_mat:
|
|
||||||
blender_mat = bpy.data.materials.new("Chunk")
|
|
||||||
blender_mat.diffuse_color = mat
|
|
||||||
blender_mats[mat] = blender_mat
|
|
||||||
mat_results.append(blender_mat)
|
|
||||||
|
|
||||||
self.create_object(
|
|
||||||
np.concatenate(chunked_verts),
|
|
||||||
np.concatenate(chunked_faces),
|
|
||||||
mat_results,
|
|
||||||
midx,
|
|
||||||
chunked_guids,
|
|
||||||
chunked_guid_ids,
|
|
||||||
)
|
|
||||||
chunked_guids = []
|
chunked_guids = []
|
||||||
chunked_guid_ids = []
|
chunked_guid_ids = []
|
||||||
chunked_verts = []
|
chunked_verts = []
|
||||||
@@ -1661,31 +1642,8 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
|
|
||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
if not has_processed_chunk:
|
if not has_processed_chunk:
|
||||||
mats = np.concatenate(chunked_materials)
|
process_chunk()
|
||||||
midx = np.concatenate(chunked_material_ids)
|
break # Break main loop.
|
||||||
mats, mapping = np.unique(mats, axis=0, return_inverse=True)
|
|
||||||
midx = mapping[midx]
|
|
||||||
|
|
||||||
mat_results = []
|
|
||||||
for mat in mats:
|
|
||||||
mat = tuple(mat)
|
|
||||||
blender_mat = blender_mats.get(mat, None)
|
|
||||||
if not blender_mat:
|
|
||||||
blender_mat = bpy.data.materials.new("Chunk")
|
|
||||||
blender_mat.diffuse_color = mat
|
|
||||||
blender_mats[mat] = blender_mat
|
|
||||||
mat_results.append(blender_mat)
|
|
||||||
|
|
||||||
# The left over chunk
|
|
||||||
self.create_object(
|
|
||||||
np.concatenate(chunked_verts),
|
|
||||||
np.concatenate(chunked_faces),
|
|
||||||
mat_results,
|
|
||||||
midx,
|
|
||||||
chunked_guids,
|
|
||||||
chunked_guid_ids,
|
|
||||||
)
|
|
||||||
break
|
|
||||||
self.elements -= results
|
self.elements -= results
|
||||||
|
|
||||||
bpy.context.scene.collection.children.link(self.collection)
|
bpy.context.scene.collection.children.link(self.collection)
|
||||||
|
|||||||
Reference in New Issue
Block a user