mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 06:32:09 +00:00
bim.load_linked_project - move processing chunk code to common method
This commit is contained in:
@@ -1545,8 +1545,35 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
ci = 0
|
ci = 0
|
||||||
|
|
||||||
|
def process_chunk() -> None:
|
||||||
|
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: list[bpy.types.Material] = []
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Create object for current chunk.
|
||||||
|
self.create_object(
|
||||||
|
np.concatenate(chunked_verts),
|
||||||
|
np.concatenate(chunked_faces),
|
||||||
|
mat_results,
|
||||||
|
midx,
|
||||||
|
chunked_guids,
|
||||||
|
chunked_guid_ids,
|
||||||
|
)
|
||||||
|
|
||||||
if iterator.initialize():
|
if iterator.initialize():
|
||||||
while True:
|
while True: # Main loop.
|
||||||
shape = iterator.get()
|
shape = iterator.get()
|
||||||
results.add(self.file.by_id(shape.id))
|
results.add(self.file.by_id(shape.id))
|
||||||
geometry = shape.geometry
|
geometry = shape.geometry
|
||||||
@@ -1557,31 +1584,8 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
if not chunked_verts:
|
if not chunked_verts:
|
||||||
break
|
break
|
||||||
mats = np.concatenate(chunked_materials)
|
process_chunk()
|
||||||
midx = np.concatenate(chunked_material_ids)
|
break # Break from main loop.
|
||||||
mats, mapping = np.unique(mats, axis=0, return_inverse=True)
|
|
||||||
midx = mapping[midx]
|
|
||||||
|
|
||||||
mat_results: list[bpy.types.Material] = []
|
|
||||||
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
|
|
||||||
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