Skip to content

rgb

Standard three-channel color type containing r, g, and b floating-point values.

Initialize a color with specific values or from a hex string.

-- default black (0, 0, 0)
local c1 = rgb()
-- custom color (Red, Green, Blue)
local yellow = rgb(1, 1, 0)
-- create from a hex string
local c2 = rgb("#00FF88")

The rgb primitive represents colors using the additive color model. Each component is a floating-point number, typically ranging from 0.0 to 1.0.

The type supports standard mathematical operations, allowing colors to be added or multiplied directly (for example, combining red and green to produce yellow). The :normalize() method ensures the brightest channel does not exceed 1.0, scaling the color back into range after arithmetic operations.

Like other color and vector primitives, rgb is FFI-backed and optimized for performance. For tight loops or per-frame logic, using in-place methods such as :add() is more efficient than allocating new values with operators.

PropertyTypeDescription
rnumberRed channel (0–1).
gnumberGreen channel (0–1).
bnumberBlue channel (0–1).
MethodDescription
:rgbm(mult)Converts the rgb color into an rgbm type with a set multiplier.
:hsv(out)Returns a hsv representation of the color.
:hex()Returns a hex string (e.g., #RRGGBB).
:luminance()Returns the perceived brightness of the color.
:set(r, g, b)Updates the color values in place.
:unpack()Returns r, g, and b as three separate numbers.

Using rgb to set a basic material property in the scene.

local meshes = ac.findMeshes("GEO_CAR_BODY")
local paintColor = rgb(0.1, 0.1, 0.8) -- deep blue
-- many material properties expect a 3-channel rgb
meshes:setMaterialProperty("ksDiffuse", paintColor)