simvx.core.helpers.matrix

NumPy matrix helpers for TRS composition and GPU upload.

Module Contents

Functions

mat4_from_trs

Build model matrix from position, rotation quaternion, and scale.

batch_mat4_from_trs

Build N model matrices from arrays of positions, quaternions, and scales.

mat4_to_bytes

Convert mat4 to bytes for GPU upload (64 bytes, row-major float32).

API

simvx.core.helpers.matrix.mat4_from_trs(pos: tuple[float, float, float] | numpy.ndarray, rot, scl: tuple[float, float, float] | numpy.ndarray) numpy.ndarray[source]

Build model matrix from position, rotation quaternion, and scale.

Args: pos: Position (x, y, z) rot: Rotation quaternion — Quat or any object with .w/.x/.y/.z scl: Scale (x, y, z)

Returns: 4x4 model matrix as numpy array (Translate * Rotate * Scale)

simvx.core.helpers.matrix.batch_mat4_from_trs(positions: numpy.ndarray, rotations: numpy.ndarray, scales: numpy.ndarray) numpy.ndarray[source]

Build N model matrices from arrays of positions, quaternions, and scales.

Args: positions: (N, 3) float32 positions rotations: (N, 4) float32 quaternions [w, x, y, z] scales: (N, 3) float32 scale factors

Returns: (N, 4, 4) float32 model matrices (Translate * Rotate * Scale)

simvx.core.helpers.matrix.mat4_to_bytes(m: numpy.ndarray) bytes[source]

Convert mat4 to bytes for GPU upload (64 bytes, row-major float32).