mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 06:00:51 +00:00
Fix bug in TessellateElements patch recipe where sometimes the patch would run forever.
This commit is contained in:
@@ -50,20 +50,27 @@ class Patcher:
|
|||||||
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
|
context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
|
||||||
elements = ifcopenshell.util.selector.filter_elements(self.file, self.query)
|
elements = ifcopenshell.util.selector.filter_elements(self.file, self.query)
|
||||||
settings = ifcopenshell.geom.settings()
|
settings = ifcopenshell.geom.settings()
|
||||||
|
settings.set(settings.STRICT_TOLERANCE, True)
|
||||||
settings.set_context_ids([context.id()])
|
settings.set_context_ids([context.id()])
|
||||||
iterator = ifcopenshell.geom.iterator(settings, self.file, multiprocessing.cpu_count(), include=elements)
|
iterator = ifcopenshell.geom.iterator(settings, self.file, multiprocessing.cpu_count(), include=elements)
|
||||||
|
replacements = {}
|
||||||
if iterator.initialize():
|
if iterator.initialize():
|
||||||
while True:
|
while True:
|
||||||
shape = iterator.get()
|
shape = iterator.get()
|
||||||
element = self.file.by_guid(shape.guid)
|
element = self.file.by_guid(shape.guid)
|
||||||
v = [[x.tolist() for x in ifcopenshell.util.shape.get_vertices(shape.geometry)]]
|
v = [[x.tolist() for x in ifcopenshell.util.shape.get_vertices(shape.geometry)]]
|
||||||
f = [ifcopenshell.util.shape.get_faces(shape.geometry)]
|
f = [ifcopenshell.util.shape.get_faces(shape.geometry)]
|
||||||
mesh = ifcopenshell.api.run(
|
replacements[element] = (v, f)
|
||||||
"geometry.add_mesh_representation", self.file, context=context, vertices=v, faces=f
|
|
||||||
)
|
|
||||||
representations = element.Representation.Representations
|
|
||||||
representations = [r for r in representations if r.ContextOfItems != context]
|
|
||||||
representations.append(mesh)
|
|
||||||
element.Representation.Representations = representations
|
|
||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Do the replacements outside the iterator to prevent messing up iterator state.
|
||||||
|
for element, geometry in replacements.items():
|
||||||
|
v, f = geometry
|
||||||
|
mesh = ifcopenshell.api.run(
|
||||||
|
"geometry.add_mesh_representation", self.file, context=context, vertices=v, faces=f
|
||||||
|
)
|
||||||
|
representations = element.Representation.Representations
|
||||||
|
representations = [r for r in representations if r.ContextOfItems != context]
|
||||||
|
representations.append(mesh)
|
||||||
|
element.Representation.Representations = representations
|
||||||
|
|||||||
Reference in New Issue
Block a user