Skip to content

shore.mesh.body ​

Body: a geometry (STL or CAD) with structured sphere projection.

Body dataclass ​

python
Body(
    mesh: trimesh.Trimesh | None = None,
    anchor: np.ndarray = field(default=None, compare=False, repr=False),
    geometry: Geometry = field(default=None, compare=False, repr=False),
    anchor_error: MeshInputError | None = field(default=None, compare=False, repr=False),
)

source

Body surface with ray-cast projection capability.

Parameters

  • mesh — Triangulated body surface. For a CAD body (geometry given) it may be omitted and defaults to the geometry's merged tessellation, which serves the mesh-based consumers (anchor resolution, C-grid slicing).
  • anchor — Ray-cast origin, shape (3,). When None, defaults to the mesh centroid (set by __post_init__).
  • geometry — The body as a Geometry. When None, an StlGeometry over mesh. Projections (k=0 ray casts, marching normals) go through it.
  • anchor_error — Why no anchor could be resolved (from_stl / from_file): the body loads, and the error is raised where the anchor is first used, by projector (ADR 0018). Collars never ray-cast, so an open half-model body without an interior point still serves them.

Body.from_stl classmethod ​

python
from_stl(
    path: str | Path,
    anchor_strategy: str = 'auto',
    skip_hygiene: bool = False,
) -> Body

source

Load an STL and resolve the anchor point.

Parameters

  • path — Path to the STL file.
  • anchor_strategy — Anchor resolution strategy passed to shore.surface.anchor.resolve_anchor. 'auto' (default) tries incenter then bbox with containment validation; 'centroid' replicates the legacy behaviour.
  • skip_hygiene — Bypass mesh hygiene (merge_vertices / fix_normals / remove degenerate faces). Preserves legacy behaviour for regression tests.

Body.from_file classmethod ​

python
from_file(
    path: str | Path,
    anchor_strategy: str = 'auto',
    skip_hygiene: bool = False,
) -> Body

source

Load an STL or a CAD file (STEP/IGES/BREP) and resolve the anchor.

STL goes through from_stl. CAD needs shore-mesh[cad]; the anchor is resolved on the merged tessellation, and skip_hygiene does not apply.

Body.is_cad property ​

python
is_cad: bool

source

True when the body has exact (non-STL) geometry.

Body.projector property ​

python
projector: Projector | AnchoredCaster

source

Anchored ray caster for the k=0 builders, one per Body.

STL: geometry.projector(anchor) (the legacy Projector, sharing the geometry's BVH; results bit-identical to before). CAD: an AnchoredCaster that casts on the tessellation and snaps hits to the exact surface.

Raises the anchor resolution error when the body has no anchor.

Body.normals method ​

python
normals(points: np.ndarray) -> np.ndarray

source

Unit outward surface normals at the closest body points (..., 3).

A CAD body gives its exact geometry normals. An STL body gives the blend of trimesh's vertex normals (_stl_normals), smooth across sharp edges, not the crease-aware normals of StlGeometry (ADR 0014, 0015). ADR 0005's acceptance spec measures k-line angles against them; the marcher's normal blending that also read them is removed (ADR 0034).

Body.project method ​

python
project(
    ni: int,
    nj: int,
    theta_cap: float | None = None,
    theta_cap_deg: float | None = None,
    i_spacing: str = 'uniform',
    i_beta: float = 3.0,
    j_spacing: str = 'uniform',
    j_beta: float = 3.0,
    j_cluster_lon: float | None = None,
) -> np.ndarray

source

Ray-cast a structured lat-lon grid onto the body surface.

Parameters

  • ni, nj — Latitude and longitude resolution.
  • theta_cap — Polar exclusion angle in radians.
  • theta_cap_deg — Polar exclusion angle in degrees (mutually exclusive with theta_cap).

Returns

  • np.ndarray, shape (ni, nj, 3) — Coordinates of the k=0 structured surface layer.

Body.project_caps method ​

python
project_caps(
    ni: int,
    nj: int,
    theta_cap: float | None = None,
    theta_cap_deg: float | None = None,
    i_spacing: str = 'uniform',
    i_beta: float = 3.0,
    j_spacing: str = 'uniform',
    j_beta: float = 3.0,
    j_cluster_lon: float | None = None,
    pole_eps_deg: float = 0.5,
) -> tuple[np.ndarray, int]

source

Unified ray-cast covering the full sphere for the cubed-sphere topology.

Returns the full projected surface plus the split index nc_cap. Rows 0 .. nc_cap-1 are the south cap, rows nc_cap .. ni_total-nc_cap are the equatorial band, rows ni_total-nc_cap .. are the north cap.

Parameters

  • ni — Number of equatorial rows.
  • nj — Longitude resolution (multiple of 4).
  • theta_cap — Polar split angle in radians. Default 0.05 * pi (~9 deg).
  • theta_cap_deg — Convenience alias in degrees.
  • pole_eps_deg — Angular exclusion at each pole in degrees (default 0.5 deg).

Returns

  • surface (np.ndarray, shape (ni_total, nj, 3))
  • nc_cap (int)

Body.directions method ​

python
directions(
    ni: int,
    nj: int,
    theta_cap: float | None = None,
    theta_cap_deg: float | None = None,
    i_spacing: str = 'uniform',
    i_beta: float = 3.0,
    j_spacing: str = 'uniform',
    j_beta: float = 3.0,
    j_cluster_lon: float | None = None,
) -> np.ndarray

source

Return (ni, nj, 3) unit direction vectors without casting rays.

Body.save_surface staticmethod ​

python
save_surface(surface: np.ndarray, path: str | Path) -> None

source

Save a k=0 surface layer to a compressed .npz file.

Body.load_surface staticmethod ​

python
load_surface(path: str | Path) -> np.ndarray

source

Load a k=0 surface layer from a .npz file.

Released under the MIT License.