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.

Parameters:
  • total_frames (int) – Total number of frames available.

  • num_samples (int) – Desired number of evenly distributed frame samples.

Returns:

np.ndarray – Array of integer frame indices with shape (N,) and dtype intp, where N <= num_samples.

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 dtype intp.

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 dtype float64 representing (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 dtype float64 representing (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.ndarray or None, optional) – Target center point array with shape (3,) and dtype float64 representing (X, Y, Z) coordinates. None uses (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.ndarray or None, optional) – Pivot center point array with shape (3,) and dtype float64. If None, 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 (float or np.ndarray) – Uniform scale factor as a float or per axis scale array with shape (3,) and dtype float64 for (sX, sY, sZ) scaling.

  • pivot (np.ndarray or None, optional) – Pivot center point array with shape (3,) and dtype float64. If None, 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.ndarray or None, optional) – Translation vector with shape (3,) and dtype float64.

  • rotation (scipy.spatial.transform.Rotation or None, optional) – Rotation to apply.

  • scale (float or np.ndarray or None, optional) – Scaling factor or per axis scale array with shape (3,).

  • pivot (np.ndarray or None, optional) – Pivot point array with shape (3,) and dtype float64.

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 dtype float64 representing (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 (mapping of str to riley.ConnectConvention) – Explicit source connectivity convention for every block.

  • mesh_types (mapping of str to riley.MeshType or None, optional) – Target Riley topology/implementation for each block. Natural surface types are used when omitted.

  • shaders (mapping of str to object or None, optional) – Backend-owned shader for each block.

  • displacement_keys (Sequence[str] or None, optional) – Names of the three displacement components. None omits motion.

Returns:

dict of str to Mesh3D – 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] or np.ndarray) – Indices to slice along the leading dimension.

Returns:

np.ndarray – Sliced array containing only the selected frames.