Two.Texture

Extends: Two.Element

Fundamental to work with bitmap data, a.k.a. pregenerated imagery, in Two.js. Supported formats include jpg, png, gif, and tiff. See Two.Texture.RegularExpressions for a full list of supported formats.

Constructor

ArgumentDescription
srcThe URL path to an image file or an <img /> element.
callbackAn optional callback function once the image has been loaded.

Properties

A list of properties that are on every Two.Texture.

fromObject

Returns: Two.Texture

ArgumentDescription
objObject notation of a Two.Texture to create a new instance

Create a new Two.Texture from an object notation of a Two.Texture.

nota-bene

Works in conjunction with Two.Texture.toObject

RegularExpressions

A map of compatible DOM Elements categorized by media format.

ImageRegistry

A canonical listing of image data used in a single session of Two.js.

nota-bene

This object is used to cache image data between different textures.

getAbsoluteURL

Returns: String

  • The serialized absolute path.

Serializes a URL as an absolute path for canonical attribution in Two.Texture.ImageRegistry.

ArgumentDescription
path

loadHeadlessBuffer

Loads an image as a buffer in headless environments.

ArgumentDescription
textureThe Two.Texture to be loaded.
onLoadThe callback function to be triggered once the image is loaded.

nota-bene

  • This function uses node's fs.readFileSync to spoof the <img /> loading process in the browser.

getTag

Returns: String

  • Returns the tag name of an image, video, or canvas node.

Retrieves the tag name of an image, video, or canvas node.

ArgumentDescription
imageThe image to infer the tag name from.

getImage

Returns: HTMLImageElement

Convenience function to set Two.Texture.image properties with canonical versions set in Two.Texture.ImageRegistry.

ArgumentDescription
srcThe URL path of the image.

Register

A collection of functions to register different types of textures. Used internally by a Two.Texture.

load

ArgumentDescription
textureThe texture to load.
callbackThe function to be called once the texture is loaded.

FlagOffset

Cached method to let renderers know offset has been updated on a Two.Texture.

FlagScale

Cached method to let renderers know scale has been updated on a Two.Texture.

loaded

Shorthand value to determine if image has been loaded into the texture.

repeat

CSS style declaration to tile Two.Path. Valid values include: 'no-repeat', 'repeat', 'repeat-x', 'repeat-y'.

offset

A two-component vector describing any pixel offset of the texture when applied to a Two.Path.

src

The URL path to the image data.

nota-bene

This property is ultimately serialized in a Two.Registry to cache retrieval.

image

The corresponding DOM Element of the texture. Can be a <img />, <canvas />, or <video /> element. See Two.Texture.RegularExpressions for a full list of supported elements.

nota-bene

In headless environments this is a Canvas.Image object. See https://github.com/Automattic/node-canvas for more information on headless image objects.

clone

Returns: Two.Texture

Create a new instance of Two.Texture with the same properties of the current texture.

copy

ArgumentDescription
textureThe reference Two.Texture

Copy the properties of one Two.Texture onto another.

toObject

Returns: Object

Return a JSON compatible plain object that represents the texture.

dispose

Detach instance from renderer including any <defs /> or textures stored in memory.