99from compas .geometry import Translation
1010from compas .geometry import Point
1111from compas .geometry import Polyline
12+ from compas .geometry import Polygon
1213from compas .datastructures import Mesh
1314
1415from OCC .Extend .DataExchange import read_step_file
5657from OCC .Core .STEPControl import STEPControl_Writer
5758from OCC .Core .STEPControl import STEPControl_AsIs
5859from OCC .Core .IFSelect import IFSelect_RetDone
60+ from OCC .Core .Interface import Interface_Static_SetCVal
5961from OCC .Core .TopTools import TopTools_IndexedDataMapOfShapeListOfShape
6062from OCC .Core .TopTools import TopTools_ListIteratorOfListOfShape
6163from OCC .Core .TopExp import topexp_MapShapesAndUniqueAncestors
@@ -747,7 +749,7 @@ def to_json(self, filepath: str):
747749 with open (filepath , "w" ) as f :
748750 self .occ_shape .DumpJson (f )
749751
750- def to_step (self , filepath : str , schema : str = "AP203" , unit : str = "MM " ) -> None :
752+ def to_step (self , filepath : str , schema : str = "AP203" , unit : str = "M " ) -> None :
751753 """Write the BRep shape to a STEP file.
752754
753755 Parameters
@@ -767,7 +769,7 @@ def to_step(self, filepath: str, schema: str = "AP203", unit: str = "MM") -> Non
767769 # write_step_file(self.occ_shape, filepath)
768770 step_writer = STEPControl_Writer ()
769771 # Interface_Static_SetCVal("write.step.schema", schema)
770- # Interface_Static_SetCVal("write.step.unit", unit)
772+ Interface_Static_SetCVal ("write.step.unit" , unit )
771773 step_writer .Transfer (self .occ_shape , STEPControl_AsIs )
772774 status = step_writer .Write (filepath )
773775 assert status == IFSelect_RetDone , status
@@ -827,7 +829,17 @@ def to_meshes(self, u=16, v=16):
827829 meshes .append (mesh )
828830 return meshes
829831
830- def to_viewmesh (self ):
832+ def to_polygons (self ):
833+ """Convert the faces of the BRep to simple polygons without underlying geometry."""
834+ polygons = []
835+ for face in self .faces :
836+ points = []
837+ for vertex in face .loops [0 ].vertices :
838+ points .append (vertex .point )
839+ polygons .append (Polygon (points ))
840+ return polygons
841+
842+ def to_viewmesh (self , linear_deflection = 1e-3 ):
831843 """Convert the BRep to a view mesh."""
832844 lines = []
833845 for edge in self .edges :
@@ -841,7 +853,7 @@ def to_viewmesh(self):
841853 lines .append (Polyline (edge .curve .locus ()))
842854 elif edge .is_bspline :
843855 lines .append (Polyline (edge .curve .locus ()))
844- return self .to_tesselation (), lines
856+ return self .to_tesselation (linear_deflection = linear_deflection ), lines
845857
846858 # ==============================================================================
847859 # Relationships
0 commit comments