Skip to content

Commit

Permalink
auto convert brep to mesh for IFC2x3
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Jul 17, 2024
1 parent d0dbf26 commit 1f335c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Added `export` method to `IFCFile` and `Model` to export selected list of entities.
* Added `update_linear_deflection` to `Model`.

### Changed

* Automatically convert `Brep` to `Mesh` when assigned in `IFC2X3`.

### Removed


Expand Down
1 change: 1 addition & 0 deletions src/compas_ifc/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, model, filepath=None, schema="IFC4", use_occ=False, load_geom
else:
self._file = ifcopenshell.open(filepath)
print("IFC file loaded: {}".format(filepath))
self.model.update_linear_deflection()

self._schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(self._file.schema)

Expand Down
12 changes: 12 additions & 0 deletions src/compas_ifc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from compas.data import Data
from compas.geometry import Transformation
from compas.tolerance import TOL

from compas_ifc.file import IFCFile

Expand Down Expand Up @@ -149,6 +150,15 @@ def update_treeform(form, node):
def create(self, cls="IfcBuildingElementProxy", parent=None, geometry=None, frame=None, properties=None, **kwargs):
return self.file.create(cls=cls, parent=parent, geometry=geometry, frame=frame, properties=properties, **kwargs)

def update_linear_deflection(self):
length_unit = self.project.length_unit
if length_unit["name"] == "METRE" and length_unit["prefix"] == "MILLI":
TOL.lineardeflection = 1
elif length_unit["name"] == "METRE" and length_unit["prefix"] == "CENTI":
TOL.lineardeflection = 1e-1
elif length_unit["name"] == "METRE" and not length_unit["prefix"]:
TOL.lineardeflection = 1e-3

@classmethod
def template(cls, schema="IFC4", building_count=1, storey_count=1):
model = cls(schema=schema)
Expand All @@ -158,6 +168,8 @@ def template(cls, schema="IFC4", building_count=1, storey_count=1):
building = model.create("IfcBuilding", parent=site, Name=f"Default Building {i+1}")
for j in range(storey_count):
model.create("IfcBuildingStorey", parent=building, Name=f"Default Storey {j+1}")

model.update_linear_deflection()
return model


Expand Down
7 changes: 6 additions & 1 deletion src/compas_ifc/resources/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from compas.geometry import Cone
from compas.geometry import Cylinder
from compas.geometry import Sphere
from compas.tolerance import TOL
from ifcopenshell.api import run

from .brep import brep_to_ifc_advanced_brep
Expand Down Expand Up @@ -35,7 +36,11 @@ def _body_to_shape(body):
else:
shape = mesh_to_IfcShellBasedSurfaceModel(file, body)
elif OCCBrep and isinstance(body, OCCBrep):
shape = brep_to_ifc_advanced_brep(file, body)
if file.schema == "IFC2X3":
print("IFC2X3 does not support advanced brep, converting representation of {} to mesh.".format(ifc_entity))
shape = mesh_to_IfcShellBasedSurfaceModel(file, body.to_viewmesh(linear_deflection=TOL.lineardeflection)[0])
else:
shape = brep_to_ifc_advanced_brep(file, body)
else:
raise Exception("Unsupported body type.")
return shape
Expand Down

0 comments on commit 1f335c8

Please sign in to comment.