pyvale.render.meshtools module¶
Conversion and geometric transformations for render surface meshes.
- evenly_spaced_frame_indices(total_frames, num_samples)[source]¶
Return sample indices evenly distributed from 0 to total_frames - 1.
- first_last_frame_indices(total_frames)[source]¶
Return indices for the first and last frame.
- Parameters:
total_frames (
int) – Total number of available frames.- Returns:
np.ndarray– Array of frame indices with shape(2,)(or(1,)/(0,)) and dtypeintp.
- mesh_bounds(mesh)[source]¶
Calculate the axis aligned bounding box of a mesh.
- Parameters:
mesh (
Mesh3D) – Mesh to query.- Returns:
tuple[np.ndarray,np.ndarray]– Tuple of(coord_min, coord_max)arrays, each with shape(3,)and dtypefloat64representing (X, Y, Z) minimum and maximum extents.
- mesh_center(mesh)[source]¶
Calculate the center of the axis aligned bounding box of a mesh.
- Parameters:
mesh (
Mesh3D) – Mesh to query.- Returns:
np.ndarray– Midpoint of the bounding box with shape(3,)and dtypefloat64representing (X, Y, Z) center coordinates.
- mesh_center_at(mesh, target=None)[source]¶
Translate a mesh so its bounding box center lies at
target.- Parameters:
mesh (
Mesh3D) – Source surface mesh to re centre.target (
np.ndarrayorNone, optional) – Target center point array with shape(3,)and dtypefloat64representing (X, Y, Z) coordinates.Noneuses(0, 0, 0).
- Returns:
Mesh3D– New translated mesh instance.
- mesh_rotate(mesh, rotation, pivot=None)[source]¶
Rotate a mesh around a pivot point.
Displacement vectors are rotated as vector fields to match coordinate reorientation.
- Parameters:
mesh (
Mesh3D) – Source surface mesh to rotate.rotation (
scipy.spatial.transform.Rotation) – Spatial rotation to apply.pivot (
np.ndarrayorNone, optional) – Pivot center point array with shape(3,)and dtypefloat64. IfNone, defaults to the origin(0, 0, 0).
- Returns:
Mesh3D– New rotated mesh instance.
- mesh_scale(mesh, scale, pivot=None)[source]¶
Scale a mesh relative to a pivot point.
- Parameters:
mesh (
Mesh3D) – Source surface mesh to scale.scale (
floatornp.ndarray) – Uniform scale factor as a float or per axis scale array with shape(3,)and dtypefloat64for (sX, sY, sZ) scaling.pivot (
np.ndarrayorNone, optional) – Pivot center point array with shape(3,)and dtypefloat64. IfNone, defaults to the origin(0, 0, 0).
- Returns:
Mesh3D– New scaled mesh instance.
- mesh_transform(mesh, translation=None, rotation=None, scale=None, pivot=None)[source]¶
Apply affine scaling, rotation, and translation in canonical order.
Order: 1. Scale about pivot, 2. Rotate about pivot, 3. Translate.
- Parameters:
mesh (
Mesh3D) – Source surface mesh to transform.translation (
np.ndarrayorNone, optional) – Translation vector with shape(3,)and dtypefloat64.rotation (
scipy.spatial.transform.RotationorNone, optional) – Rotation to apply.scale (
floatornp.ndarrayorNone, optional) – Scaling factor or per axis scale array with shape(3,).pivot (
np.ndarrayorNone, optional) – Pivot point array with shape(3,)and dtypefloat64.
- Returns:
Mesh3D– New transformed mesh instance.
- mesh_translate(mesh, translation)[source]¶
Translate a mesh by an offset vector without mutating the original.
Note that translation shifts nodal coordinates but preserves nodal displacement vectors unchanged.
- Parameters:
mesh (
Mesh3D) – Source surface mesh to translate.translation (
np.ndarray) – Translation vector array with shape(3,)or(2,)and dtypefloat64representing (dX, dY, dZ) offsets.
- Returns:
Mesh3D– New translated mesh instance.
- meshes3d_from_simdata(sim_data, conventions, *, mesh_types=None, shaders=None, displacement_keys=None)[source]¶
Build one prepared surface mesh for each simulation mesh block.
- Parameters:
sim_data (
pyvale.dataio.SimData) – Simulation data containing coordinates, connectivity, and optionally nodal displacement fields.conventions (
mappingofstrtoriley.ConnectConvention) – Explicit source connectivity convention for every block.mesh_types (
mappingofstrtoriley.MeshTypeorNone, optional) – Target Riley topology/implementation for each block. Natural surface types are used when omitted.shaders (
mappingofstrtoobjectorNone, optional) – Backend-owned shader for each block.displacement_keys (
Sequence[str]orNone, optional) – Names of the three displacement components.Noneomits motion.
- Returns:
dictofstrtoMesh3D– Prepared meshes keyed by input connectivity block.
- select_frames(frames, indices)[source]¶
Index a leading frame dimension with integer indices.
- Parameters:
frames (
np.ndarray) – Array whose leading dimension is frames, e.g. shape(num_frames, ...).indices (
Sequence[int]ornp.ndarray) – Indices to slice along the leading dimension.
- Returns:
np.ndarray– Sliced array containing only the selected frames.