From a5daf4177a9fa8201be7dfc027c4113d38f36901 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 21 Mar 2024 14:42:42 +0500 Subject: [PATCH] add_mesh_representation - option to force faceted breps --- .../api/geometry/add_mesh_representation.py | 5 ++-- .../ifcpatch/recipes/TessellateElements.py | 28 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_mesh_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_mesh_representation.py index bb0ff285a1..ac2167a70e 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_mesh_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_mesh_representation.py @@ -20,7 +20,7 @@ import ifcopenshell.util.unit class Usecase: - def __init__(self, file, **settings): + def __init__(self, file: ifcopenshell.file, **settings): self.file = file self.settings = { "context": None, # IfcGeometricRepresentationContext @@ -33,6 +33,7 @@ class Usecase: "faces": None, # A list of polygons, represented by vertex indices "coordinate_offset": None, # Optionally apply a vector offset to all coordinates "unit_scale": None, # A scale factor to apply for all vectors in case the unit is different + "force_faceted_brep": False, # Force using IfcFacetedBreps instead of IfcPolygonalFaceSets } for key, value in settings.items(): self.settings[key] = value @@ -43,7 +44,7 @@ class Usecase: return self.create_mesh_representation() def create_mesh_representation(self): - if self.file.schema == "IFC2X3": + if self.settings["force_faceted_brep"] or self.file.schema == "IFC2X3": return self.create_faceted_brep() return self.create_polygonal_face_set() diff --git a/src/ifcpatch/ifcpatch/recipes/TessellateElements.py b/src/ifcpatch/ifcpatch/recipes/TessellateElements.py index db71e5ae06..88635144a3 100644 --- a/src/ifcpatch/ifcpatch/recipes/TessellateElements.py +++ b/src/ifcpatch/ifcpatch/recipes/TessellateElements.py @@ -17,14 +17,24 @@ # along with IfcPatch. If not, see . import ifcopenshell +import ifcopenshell.api import ifcopenshell.geom import ifcopenshell.util.selector +import ifcopenshell.util.shape import ifcopenshell.util.representation import multiprocessing +from logging import Logger class Patcher: - def __init__(self, src, file, logger, query="IfcBeam"): + def __init__( + self, + src: str, + file: ifcopenshell.file, + logger: Logger, + query: str = "IfcBeam", + force_faceted_brep: bool = False, + ): """Convert element body representations to tessellations or faceted breps Some software have bugs that result in incorrect geometry being @@ -35,16 +45,23 @@ class Patcher: See example bug: https://github.com/Autodesk/revit-ifc/issues/707 + :param query: Query string to filter out elements to convert, defaults to "IfcBeam" + :type query: str + :param force_faceted_brep: Force using IfcFacetedBreps instead of IfcPolygonalFaceSets, + defaults to `False` + :type force_faceted_brep: bool + Example: .. code:: python - ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "TessellateElements", "arguments": ["IfcBeam"]}) + ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "TessellateElements", "arguments": ["IfcBeam", False]}) """ self.src = src self.file = file self.logger = logger self.query = query + self.force_faceted_brep = force_faceted_brep def patch(self): context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW") @@ -68,7 +85,12 @@ class Patcher: 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 + "geometry.add_mesh_representation", + self.file, + context=context, + vertices=v, + faces=f, + force_faceted_brep=self.force_faceted_brep, ) representations = element.Representation.Representations representations = [r for r in representations if r.ContextOfItems != context]