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 distancehfrom the surface the error is about2 \* deflection + h \* (facet normal error): a couple of deflections for points near the surface (smoothing, dragging), more for distant points, which should useexact=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
OcctGeometry(
shape: TopoDS_Shape,
*,
deflection: float | None = None,
rel_deflection: float = 0.001,
angular_deflection: float = 0.2,
heal: bool = True,
)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_deflectiontimes the bounding-box diagonal.rel_deflection— Linear deflection relative to the bounding-box diagonal.angular_deflection— Angular deflection of the tessellation, radians.heal— RunShapeFix_Shapeon the input first.
OcctGeometry.from_file classmethod
from_file(path: str | Path, **kwargs: object) -> OcctGeometryLoad .step/.stp (build123d), .brep/.brp (build123d) or .iges/.igs (OCP IGESControl_Reader).
OcctGeometry.bounds property
bounds: np.ndarrayOcctGeometry.display method
display() -> DisplayThe model as drawn (ADR 0038): the tier-1 tessellation, each triangle owned by its face; edges as polylines; vertices.
OcctGeometry.entities method
entities(kind: EntityKind) -> tuple[EntityRef, ...]OcctGeometry.ray_cast method
ray_cast(
anchor: np.ndarray,
dirs: np.ndarray,
on_failure: str = 'raise',
) -> ProjectionResultOcctGeometry.project method
project(
points: np.ndarray,
entity: EntityRef | None = None,
*,
exact: bool = False,
) -> ProjectionOcctGeometry.evaluate method
evaluate(entity: EntityRef, params: np.ndarray) -> np.ndarrayOcctGeometry.fingerprint method
fingerprint(entity: EntityRef) -> EntityKeyFingerprint: OCCT geometric type, centroid, area/length, bbox (cached).
OcctGeometry.proxy property
proxy: trimesh.TrimeshThe tier-1 tessellation (faces not merged across edges).
OcctGeometry.merged_proxy method
merged_proxy() -> trimesh.TrimeshThe 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.