Skip to content

shore.geometry.occt ​

OCCT backend of the Geometry protocol (ADR 0002).

Exact B-rep geometry from STEP, BREP or IGES via OpenCASCADE (OCP, installed with build123d: pip install 'shore-mesh[cad]'). Entities are the shape's faces (SURFACE), edges (CURVE) and vertices (POINT), indexed in TopExp.MapShapes order; indices are stable for one load only (persistent identity is ADR 0003).

Projection has two tiers:

  • exact=False (tier 1, vectorised): closest point on a tessellation that is built once at load and keeps (u, v) and the oriented surface normal at every node; parameters and normals are interpolated barycentrically. Closest points come from trimesh on the tessellation (R-trees built once at load, ~2.5e4-1.3e5 points/s). BRepMesh enforces its deflection on edges; triangle interiors sag up to ~2x further. For a query at distance h from the surface the error is about 2 \* deflection + h \* (facet normal error): a couple of deflections for points near the surface (smoothing, dragging), more for distant points, which should use exact=True. Where a parameter is singular (a sphere pole, a cone apex: the surface derivative along it vanishes) the arbitrary value at the singular node is left out of that parameter's interpolation.
  • exact=True (tier 2, per point): Newton projection onto the exact face surface, seeded from tier 1, with a trimming check; points whose foot lies outside the trimmed face fall back to an exact shape-distance query, so the answer stays on the face (or its boundary). Curves use a clamped Newton iteration on the exact edge curve.

ray_cast answers on the tessellation (tier 1), through the same Projector the STL backend uses.

These calls run in the caller's thread and hold the GIL; a GUI must run long loads in a subprocess (ADR 0006).

OcctGeometry class ​

python
OcctGeometry(
    shape: TopoDS_Shape,
    *,
    deflection: float | None = None,
    rel_deflection: float = 0.001,
    angular_deflection: float = 0.2,
    heal: bool = True,
)

source

B-rep body as a Geometry.

Parameters

  • shape — OCCT shape (TopoDS_Shape), e.g. build123d_object.wrapped.
  • deflection — Absolute linear deflection of the tier-1 tessellation. Default: rel_deflection times the bounding-box diagonal.
  • rel_deflection — Linear deflection relative to the bounding-box diagonal.
  • angular_deflection — Angular deflection of the tessellation, radians.
  • heal — Run ShapeFix_Shape on the input first.

OcctGeometry.from_file classmethod ​

python
from_file(path: str | Path, **kwargs: object) -> OcctGeometry

source

Load .step/.stp (build123d), .brep/.brp (build123d) or .iges/.igs (OCP IGESControl_Reader).

OcctGeometry.bounds property ​

python
bounds: np.ndarray

source

OcctGeometry.display method ​

python
display() -> Display

source

The model as drawn (ADR 0038): the tier-1 tessellation, each triangle owned by its face; edges as polylines; vertices.

OcctGeometry.entities method ​

python
entities(kind: EntityKind) -> tuple[EntityRef, ...]

source

OcctGeometry.ray_cast method ​

python
ray_cast(
    anchor: np.ndarray,
    dirs: np.ndarray,
    on_failure: str = 'raise',
) -> ProjectionResult

source

OcctGeometry.project method ​

python
project(
    points: np.ndarray,
    entity: EntityRef | None = None,
    *,
    exact: bool = False,
) -> Projection

source

OcctGeometry.evaluate method ​

python
evaluate(entity: EntityRef, params: np.ndarray) -> np.ndarray

source

OcctGeometry.fingerprint method ​

python
fingerprint(entity: EntityRef) -> EntityKey

source

Fingerprint: OCCT geometric type, centroid, area/length, bbox (cached).

OcctGeometry.proxy property ​

python
proxy: trimesh.Trimesh

source

The tier-1 tessellation (faces not merged across edges).

OcctGeometry.merged_proxy method ​

python
merged_proxy() -> trimesh.Trimesh

source

The tessellation with coincident vertices merged and degenerate triangles dropped: watertight for a closed solid.

For mesh-based consumers that need a closed triangulation (inside/outside tests, plane sections, dihedral-angle TE detection). Its vertex normals are smoothed across face boundaries, so do not read normals from it: use project.

Released under the MIT License.