Represents a 3D transformation containing position, rotation, and scale components. This class provides a convenient way to handle 3D object transformations with automatic matrix composition and decomposition capabilities.

const transform = new Transform3D();
transform.position = Vector3.fromCopyArray([1, 2, 3]);
transform.scale = Vector3.fromCopyArray([2, 2, 2]);
transform.rotation = Quaternion.fromEulerAngles(0, Math.PI / 4, 0);
const matrix = transform.matrix;

Constructors

Accessors

  • get updateCount(): number
  • Gets the number of times this transform has been updated. This can be useful for optimization and caching purposes.

    Returns number

    The update count as a number

Methods

  • Efficiently computes the transformation matrix and stores it in the provided matrix. This method avoids memory allocation by reusing an existing matrix object.

    Parameters

    Returns void

  • Rotates the transform to face from one direction to another. Calculates the rotation needed to align the 'from' direction with the 'to' direction.

    Parameters

    • fromVec: Vector3

      The current forward direction

    • toVec: Vector3

      The target direction to face towards

    Returns void

  • Checks if this transform is equal to another transform within a given tolerance.

    Parameters

    • rhs: Transform3D

      The transform to compare against

    • delta: number = Number.EPSILON

      The tolerance for comparison (default: Number.EPSILON)

    Returns boolean

    True if the transforms are equal within the specified tolerance

  • Sets the position using an array of three numbers.

    Parameters

    • array: Array3<number>

      Array containing [x, y, z] position values

    Returns void

  • Sets transform properties from a JSON object. Supports setting position, scale, rotation (as quaternion), and matrix properties.

    Parameters

    • arg: JSON

      JSON object or JSON string containing transform properties

    Returns void

  • Sets the rotation using an array of four numbers representing a quaternion.

    Parameters

    • array: Array4<number>

      Array containing [x, y, z, w] quaternion values

    Returns void

  • Sets the rotation to align with specified up and front vectors. Creates a coordinate system where the Y-axis aligns with the up vector and the Z-axis aligns with the front vector.

    Parameters

    • UpVec: IVector3

      The desired up direction (Y-axis)

    • FrontVec: IVector3

      The desired front direction (Z-axis)

    Returns void

  • Sets the scale using an array of three numbers.

    Parameters

    • array: Array3<number>

      Array containing [x, y, z] scale values

    Returns void

  • Sets multiple transform components at once for optimal performance. This method reduces the cost of automatically updating transform matrices by setting all components in a single operation. Useful for animation and batch updates where performance is critical.

    Note: The provided transform components must be mutually consistent. For example, if a matrix is provided, its decomposed translate, rotate, and scale components should match the individual component arguments.

    Parameters

    Returns void