compas_brep
¤
compas_brep: Pure Python Brep implementation based on the COMPAS framework.
Classes¤
Brep
¤
Brep(name: str | None = None)
Thin wrapper around a native backend geometry object (OCC or Rhino).
_native_brep is the sole source of truth. Topology lists are lazy caches
populated on demand from native via _ensure_topology; they are never written
as primary data. All public interface values are COMPAS types.
-
API Reference
-
compas_brep ClassesBrep Methods:-
__add__ -
__and__ -
__sub__ -
copy -
filleted -
from_boolean_difference -
from_boolean_intersection -
from_boolean_union -
from_boolean_union_multi -
from_box -
from_brepfaces -
from_breps -
from_cone -
from_curves -
from_cylinder -
from_extrusion -
from_iges -
from_loft -
from_mesh -
from_native -
from_pipe -
from_plane -
from_polygons -
from_sphere -
from_step -
from_surface -
from_sweep -
from_torus -
offset -
overlap -
split -
trimmed
-
-
Topology
brep ClassesBrep Methods:-
__add__ -
__and__ -
__sub__ -
copy -
filleted -
from_boolean_difference -
from_boolean_intersection -
from_boolean_union -
from_boolean_union_multi -
from_box -
from_brepfaces -
from_breps -
from_cone -
from_curves -
from_cylinder -
from_extrusion -
from_iges -
from_loft -
from_mesh -
from_native -
from_pipe -
from_plane -
from_polygons -
from_sphere -
from_step -
from_surface -
from_sweep -
from_torus -
offset -
overlap -
split -
trimmed
-
-
- API Reference
Attributes¤
Methods:¤
__add__
¤
A + B. Same as :meth:from_boolean_union, so it returns a list.
__and__
¤
A & B. Same as :meth:from_boolean_intersection, so it returns a list.
__sub__
¤
A - B. Same as :meth:from_boolean_difference, so it returns a list.
contains
¤
contours
¤
edge_loops
¤
fillet
¤
filleted
¤
from_boolean_difference
classmethod
¤
Boolean subtraction: A - B.
Returns one Brep per resulting piece — a subtraction can cut a shape into several disconnected ones. Empty when nothing is left.
from_boolean_intersection
classmethod
¤
Boolean intersection: A & B.
Returns one Brep per resulting piece. Empty when the two do not overlap.
from_boolean_union
classmethod
¤
Boolean union: A + B.
Returns one Brep per resulting piece — disjoint inputs stay disjoint.
from_boolean_union_multi
classmethod
¤
Boolean union of multiple Breps, chained pairwise.
Only the first piece of each intermediate union is carried into the next step, so disjoint inputs are not all preserved. Union them pairwise if that matters.
Parameters:
-
*breps(Brep, default:()) –Two or more Breps to union.
from_brepfaces
classmethod
¤
Build a Brep from a list of BrepFace objects.
from_breps
classmethod
¤
from_curves
classmethod
¤
from_cylinder
classmethod
¤
Create a Brep from a COMPAS Cylinder.
from_extrusion
classmethod
¤
from_iges
classmethod
¤
from_loft
classmethod
¤
from_native
classmethod
¤
Create a Brep from a native backend object (OCC TopoDS_Shape or Rhino.Geometry.Brep).
Parameters:
-
native_brep(Any) –A native OCC or Rhino brep object.
from_pipe
classmethod
¤
from_plane
classmethod
¤
from_plane(
plane: Plane,
domain_u: tuple[float, float] = (-1, 1),
domain_v: tuple[float, float] = (-1, 1),
) -> Brep
Create a single planar face Brep from a Plane with the given domain.
from_polygons
classmethod
¤
Create a Brep from a list of COMPAS Polygons.
from_step
classmethod
¤
from_surface
classmethod
¤
from_sweep
classmethod
¤
offset
¤
Return an offset copy of this Brep.
Parameters:
-
distance(float) –The offset distance (positive = outward, negative = inward).
overlap
¤
slice
¤
Intersect the Brep with a plane, returning intersection polylines.
Parameters:
-
plane(Plane) –The cutting plane.
split
¤
Split this Brep by a cutter Brep (typically a planar surface).
Parameters:
-
cutter(Brep) –The cutting Brep.
to_iges
¤
to_iges(filepath: str) -> None
Export this Brep to an IGES file.
Parameters:
-
filepath(str) –Path to the output .igs or .iges file.
to_meshes
¤
to_step
¤
to_step(filepath: str, **kwargs) -> None
Export this Brep to a STEP file.
Parameters:
-
filepath(str) –Path to the output .step or .stp file.
to_tesselation
¤
to_tesselation(
linear_deflection: float = 0.1, n: int = 16, n_curves: int = 64
) -> tuple[Mesh, list[Polyline]]
Create a tessellation of the Brep for visualization.
Returns a triangulated mesh and a list of boundary polylines. Matches the interface expected by compas_viewer's BRepObject.
Uses cached tessellation when available. Otherwise delegates to the active backend via the brep_tessellate pluggable and caches the result.
Parameters:
to_viewmesh
¤
Convert the Brep to a single mesh for visualization.
Uses cached tessellation if available, otherwise delegates to the active backend via the brep_tessellate pluggable.
Parameters:
transform
¤
transform(transformation: Transformation) -> None
Transform this Brep in-place by a transformation matrix.
Parameters:
-
transformation(Transformation) –The transformation to apply.
BrepEdge
¤
BrepEdge(
start: BrepVertex,
end: BrepVertex,
curve: Line | Circle | Ellipse | NurbsCurve | None = None,
domain: tuple[float, float] | None = None,
)
A Brep edge defined by start/end vertices and a 3D curve.
The curve is a Line, a Circle, an Ellipse, or a NurbsCurve.
An analytic curve (Circle / Ellipse) is an unbounded closed conic, so
the edge also carries domain -- the parameter interval it actually runs
over, in the parameter space :func:compas_brep.exchange.analytic_curve_point
defines. A quarter-circle fillet edge and a full circular seam are the same
Circle with different domains. Line and NurbsCurve carry their own
extent, so their domain is None.
- API Reference
Attributes¤
domain
property
writable
¤
The parameter interval this edge runs over, for an analytic curve.
end_vertex
property
¤
end_vertex: BrepVertex
Alias of :attr:last_vertex, for compatibility with compas_rhino.
is_arc
property
¤
is_arc: bool
True for an edge running along part of a circle, not the whole of it.
is_circle
property
¤
is_circle: bool
True for a full circular edge. A partial one is an arc -- see :attr:is_arc.
start_vertex
property
¤
start_vertex: BrepVertex
Alias of :attr:first_vertex, for compatibility with compas_rhino.
Methods:¤
BrepError
¤
Represents a generic error in the Brep context.
BrepFace
¤
BrepFace(
outer_loop: BrepLoop,
surface: Plane
| CylindricalSurface
| SphericalSurface
| ToroidalSurface
| ConicalSurface
| NurbsSurface
| None = None,
is_reversed: bool = False,
domain_u: tuple[float, float] | None = None,
domain_v: tuple[float, float] | None = None,
)
A Brep face defined by a surface and boundary loops.
The surface can be a Plane, CylindricalSurface, or NurbsSurface. The outer loop defines the face boundary; inner loops define holes.
- API Reference
Attributes¤
boundary
property
¤
boundary: BrepLoop
Alias of :attr:outer_loop, for compatibility with compas_rhino.
is_bspline
property
¤
is_bspline: bool
Alias of :attr:is_nurbs, for compatibility with compas.geometry.BrepFace.
native_face
property
¤
native_face: object | None
The underlying backend face, or None for a face not backed by a kernel.
nurbssurface
property
¤
nurbssurface: NurbsSurface
The underlying surface of this face as a NURBS surface.
Provided for compatibility with compas.geometry.BrepFace. Like the old
implementations, this returns the unflipped underlying surface - it does not
account for :attr:is_reversed. Prefer :meth:frame_at where a face normal is
what is wanted.
surface_type
property
¤
surface_type: str
Return the surface type as a string: 'plane', 'cylinder', 'sphere', 'torus', 'cone', or 'nurbs'.
Methods:¤
frame_at
¤
The frame of the face at the given surface parameters.
The zaxis of the returned frame is the face normal: for a face whose
:attr:is_reversed is True the underlying surface normal is flipped, so that
opposite faces of a solid report opposite normals. Use :attr:surface directly
to get the unflipped surface.
Parameters:
-
u(float | None, default:None) –The u parameter, in the parametrization of :attr:
surface. Defaults to the middle of :attr:domain_u. -
v(float | None, default:None) –The v parameter, in the parametrization of :attr:
surface. Defaults to the middle of :attr:domain_v.
Returns:
-
class:`compas.geometry.Frame`–A new frame; modifying it does not affect the face.
Notes
A planar face has no parametrization to speak of - :attr:surface is a
:class:compas.geometry.Plane, which carries no x-direction - so for planar
faces u and v are distances along the axes of the plane's own frame,
measured from the plane's origin, and omitting them puts the frame on the face
centroid rather than in the middle of the uv domain.
BrepFilletError
¤
Raised when a fillet operation has failed or had no result.
BrepInvalidError
¤
Raised when the process of re-constructing a Brep has resulted in an invalid Brep.
BrepLoop
¤
BrepLoop(
edges: list[BrepEdge] | None = None,
trims: list[BrepTrim] | None = None,
is_outer: bool = True,
)
Pure Python implementation of a Brep loop.
A loop can store edges directly (legacy) or trims (STEP-inspired). When trims are present, edges are derived from them.
- API Reference
BrepTrim
¤
BrepTrim(
edge: BrepEdge | None,
is_reversed: bool = False,
curve_2d: NurbsCurve | None = None,
vertex: BrepVertex | None = None,
)
A coedge: a directed usage of a BrepEdge within a BrepLoop on a BrepFace.
Inspired by STEP's ORIENTED_EDGE / PCURVE model. A trim wraps a shared
BrepEdge with:
- is_reversed: whether this usage traverses the edge backward
- curve_2d: a NurbsCurve in the face surface's UV parameter space (pcurve)
The pcurve allows direct UV-space tessellation without 3D→UV inversion. The 3D curve and vertices are accessed via the underlying edge.
- API Reference
Attributes¤
curve
property
writable
¤
curve: NurbsCurve | None
The 2D parametric curve in the face's UV space (pcurve).
curve_2d
property
writable
¤
curve_2d: NurbsCurve | None
Alias for the 2D parametric curve (pcurve).
is_singular
property
¤
is_singular: bool
Whether this trim has no edge and collapses to a single vertex.
A sphere's poles are the canonical case: the trim spans the full u-range of the surface at v = min or v = max, but every point on it is the same point in 3D.
vertex
property
¤
vertex: BrepVertex | None
The vertex a singular trim collapses to. None for an ordinary trim.
Methods:¤
sample_points
¤
Sample points along this trim for visualization.
When a pcurve is available, samples via pcurve → surface evaluation so the resulting polyline lies exactly on the tessellated surface mesh. Falls back to the 3D edge curve when no pcurve is present.
Parameters:
BrepTrimmingError
¤
Raised when a trimming operation has failed or had no result.
BrepVertex
¤
BrepVertex(point: Point)
Pure Python implementation of a Brep vertex.
- API Reference
LoopType
¤
Constants describing the role of a loop within its face.
Mirrors the loop types of Rhino.Geometry.BrepLoopType for the two cases
compas_brep distinguishes.
NurbsCurve
¤
NurbsCurve(name: str | None = None)
A rational NURBS curve.
Parameters:
-
name(str | None, default:None) –The name of the curve.
-
API Reference
-
compas_brep Classes - Geometry
-
Topology
trim ClassesBrepTrim Attributes
-
- API Reference
Attributes¤
Methods:¤
frame_at
¤
from_circle
classmethod
¤
from_circle(circle: Circle) -> NurbsCurve
Create a rational NURBS circle (degree 2, 9 control points).
Parameters:
-
circle(Circle) –The circle.
from_ellipse
classmethod
¤
from_ellipse(ellipse: Ellipse) -> NurbsCurve
Create a rational NURBS ellipse (degree 2, 9 control points).
Parameters:
-
ellipse(Ellipse) –The ellipse.
from_interpolation
classmethod
¤
from_interpolation(points: list[Point], degree: int = 3) -> NurbsCurve
from_line
classmethod
¤
from_line(line: Line) -> NurbsCurve
from_parameters
classmethod
¤
from_parameters(
points: list[Point],
weights: list[float],
knots: list[float],
mults: list[int] | None = None,
degree: int = 3,
multiplicities: list[int] | None = None,
) -> NurbsCurve
Create a NURBS curve from explicit parameters.
Parameters:
from_points
classmethod
¤
from_points(points: list[Point], degree: int = 3) -> NurbsCurve
point_at
¤
tangent_at
¤
Tangent vector at parameter t (unnormalized).
Uses finite differences on the rational curve.
Parameters:
-
t(float) –Parameter value.
to_linesegments
¤
to_polyline
¤
transform
¤
transform(transformation: Transformation) -> None
Transform all control points in-place.
Parameters:
-
transformation(Transformation) –The transformation to apply.
NurbsSurface
¤
NurbsSurface(name: str | None = None)
A rational NURBS surface (tensor-product).
Parameters:
-
name(str | None, default:None) –The name of the surface.
-
API Reference
-
compas_brep Classes -
Topology
face ClassesBrepFace Attributesnurbssurface -
Geometry
nurbs ClassesNurbsSurface Methods:
-
-
API Reference
-
compas_brep Classes - Topology
-
Geometry
nurbs ClassesControlPointGrid
-
Attributes¤
points
property
¤
points: ControlPointGrid
2-D grid of control points (nu x nv).
Supports both surface.points[i][j] and surface.points[i, j] indexing.
Methods:¤
frame_at
¤
from_extrusion
classmethod
¤
from_extrusion(curve: NurbsCurve, vector: Vector) -> NurbsSurface
Create a surface by extruding a curve along a vector.
U direction follows the curve, V direction is the extrusion.
Parameters:
-
curve(NurbsCurve) –The profile curve.
-
vector(Vector) –The extrusion direction.
from_fill
classmethod
¤
from_fill(
curve1: NurbsCurve,
curve2: NurbsCurve,
curve3: NurbsCurve | None = None,
curve4: NurbsCurve | None = None,
style: str = "stretch",
) -> NurbsSurface
Create a surface filling between boundary curves.
For 2 curves a ruled surface (linear interpolation) is created. For 4 curves a simplified bilinear Coons patch is created.
Parameters:
-
curve1(NurbsCurve) –First boundary curve.
-
curve2(NurbsCurve) –Second boundary curve (opposite to curve1).
-
curve3(NurbsCurve | None, default:None) –Third boundary curve.
-
curve4(NurbsCurve | None, default:None) –Fourth boundary curve.
-
style(str, default:'stretch') –Fill style (currently only "stretch" is supported).
from_meshgrid
classmethod
¤
from_meshgrid(nu: int = 4, nv: int = 4) -> NurbsSurface
from_parameters
classmethod
¤
from_parameters(
points: list[list[Point]],
weights: list[list[float]],
knots_u: list[float],
knots_v: list[float],
mults_u: list[int],
mults_v: list[int],
degree_u: int,
degree_v: int,
) -> NurbsSurface
Create a NurbsSurface from explicit parameters.
Parameters:
-
points(list[list[Point]]) –2-D grid of control points (nu x nv).
-
weights(list[list[float]]) –2-D grid of weights.
-
knots_u(list[float]) –Unique knot values in U direction.
-
knots_v(list[float]) –Unique knot values in V direction.
-
mults_u(list[int]) –Multiplicities in U direction.
-
mults_v(list[int]) –Multiplicities in V direction.
-
degree_u(int) –Degree in U direction.
-
degree_v(int) –Degree in V direction.
from_points
classmethod
¤
Create a NurbsSurface from a 2-D grid of control points.
Generates clamped uniform knot vectors. Degree is clamped to
min(degree, n_points - 1) in each direction.
Parameters:
isocurve_u
¤
isocurve_u(u: float) -> NurbsCurve
isocurve_v
¤
isocurve_v(v: float) -> NurbsCurve
normal_at
¤
point_at
¤
space_u
¤
Return n+1 uniformly spaced parameters in U domain.
Parameters:
-
n(int, default:10) –Number of intervals.
space_v
¤
Return n+1 uniformly spaced parameters in V domain.
Parameters:
-
n(int, default:10) –Number of intervals.
transform
¤
transform(transformation: Transformation) -> None
Transform all control points in-place.
Parameters:
-
transformation(Transformation) –The transformation to apply.