Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    Class FloatPacking

    Utility static class providing functionality to pack float values to various storage representations.

    float2Half converts a JavaScript number to the 16-bit half-float encoding used by half-precision textures and vertex formats, so float data can be uploaded to the GPU at half the size.

    // Fill a half-float buffer from an array of numbers
    const halves = new Uint16Array(values.length);
    for (let i = 0; i < values.length; i++) {
    halves[i] = FloatPacking.float2Half(values[i]);
    }
    Index
    • Packs a float to a 16-bit half-float representation used by the GPU.

      Parameters

      • value: number

        The float value to pack.

      Returns number

      The 16-bit half-float representation as an integer.

      const half = FloatPacking.float2Half(1.5);