BabylonJS/Babylon.js · error · ReferenceError

Can not floor a color

Error message

Can not floor a color

What it means

Color3.floorToRef is a deliberate stub that throws ReferenceError("Can not floor a color"). Component-wise flooring is not supported for Color3 in this API because it has no defined color-space meaning. Any call throws unconditionally.

Source

Thrown at packages/dev/core/src/Maths/math.color.pure.ts:275

     * Updates the current Color3 with the maximal coordinate values between its and the given coordinates.
     * @param r defines the r coordinate of the operand
     * @param g defines the g coordinate of the operand
     * @param b defines the b coordinate of the operand
     * @returns the current updated Color3
     */
    public maximizeInPlaceFromFloats(r: number, g: number, b: number): this {
        this.r = Math.max(r, this.r);
        this.g = Math.max(g, this.g);
        this.b = Math.max(b, this.b);
        return this;
    }

    /**
     * @internal
     * Do not use
     */
    public floorToRef(_result: IColor3Like): never {
        throw new ReferenceError("Can not floor a color");
    }

    /**
     * @internal
     * Do not use
     */
    public floor(): never {
        throw new ReferenceError("Can not floor a color");
    }

    /**
     * @internal
     * Do not use
     */
    public fractToRef(_result: IColor3Like): never {
        throw new ReferenceError("Can not fract a color");
    }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Floor components manually: result.r = Math.floor(c.r); result.g = Math.floor(c.g); result.b = Math.floor(c.b).
  2. Clamp channels to [0,1] with Math.min/Math.max if the goal is range limiting, not flooring.
  3. Use a Vector3 if you need the full vector operation set.
  4. Route color inputs away from generic floor/quantization helpers.

Example fix

// before
const out = {};
color.floorToRef(out);
// after
const out = {
  r: Math.floor(color.r),
  g: Math.floor(color.g),
  b: Math.floor(color.b)
};
Defensive patterns

Strategy: fallback

Validate before calling

if (color instanceof Color3) {
  result.r = Math.floor(color.r);
  result.g = Math.floor(color.g);
  result.b = Math.floor(color.b);
} else {
  color.floorToRef(result);
}

Type guard

function isColor3Like(c: unknown): c is IColor3Like {
  return !!c && typeof c === 'object' && 'r' in c && 'g' in c && 'b' in c && !('a' in c);
}

Try / catch

try {
  color.floorToRef(result);
} catch (e) {
  if (e instanceof ReferenceError && e.message === 'Can not floor a color') {
    result.r = Math.floor(color.r);
    result.g = Math.floor(color.g);
    result.b = Math.floor(color.b);
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling color3.floorToRef(result) directly, or generic quantization code that applies floorToRef to an IColor3Like object.

Common situations: Quantizing/clamping color channel values with vector-style helpers; bulk processing of arrays of colors with a shared math routine; porting numeric pipelines to colors.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/cfecd3cbbb3d4d89. Report an issue: GitHub.