Skip to content

FxMeshLayerTexture ​

This module contains functions for modifing the texture of MeshLayer nodes.

INFO

Source textures and pixels define the data on which the functions of this module operate.

A source node is any MeshLayer node identified by the given NodeID.

A source texture is the texture of a source node. Every MeshLayer node has exactly one texture.

The source pixels are all pixels of the source texture, unless the NodeID wildcard /o is used and the active node is a MeshLayer whose texture has selected pixels. In this case, only the selected pixels are the source pixels.

Load ​

lua
FxMeshLayerTexture = require "FxMeshLayerTexture";

Functions ​

FunctionDescription
BrightnessContrast (NodeID, Brightness, Contrast)Adjusts brightness and contrast of the texture.
Clear (NodeID)Deletes all pixels.
ColorOverlay (NodeID, Color, Opacity)Blends pixels with another color.
Desaturate (NodeID)Desaturates pixels.
Export (NodeID, Filename)Exports the texture as an image file.
Fill (NodeID, Pixel)Sets all solid pixels.
FillColor (NodeID, Color)Sets the color of pixels.
FillMaterial (NodeID, Material)Sets the material of pixels.
Flip (NodeID, Horizontally)Flips the texture.
HueSaturation (NodeID, Hue, Saturation, Lightness)Adjusts hue, saturation and lightness of the texture.
Import (NodeID, Filename)Imports image files into textures.
InvertColors (NodeID)Inverts colors of the texture.
ReduceColors (NodeID, ColorCount)Reduces the number of distinct colors used in the texture.
ReplaceColor (NodeID, Color, ReplacementColor)Replaces colors of pixels.
ReplaceMaterial (NodeID, Material, ReplacementMaterial)Replaces materials of pixels.
Resize (NodeID, X, Y)Resizes the texture.

BrightnessContrast (NodeID, Brightness, Contrast) ​

This function roughly adjusts the brightness and contrast of a texture. For each source pixel, the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel. The brightness and contrast values range from 0.0 to 1.0.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • Brightness: The brightness shift, clamped to [-1.0, 1.0]
  • Contrast: The contrast shift, clamped to [-1.0, 1.0]

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
-- shift brightness by 0.5
FxMeshLayerTexture.BrightnessContrast("layer1", 0.5, 0);

Clear (NodeID) ​

This function deletes all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.Clear("layer1");

ColorOverlay (NodeID, Color, Opacity) ​

This function roughly blends the source texture with a color and opacity. For each source pixel, the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
color = FxColor.CreateFromHex("ff00ff");
FxMeshLayerTexture.ColorOverlay("layer1", color, 0.5);

Desaturate (NodeID) ​

This function roughly reduces the saturation of the source texture to 0.0. For each source pixel, the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.Desaturate("layer1");

Export (NodeID, Filename) ​

This function exports the source texture as an image file.

Parameters ​

  • NodeID: The NodeID to identify a single source node
  • Filename: absolute filename to save file as

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_FILE_OPERATION_FAILED

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.Export("layer1", "c:\image.png");

Fill (NodeID, Pixel) ​

This function replaces all solid source pixels with the given pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID

Since ​

Version 1.0

Example ​

lua
pixel = FxPixel.Create(0, 0);
FxMeshLayerTexture.Fill("layer1", pixel);

FillColor (NodeID, Color) ​

This function assigns the given color to all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.FillColor("layer1", 10);

FillMaterial (NodeID, Material) ​

This function applies the given material to all source pixels.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.FillMaterial("layer1", 1);

Flip (NodeID, Horizontally) ​

This function flips the source pixels inside the source pixel box.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
-- flip vertically
FxMeshLayerTexture.Flip("layer1", false);

HueSaturation (NodeID, Hue, Saturation, Lightness) ​

This function roughly adjusts the hue, saturation, and lightness of the source texture. For each source pixel, the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel. The hue, saturation, and lightness values range from 0.0 to 1.0.

Parameters ​

  • NodeID: The NodeID to identify the source nodes
  • Hue: The hue shift, clamped to [-1.0, 1.0]
  • Saturation: The saturation shift, clamped to [-1.0, 1.0]
  • Lightness: The lightness shift, clamped to [-1.0, 1.0]

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.HueSaturation("layer1", -0.2, -0.5, 0);

Import (NodeID, Filename) ​

This function imports an image file into the source texture.

Parameters ​

  • NodeID: The NodeID to identify a single source node
  • Filename: The absolute filename of the image file to import

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_FILE_OPERATION_FAILED

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.Import("layer1", "c:\image.png");

InvertColors (NodeID) ​

This function roughly inverts the colors of the source texture. For each source pixel the adjusted color is calculated, then the index color that best matches the calculated color is determined and assigned to the pixel.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.InvertColors("layer1");

ReduceColors (NodeID, ColorCount) ​

This function reduces the number of colors used in the specified source pixels.

Parameters ​

  • NodeID: The NodeID that identifies the source nodes.
  • ColorCount: The target number of colors to be used by the source pixels.

Errors ​

Possible errors include: FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_VALUE_INVALID.

Since ​

Version 1.0

Example ​

lua
FxVoxelLayer.ReduceColors("layer1", 0, 10);

ReplaceColor (NodeID, Color, ReplacementColor) ​

This function assigns the specified new ReplacementColor to all source pixels that have Color assigned.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.ReplaceColor("layer1", 0, 1);

ReplaceMaterial (NodeID, Material, ReplacementMaterial) ​

This function assigns the specified new material to all source pixels that have Material assigned.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND, FX_ITEM_INDEX_INVALID

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.ReplaceMaterial("layer1", 0, 1);

Resize (NodeID, X, Y) ​

This function resizes the source texture and resamples its contents.

Parameters ​

Errors ​

Possible errors include FX_REQUIRED_ASSET_UNAVAILABLE, FX_NODE_NOT_FOUND

Since ​

Version 1.0

Example ​

lua
FxMeshLayerTexture.Resize("layer1", 128, 128);