rgb
Standard three-channel color type containing r, g, and b floating-point values.
Usage Patterns
Section titled “Usage Patterns”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 stringlocal c2 = rgb("#00FF88")Convert to rgbm to add an alpha/intensity channel.
local base = rgb(1, 0, 0)local forUI = base:rgbm(0.5) -- mult=0.5 (50% opacity)Description
Section titled “Description”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.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
r | number | Red channel (0–1). |
g | number | Green channel (0–1). |
b | number | Blue channel (0–1). |
Common Methods
Section titled “Common Methods”| Method | Description |
|---|---|
: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. |
Examples
Section titled “Examples”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 rgbmeshes:setMaterialProperty("ksDiffuse", paintColor)Checking if a color is “bright” or “dark” to determine the best text color to use over it.
local myColor = rgb(0.2, 0.2, 0.2)
if myColor:luminance() < 0.5 then ui.textColored("Dark background, using white text", rgbm.colors.white)else ui.textColored("Light background, using black text", rgbm.colors.black)end