TextureAtlas

Texture atlas stores images in one texture. Each image has its own atlas texture coordinates.

Constructor

new TextureAtlas(widthopt, heightopt)

Parameters:
NameTypeAttributesDefaultDescription
widthnumber<optional>
1024

Texture atlas width, if it hasn't 1024 default.

heightnumber<optional>
1024

Texture atlas height, if it hasn't 1024 default.

Methods

(protected) _makeAtlas(fastInsertopt)

Main atlas making function.

Parameters:
NameTypeAttributesDefaultDescription
fastInsertboolean<optional>
false

If it's true atlas doesn't restore all images again and store image in the current atlas scheme.

addImage(image, fastInsertopt) → {TextureAtlasNode|undefined}

Adds image to the atlas and returns created node with texture coordinates of the stored image.

Parameters:
NameTypeAttributesDefaultDescription
imageHTMLImageElementExt

Input javascript image object.

fastInsertboolean<optional>
false

If it's true atlas doesn't restore all images again and store image in the current atlas scheme.

Returns:
Type: 
TextureAtlasNode | undefined

assignHandler(handler)

Sets openglobus gl handler that creates gl texture.

Parameters:
NameTypeDescription
handlerHandler

WebGL handler.

clearCanvas()

Clear atlas with black.

createTexture()

Creates atlas gl texture.

getCanvas() → {HTMLCanvasElement}

Returns canvas object.

Returns:
Type: 
HTMLCanvasElement

getDiagonal(image) → {number}

Returns image diagonal size.

Parameters:
NameTypeDescription
imageHTMLImageElementExt

Image object.

Returns:
Type: 
number

getImage() → {HTMLImageElement}

Returns atlas javascript image object.

Returns:
Type: 
HTMLImageElement

loadImage(src, success)

Asynchronous function that loads and creates image to the image cache, and call success callback when it's done.

Parameters:
NameTypeDescription
srcstring

Image object src string.

successImagesCacheManagerCallback

The callback that handles the image loads done.

TextureAtlas

new TextureAtlas(rect, texCoords)

Atlas binary tree node.

Parameters:
NameTypeDescription
rectRectangle

Node image rectangle.

texCoordsArray.<number>

Node image rectangle.

Methods

(protected) _makeAtlas(fastInsertopt)

Main atlas making function.

Parameters:
NameTypeAttributesDefaultDescription
fastInsertboolean<optional>
false

If it's true atlas doesn't restore all images again and store image in the current atlas scheme.

addImage(image, fastInsertopt) → {TextureAtlasNode|undefined}

Adds image to the atlas and returns created node with texture coordinates of the stored image.

Parameters:
NameTypeAttributesDefaultDescription
imageHTMLImageElementExt

Input javascript image object.

fastInsertboolean<optional>
false

If it's true atlas doesn't restore all images again and store image in the current atlas scheme.

Returns:
Type: 
TextureAtlasNode | undefined

assignHandler(handler)

Sets openglobus gl handler that creates gl texture.

Parameters:
NameTypeDescription
handlerHandler

WebGL handler.

clearCanvas()

Clear atlas with black.

createTexture()

Creates atlas gl texture.

getCanvas() → {HTMLCanvasElement}

Returns canvas object.

Returns:
Type: 
HTMLCanvasElement

getDiagonal(image) → {number}

Returns image diagonal size.

Parameters:
NameTypeDescription
imageHTMLImageElementExt

Image object.

Returns:
Type: 
number

getImage() → {HTMLImageElement}

Returns atlas javascript image object.

Returns:
Type: 
HTMLImageElement

loadImage(src, success)

Asynchronous function that loads and creates image to the image cache, and call success callback when it's done.

Parameters:
NameTypeDescription
srcstring

Image object src string.

successImagesCacheManagerCallback

The callback that handles the image loads done.