mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
add_mesh_representation - option to force faceted breps
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user