Skip to main content

Texture

A texture object, either generated by the model or created with the TextureAPI

warning

This page is a WIP. It contains all the information in Figura's documentation but we're working on adding more helpful descriptions.

For this page assume:

local myTex = textures["myTexture"]

getDimensions()

Returns a vector of this texture width and height

getDimensions()

Returns:

TypeDescription
Vector2-

Example:

myText:getDimensions()

getName()

Returns this texture name

getName()

Returns:

TypeDescription
String-

Example:

myText:getName()

getPath()

Returns this texture resource path location

getPath()

Returns:

TypeDescription
String-

Example:

myText:getPath()

setPixel()

Aliases: pixel()

Sets the RGBA color of the specified pixel

setPixel(x, y, rgb)

Parameters:

NameTypeDescriptionDefault
xInteger--
yInteger--
rgbVector3--

Returns:

TypeDescription
TextureReturns self for chaining

Example:

myText:setPixel(32, 32, 0, 0, 1, 1)

getPixel()

Gets the RGBA color from the specified pixel

getPixel(x, y)

Parameters:

NameTypeDescriptionDefault
xInteger--
yInteger--

Returns:

TypeDescription
Vector4-

Example:

myText:getPixel(32, 32)

applyFunc()

Calls the given function on the specified area of this texture, it will iterate over each pixel, giving its current x, y, and color as arguments, the color is a vec4 in RGBA format, and the return value will set that pixel's color

Invalid return values or nil takes no effects

applyFunc(x, y, width, height, func)

Parameters:

NameTypeDescriptionDefault
xInteger--
yInteger--
widthInteger--
heightInteger--
funcFunction--

Returns:

TypeDescription
TextureReturns self for chaining

Example:

-- multiplying each pixel in the texture by a color to tint it
local dimensions = myTex:getDimensions()
local tint = vec(140 / 255, 254 / 255, 254 / 255, 255 / 255)

-- create a function that accepts the color of the pixel, and its x, y position
function tintFunc(color, x, y)
-- multiply the color of the pixel by our tint
return color:mul(tint)
end

-- call the function on each pixel with applyFunc
myTex:applyFunc(0, 0, dimensions.x, dimensions.y, tintFunc)

applyMatrix()

Transforms all pixels in the specified area of this texture by the matrix

If clip is true, the resulting colour channels will be clamped between 0 and 1

applyMatrix(x, y, width, height, matrix, clip)

Parameters:

NameTypeDescriptionDefault
xInteger--
yInteger--
widthInteger--
heightInteger--
matrixMatrix4--
clipBoolean--

Returns:

TypeDescription
TextureReturns self for chaining

Example:

-- multiplying each pixel in the texture by a color to tint it
local color = vec(140 / 255, 254 / 255, 254 / 255)
local dimensions = myTex:getDimensions()
myTex:applyMatrix(0, 0, dimensions.x, dimensions.y, matrices.mat4():scale(color))

fill()

Sets the RGBA color of the entire specified region

fill(x, y, width, height, rgb)

Parameters:

NameTypeDescriptionDefault
xInteger--
yInteger--
widthInteger--
heightInteger--
rgbVector3--

Returns:

TypeDescription
TextureReturns self for chaining

Example:

myText:fill(0, 0, 32, 32, 0, 0, 1, 1)

restore()

Restores the texture to its original state, before any modifications

restore()

Returns:

TypeDescription
TextureReturns self for chaining

Example:

myText:restore()

save()

Returns a base64 string representation of this texture

save()

Returns:

TypeDescription
String-

Example:

myText:save()

update()

Updates the texture to the GPU, applying all the changes

update()

Returns:

TypeDescription
TextureReturns self for chaining

Example:

myText:update()