Function quantizePositions3AndCreateMat4

  • Quantizes 3D position data into a compressed 16-bit format and generates a matrix for decompressing the positions. The function maps the 3D positions into a defined axis-aligned bounding box (AABB), scales them to fit into a 16-bit integer range, and then constructs a transformation matrix (combining translation and scaling) for future decompression operations.

    This process is commonly used in mesh compression to minimize the storage size of the positions while maintaining the relative precision within the bounding box. The decompress matrix can be used to recover the original positions after decompression.

    Parameters

    • positions: FloatArrayParam

      A flat array of 3D position data (x, y, z).

    • aabb: FloatArrayParam

      The axis-aligned bounding box (AABB) represented as a 6-element array [xmin, ymin, zmin, xmax, ymax, zmax].

    • positionsDecompressMatrix: FloatArrayParam

      A 4x4 matrix to be populated with the transformation matrix for decompression.

    Returns Uint16Array<any>

    A new array containing the quantized positions in a compressed 16-bit format.

    const positions = new Float32Array([0.5, 0.7, 1.0, 1.2, 1.8, 2.0]);
    const aabb = new Float32Array([0, 0, 0, 2, 2, 2]);
    const positionsDecompressMatrix = new Float32Array(16); // 4x4 matrix
    const quantizedPositions = quantizePositions3AndCreateMat4(positions, aabb, positionsDecompressMatrix);
    console.log(quantizedPositions);
    console.log(positionsDecompressMatrix); // The transformation matrix for decompression