Options
All
  • Public
  • Public/Protected
  • All
Menu

Utilities to convert RGBA colors encoded in custom number (hex) format to THREE.Color objects.

The functions provided allows for conversion from and to our custom number based color format, which contains transparency, red, green and blue color channels in a way that each channel occupies 8 bits of resulting number (color format 0xTTRRGGBB). In order to preserve compatibility with THREE.Color class and its hexadecimal color representation, we do not store alpha channel in encoded color's number, but replace it with transparency channel, which is simply opposite to alpha: transparency = 0xFF - alpha Such channel value is stored on the oldest bits (octet) in the integral color (numeric) value, so it is fully compatible with THREE.Color numerical representation (@see [[THREE.Color.getHex]], [[THREE.Color.setHex]]). See also getHexFromRgba and getRgbaFromHex for more info about conversion.

Index

Functions

getAlphaFromHex

  • getAlphaFromHex(hex: number): number
  • Retrieves alpha color channel from hex encoded color value.

    see

    getHexFromRgba.

    Parameters

    • hex: number

      The number encoded color value (representable as 0xRRGGBB or 0xTTRRGGBB in hex).

    Returns number

    The floating point alpha component in <0, 1> range.

getHexFromHsl

  • getHexFromHsl(h: number, s: number, l: number): number
  • Encode and convert HSL value to number coded color format (0xRRGGBB).

    see

    getHexFromRgb.

    Parameters

    • h: number

      Hue component value between 0 and 1.

    • s: number

      Saturation value between 0 and 1.

    • l: number

      Lightness channel between 0 and 1.

    Returns number

getHexFromRgb

  • getHexFromRgb(r: number, g: number, b: number): number
  • Encodes RGB all color channels in single number with format 0xRRGGBB.

    All input channels should be in <0, 1> range (inclusively). See also getHexFromRgba for more information about [[THREE.Color]] compatibility.

    note

    This method is fully compatible with THREE.js color encoding, so you may pass this value directly to THREE.Color c-tor.

    Parameters

    • r: number
    • g: number
    • b: number

    Returns number

getHexFromRgba

  • getHexFromRgba(r: number, g: number, b: number, a: number): number
  • Encodes RGBA channels in custom number coded format (represented in hex as 0xTTRRGGBB).

    We do not use direct alpha channel mapping to hex in order to preserve compatibility with THREE.js color format (0xRRGGBB). This is done by encoding transparency (255 - alpha) instead of alpha on the oldest bits, shifted by [[SHIFT_TRANSPARENCY]]. This way simple 0xRRGGBB color is equal to 0x00RRGGBB without transparency and color defining transparency (alpha < 255) is always recognizable by the oldest bit set:

    (color >> SHIFT_TRANSPARENCY) !== 0.
    note

    All input components are floating points in <0, 1> range (inclusively).

    note

    Although method encodes transparency channel in single number value, it is still compatible with THREE.js number based color coding (0xRRGGBB), so you may pass this value to [[THREE.Color]] c-tor, but keep in mind that transparency will be silently ignored.

    Parameters

    • r: number
    • g: number
    • b: number
    • a: number

    Returns number

getRgbaFromHex

  • getRgbaFromHex(hex: number, target?: RGBA): RGBA
  • Retrieve RGBA channels separately from number encoded custom color format.

    Provides an easy way for channels extraction (r, g, b, a) from custom number coded color format.

    see

    getHexFromRgba.

    Parameters

    • hex: number

      The number encoded color value (0xRRGGBB or 0xTTRRGGBB in hex).

    • Default value target: RGBA = new RGBA()

    Returns RGBA

    r, g, b, a channels in simple object, where each channel value is saved as floating point from 0 to 1 inclusively.

hasAlphaInHex

  • hasAlphaInHex(hex: number): boolean
  • Determines if number encoded color contains alpha (opacity) defined and different then 255.

    Parameters

    • hex: number

      The number encoded color (0xRRGGBB or 0xTTRRGGBB in hex).

    Returns boolean

    True if color has transparency defined.

removeAlphaFromHex

  • removeAlphaFromHex(hex: number): number
  • Remove transparency info from the number coded color, makes it compatible with external libs.

    see

    getAlphaFromHex.

    Parameters

    • hex: number

      The number encoded color value (representable as 0xRRGGBB or 0xTTRRGGBB in hex).

    Returns number

    number coded color value representable as 0xRRGGBB in hex.

Generated using TypeDoc