add_mesh_representation - option to force faceted breps

This commit is contained in:
Andrej730
2024-03-21 14:42:42 +05:00
parent 1b1eccb0c1
commit a5daf4177a
2 changed files with 28 additions and 5 deletions
@@ -17,14 +17,24 @@
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
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]