ProceduralTextureProvider
Lens Studio v3.0+
Inherits from TextureProvider
Description
Provides a texture that can be written to or read from. Can be accessed using Texture.control on a Procedural Texture.
Methods
getPixels(Number x, Number y, Number width, Number height, Uint8Array data)
: void
Returns a Uint8 array containing the pixel values in a region of the texture. The region starts at the pixel coordinates x, y, and extends rightward by width and upward by height. Values returned are integers ranging from 0 to 255.
setPixels(Number x, Number y, Number width, Number height, Uint8Array data)
: void
Sets a region of pixels on the texture. The region starts at the pixel coordinates x, y, and extends rightward by width and upward by height. Uses the values of the passed in Uint8Array data, which should be integer values ranging from 0 to 255.
static create(Number width, Number height, Colorspace colorspace)
: Texture
Creates a new, blank Texture Provider using the passed in dimensions and Colorspace. The ProceduralTextureProvider can be accessed through the control property on the returned texture.
static createFromTexture(Texture texture)
: Texture
Creates a new Procedural Texture based on the passed in texture. The ProceduralTextureProvider can be accessed through the control property on the returned texture.
Inherited Methods
getAspect()
: Number
Returns the texture’s aspect ratio, which is calculated as width / height.
getHeight()
: Number
Returns the height of the texture in pixels.
getWidth()
: Number
Returns the width of the texture in pixels.
getTypeName()
: String
Returns the name of this object’s type.
isOfType(String type)
: Boolean
Returns true if the object matches or derives from the passed in type.
Examples
// @input Component.Image image
var width = 64;
var height = 64;
var channels = 4; // RGBA
var newTex = ProceduralTextureProvider.create(width, height, Colorspace.RGBA);
var newData = new Uint8Array(width * height * channels);
for (var y=0; y<height; y++) {
for (var x=0; x<width; x++) {
// Calculate index
var index = (y * width + x) * channels;
// Set R, G, B, A
newData[index] = (x / (width-1)) * 255;
newData[index+1] = (y / (height-1)) * 255;
newData[index+2] = 0;
newData[index+3] = 255;
}
}
newTex.control.setPixels(0, 0, width, height, newData);
script.image.mainPass.baseTex = newTex;
Still Looking for help?
Visit Support