A RGBA color class that extends Vector4 to provide color-specific functionality. Represents colors with red, green, blue, and alpha (transparency) components, each ranging from 0.0 to 1.0.

// Create a red color with full opacity
const red = ColorRgba.fromCopy4(1.0, 0.0, 0.0, 1.0);

// Create from array
const blue = ColorRgba.fromCopyArray([0.0, 0.0, 1.0, 1.0]);

Hierarchy (view full)

Implements

Constructors

Properties

_v: TypedArray = ...

Internal typed array storage for vector components

Accessors

  • get a(): number
  • Gets the alpha (transparency) component of the color.

    Returns number

    The alpha component value (0.0 = transparent, 1.0 = opaque)

  • get bytesPerComponent(): number
  • Gets the number of bytes per component in the underlying typed array.

    Returns number

    The number of bytes per element (4 for Float32Array, 8 for Float64Array)

  • get glslStrAsFloat(): string
  • Converts the vector to a GLSL vec4 string representation with float precision.

    Returns string

    A GLSL-compatible vec4 string (e.g., "vec4(1.0, 2.0, 3.0, 4.0)")

  • get glslStrAsInt(): string
  • Converts the vector to a GLSL ivec4 string representation with integer values.

    Returns string

    A GLSL-compatible ivec4 string (e.g., "ivec4(1, 2, 3, 4)")

  • get w(): number
  • Gets the w component (equivalent to alpha component).

    Returns number

    The w/alpha component value

  • get wgslStrAsFloat(): string
  • Converts the vector to a WGSL vec4f string representation with float precision.

    Returns string

    A WGSL-compatible vec4f string (e.g., "vec4f(1.0, 2.0, 3.0, 4.0)")

  • get wgslStrAsInt(): string
  • Converts the vector to a WGSL vec4i string representation with integer values.

    Returns string

    A WGSL-compatible vec4i string (e.g., "vec4i(1, 2, 3, 4)")

  • get y(): number
  • Gets the y component (equivalent to green component).

    Returns number

    The y/green component value

  • get compositionType(): CompositionTypeClass<"VEC4">
  • Gets the composition type identifier for this vector type.

    Returns CompositionTypeClass<"VEC4">

    The CompositionType.Vec4 identifier

Methods

  • Gets the component value at the specified index.

    Parameters

    • i: number

      The index (0=x, 1=y, 2=z, 3=w)

    Returns number

    The component value at the specified index

  • Calculates the dot product between this vector and another vector. The dot product is the sum of the products of corresponding components.

    Parameters

    • vec: IVector4

      The vector to calculate dot product with

    Returns number

    The dot product of the two vectors

  • Checks if this vector is approximately equal to another vector within a specified tolerance.

    Parameters

    • vec: IVector4

      The vector to compare with

    • delta: number = Number.EPSILON

      The tolerance value for comparison (default: Number.EPSILON)

    Returns boolean

    True if the vectors are approximately equal, false otherwise

  • Checks if the internal storage shares the same ArrayBuffer as the provided one. Useful for determining if vectors share underlying memory.

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer to compare against

    Returns boolean

    True if the same ArrayBuffer is used, false otherwise

  • Gets the component value at the specified index. Alias for the at() method for convenience.

    Parameters

    • i: number

      The index of the component to retrieve

    Returns number

    The component value at the given index

  • Divides a vector by a scalar value and stores the result in the output vector. If the divisor is zero, the result components will be set to Infinity and an error will be logged. This method modifies the output vector in-place for better performance.

    Parameters

    • vec: IVector4

      The vector to divide

    • value: number

      The scalar value to divide by

    • out: IMutableVector4

      The output vector to store the result (will be modified)

    Returns IMutableVector4

    The modified output vector with each component divided by the scalar

  • Divides the left color vector by the right color vector component-wise.

    Parameters

    • l_vec: IVector4

      The left operand color vector (dividend)

    • r_vec: IVector4

      The right operand color vector (divisor)

    Returns ColorRgba

    A new ColorRgba instance representing the component-wise quotient

    Error if any component of r_vec is zero

  • Divides the left vector by the right vector component-wise and stores the result in the output vector. If any component of the right vector is zero, the corresponding result component will be set to Infinity. This method modifies the output vector in-place for better performance.

    Parameters

    • l_vec: IVector4

      The left operand vector (dividend)

    • r_vec: IVector4

      The right operand vector (divisor)

    • out: IMutableVector4

      The output vector to store the result (will be modified)

    Returns IMutableVector4

    The modified output vector with component-wise division result

  • Calculates the dot product of two vectors. The dot product is the sum of the products of corresponding components.

    Parameters

    Returns number

    The dot product of the two vectors

  • Creates a new Vector4 from an ArrayBuffer. The ArrayBuffer should contain at least 16 bytes (4 float32 values).

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer containing vector data

    Returns Vector4

    A new Vector4 instance using the ArrayBuffer data

  • Creates a new ColorRgba instance from individual RGBA component values.

    Parameters

    • x: number

      The red component value

    • y: number

      The green component value

    • z: number

      The blue component value

    • w: number

      The alpha component value

    Returns ColorRgba

    A new ColorRgba instance with the specified component values

  • Creates a new Vector4 by copying from a Float32Array. This creates a new Float32Array copy of the input data.

    Parameters

    • float32Array: Float32Array

      The Float32Array to copy from

    Returns Vector4

    A new Vector4 instance with copied Float32Array data

  • Creates a new Vector4 from a Vector3, setting the W component to 1. This is commonly used for converting 3D positions to homogeneous coordinates.

    Parameters

    • vec3: IVector3

      The source Vector3 to copy from

    Returns Vector4

    A new Vector4 with (vec3.x, vec3.y, vec3.z, 1.0)

  • Creates a new Vector4 from a Float32Array. The Float32Array is used directly without copying.

    Parameters

    • float32Array: Float32Array

      The Float32Array containing vector components

    Returns Vector4

    A new Vector4 instance using the provided Float32Array

  • Calculates the squared length (magnitude) of a vector. This is more efficient than length() when only comparing magnitudes.

    Parameters

    • vec: IVector4

      The vector to calculate squared length for

    Returns number

    The squared length of the vector

  • Multiplies a vector by a scalar value and stores the result in the output vector. This method modifies the output vector in-place for better performance.

    Parameters

    • vec: IVector4

      The vector to multiply

    • value: number

      The scalar value to multiply by

    • out: IMutableVector4

      The output vector to store the result (will be modified)

    Returns IMutableVector4

    The modified output vector with each component multiplied by the scalar

  • Subtracts the right vector from the left vector component-wise and stores the result in the output vector. This method modifies the output vector in-place for better performance.

    Parameters

    • l_vec: IVector4

      The left operand vector (minuend)

    • r_vec: IVector4

      The right operand vector (subtrahend)

    • out: IMutableVector4

      The output vector to store the result (will be modified)

    Returns IMutableVector4

    The modified output vector containing the difference