shore.mesh.body
Body: a geometry (STL or CAD) with structured sphere projection.
Body dataclass
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),
)Body surface with ray-cast projection capability.
Parameters
mesh— Triangulated body surface. For a CAD body (geometrygiven) 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 aGeometry. When None, anStlGeometryover 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, byprojector(ADR 0018). Collars never ray-cast, so an open half-model body without an interior point still serves them.
Body.from_stl classmethod
from_stl(
path: str | Path,
anchor_strategy: str = 'auto',
skip_hygiene: bool = False,
) -> BodyLoad an STL and resolve the anchor point.
Parameters
path— Path to the STL file.anchor_strategy— Anchor resolution strategy passed toshore.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
from_file(
path: str | Path,
anchor_strategy: str = 'auto',
skip_hygiene: bool = False,
) -> BodyLoad 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
is_cad: boolTrue when the body has exact (non-STL) geometry.
Body.projector property
projector: Projector | AnchoredCasterAnchored 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
normals(points: np.ndarray) -> np.ndarrayUnit 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
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.ndarrayRay-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
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]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. Default0.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
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.ndarrayReturn (ni, nj, 3) unit direction vectors without casting rays.
Body.save_surface staticmethod
save_surface(surface: np.ndarray, path: str | Path) -> NoneSave a k=0 surface layer to a compressed .npz file.
Body.load_surface staticmethod
load_surface(path: str | Path) -> np.ndarrayLoad a k=0 surface layer from a .npz file.