Request

Response

    Autodesk.Viewing.Scene
    Version 8 preview
    This page documents a preview of the Viewer SDK v8. APIs and content can still change before the final release.

    Color

    new Color(colorOrRed, green, blue)

    Represents an RGB color. Each component (r, g, b) is a number in the range 0.0 to 1.0.

    The color can be initialized from a hexadecimal value, a CSS-style string ('rgb(255,0,0)', '#ff0000', …), or another color. Passing three arguments is interpreted as separate red, green and blue components.

    Parameters

    colorOrRed
    number, string, Color
    Hex, CSS string, or color to copy. Or pass (r, g, b) in 0.0..1.0.
    green
    number
    Green component in 0.0..1.0.
    blue
    number
    Blue component in 0.0..1.0.

    Properties

    r
    number
    The red component, in the range 0.0 to 1.0. Default: 1.
    g
    number
    The green component, in the range 0.0 to 1.0. Default: 1.
    b
    number
    The blue component, in the range 0.0 to 1.0. Default: 1.

    Methods

    set(value)

    Sets this color from a hex value, a CSS color string, or another color.

    Parameters

    value*
    number, string, Color
    Hex value, CSS color string, or color to copy.
    * Required

    Returns

    typedescription
    Color This color.

    setHex(hex)

    Sets this color from a hexadecimal value (e.g. 0xff0000).

    Parameters

    hex*
    number
    Hexadecimal color value.
    * Required

    Returns

    typedescription
    Color This color.

    setRGB(r, g, b)

    Sets the red, green and blue components.

    Parameters

    r*
    number
    Red component, in the range 0.0 to 1.0.
    g*
    number
    Green component, in the range 0.0 to 1.0.
    b*
    number
    Blue component, in the range 0.0 to 1.0.
    * Required

    Returns

    typedescription
    Color This color.

    setHSL(h, s, l)

    Sets this color from hue, saturation and lightness components.

    Parameters

    h*
    number
    Hue, in the range 0.0 to 1.0.
    s*
    number
    Saturation, in the range 0.0 to 1.0.
    l*
    number
    Lightness, in the range 0.0 to 1.0.
    * Required

    Returns

    typedescription
    Color This color.

    setStyle(style)

    Sets this color from a CSS-style string, e.g. 'rgb(255,0,0)', 'rgb(100%,0%,0%)', '#ff0000', or '#f00'.

    Parameters

    style*
    string
    CSS color string.
    * Required

    Returns

    typedescription
    Color This color.

    copy(color)

    Copies the components of the given color into this color.

    Parameters

    color*Color to copy.
    * Required

    Returns

    typedescription
    Color This color.

    copyGammaToLinear(color, gammaFactor)

    Copies the given color, converting it from gamma to linear color space.

    Parameters

    color*Color to copy.
    gammaFactor
    number
    Gamma factor.
    * Required

    Returns

    typedescription
    Color This color.

    copyLinearToGamma(color, gammaFactor)

    Copies the given color, converting it from linear to gamma color space.

    Parameters

    color*Color to copy.
    gammaFactor
    number
    Gamma factor.
    * Required

    Returns

    typedescription
    Color This color.

    convertGammaToLinear()

    Converts this color from gamma to linear color space in place.

    Returns

    typedescription
    Color This color.

    convertLinearToGamma()

    Converts this color from linear to gamma color space in place.

    Returns

    typedescription
    Color This color.

    getHex()

    Returns the hexadecimal value of this color.

    Returns

    typedescription
    number Hexadecimal color value.

    getHexString()

    Returns the hexadecimal value of this color as a 6-digit string (e.g. 'ff0000').

    Returns

    typedescription
    string Hexadecimal color string.

    getHSL(optionalTarget)

    Returns the hue, saturation and lightness of this color.

    Parameters

    optionalTarget
    Object
    Optional object to write the result into. A new object is created if omitted.

    Returns

    typedescription
    Object The hue, saturation and lightness, each in the range 0.0 to 1.0.

    getStyle()

    Returns this color as a CSS rgb(...) string.

    Returns

    typedescription
    string CSS color string, e.g. 'rgb(255,0,0)'.

    offsetHSL(h, s, l)

    Offsets this color’s hue, saturation and lightness by the given amounts.

    Parameters

    h*
    number
    Hue offset.
    s*
    number
    Saturation offset.
    l*
    number
    Lightness offset.
    * Required

    Returns

    typedescription
    Color This color.

    add(color)

    Adds the given color’s components to this color.

    Parameters

    color*Color to add.
    * Required

    Returns

    typedescription
    Color This color.

    addColors(color1, color2)

    Sets this color to the component-wise sum of two colors.

    Parameters

    color1*First color.
    color2*Second color.
    * Required

    Returns

    typedescription
    Color This color.

    addScalar(s)

    Adds a scalar value to each component of this color.

    Parameters

    s*
    number
    Scalar value to add.
    * Required

    Returns

    typedescription
    Color This color.

    multiply(color)

    Multiplies this color’s components by the given color’s components.

    Parameters

    color*Color to multiply by.
    * Required

    Returns

    typedescription
    Color This color.

    multiplyScalar(s)

    Multiplies each component of this color by a scalar value.

    Parameters

    s*
    number
    Scalar value to multiply by.
    * Required

    Returns

    typedescription
    Color This color.

    lerp(color, alpha)

    Linearly interpolates this color toward the given color.

    Parameters

    color*Color to interpolate toward.
    alpha*
    number
    Interpolation factor, in the range 0.0 to 1.0.
    * Required

    Returns

    typedescription
    Color This color.

    equals(c)

    Returns whether the given color equals this color.

    Parameters

    c*Color to compare against.
    * Required

    Returns

    typedescription
    boolean true if all components are equal.

    fromArray(array)

    Sets this color’s components from the first three elements of an array.

    Parameters

    array*
    Array.<number>
    Array of [r, g, b] values, each in the range 0.0 to 1.0.
    * Required

    Returns

    typedescription
    Color This color.

    toArray(array, offset)

    Writes this color’s components into an array as [r, g, b].

    Parameters

    array
    Array.<number>
    Array to write into. A new array is created if omitted.
    offset
    number
    Offset into the array.

    Returns

    typedescription
    Array.<number> The array.

    clone()

    Returns a new color with the same components as this color.

    Returns

    typedescription
    Color A new color.