Texture
A texture object, either generated by the model or created with the TextureAPI
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:
Type | Description |
---|---|
Vector2 | - |
Example:
myText:getDimensions()
getName()
Returns this texture name
getName()
Returns:
Type | Description |
---|---|
String | - |
Example:
myText:getName()
getPath()
Returns this texture resource path location
getPath()
Returns:
Type | Description |
---|---|
String | - |
Example:
myText:getPath()
setPixel()
Aliases: pixel()
Sets the RGBA color of the specified pixel
- Overload 1
- Overload 2
- Overload 3
Example:
myText:setPixel(32, 32, 0, 0, 1, 1)
getPixel()
Gets the RGBA color from the specified pixel
getPixel(x, y)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Integer | - | - |
y | Integer | - | - |
Returns:
Type | Description |
---|---|
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:
Name | Type | Description | Default |
---|---|---|---|
x | Integer | - | - |
y | Integer | - | - |
width | Integer | - | - |
height | Integer | - | - |
func | Function | - | - |
Returns:
Type | Description |
---|---|
Texture | Returns 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:
Name | Type | Description | Default |
---|---|---|---|
x | Integer | - | - |
y | Integer | - | - |
width | Integer | - | - |
height | Integer | - | - |
matrix | Matrix4 | - | - |
clip | Boolean | - | - |
Returns:
Type | Description |
---|---|
Texture | Returns 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
- Overload 1
- Overload 2
- Overload 3
fill(x, y, width, height, rgb)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Integer | - | - |
y | Integer | - | - |
width | Integer | - | - |
height | Integer | - | - |
rgb | Vector3 | - | - |
Returns:
Type | Description |
---|---|
Texture | Returns 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:
Type | Description |
---|---|
Texture | Returns self for chaining |
Example:
myText:restore()
save()
Returns a base64 string representation of this texture
save()
Returns:
Type | Description |
---|---|
String | - |
Example:
myText:save()
update()
Updates the texture to the GPU, applying all the changes
update()
Returns:
Type | Description |
---|---|
Texture | Returns self for chaining |
Example:
myText:update()