Skip to content

@bloopjs/toodle


@bloopjs/toodle / textures/AssetManager / AssetManager

Class: AssetManager ​

Defined in: textures/AssetManager.ts:41

Constructors ​

Constructor ​

new AssetManager(backend, options): AssetManager

Defined in: textures/AssetManager.ts:49

Parameters ​

backend ​

IRenderBackend

options ​

AssetManagerOptions = {}

Returns ​

AssetManager

Properties ​

bundles ​

readonly bundles: Bundles

Defined in: textures/AssetManager.ts:42


extra ​

extra: object

Defined in: textures/AssetManager.ts:501

Advanced and niche features

getAtlasCoords() ​

getAtlasCoords: (id) => AtlasCoords[]

Get the atlas coordinates for a texture.

Parameters ​
id ​

string

The id of the texture to get the atlas coordinates for

Returns ​

AtlasCoords[]

An array of the atlas coordinates for the texture

getAtlasUsage() ​

getAtlasUsage: () => object

Get diagnostics on texture atlas usage

Returns ​

Usage stats for texture atlases

available ​

available: number

The number of texture atlases that are currently unused and available to load textures into.

total ​

total: number = totalLayers

The total number of texture atlases that can be loaded.

used ​

used: number

The number of texture atlases that are currently in use.

getLoadedBundleIds() ​

getLoadedBundleIds: () => string[]

Returns ​

string[]

getRegisteredBundleIds() ​

getRegisteredBundleIds: () => string[]

Returns ​

string[]

getTextureOffset() ​

getTextureOffset: (id) => Vec2

Get the texture default offset

Parameters ​
id ​

string

The id of the texture to get the atlas coordinates for

Returns ​

Vec2

Point of the texture's associated X,Y offset

loadAtlas() ​

loadAtlas: (atlas) => Promise<number>

Load a texture atlas from a CpuTextureAtlas.

Parameters ​
atlas ​

CpuTextureAtlas

The texture atlas to load

Returns ​

Promise<number>

The index of the atlas

nextAvailableAtlasIndex() ​

nextAvailableAtlasIndex: () => number

Consume the next available atlas index.

Returns ​

number

setAtlasCoords() ​

setAtlasCoords: (id, coords) => void

Set the atlas coordinates for a texture.

This should not be necessary for most use cases. This allows for UV precision

Parameters ​
id ​

string

The id of the texture to set the atlas coordinates for

coords ​

AtlasCoords

The atlas coordinates to set

Returns ​

void

unloadAtlas() ​

unloadAtlas: (atlasIndex) => Promise<void>

Unload an atlas from the texture atlas.

Parameters ​
atlasIndex ​

number

The index of the atlas to unload

Returns ​

Promise<void>

Accessors ​

atlasId ​

Get Signature ​

get atlasId(): string

Defined in: textures/AssetManager.ts:74

Get the atlas ID this asset manager uses.

Returns ​

string


atlasSize ​

Get Signature ​

get atlasSize(): Size

Defined in: textures/AssetManager.ts:89

Get the atlas dimensions

Returns ​

Size


textureAtlas ​

Get Signature ​

get textureAtlas(): GPUTexture

Defined in: textures/AssetManager.ts:82

Get the GPU texture atlas. For WebGPU, returns GPUTexture.

Deprecated ​

Access via backend.getTextureAtlas(atlasId).handle instead

Returns ​

GPUTexture


textureIds ​

Get Signature ​

get textureIds(): string[]

Defined in: textures/AssetManager.ts:154

A read-only array of all currently loaded texture ids.

Returns ​

string[]


textures ​

Get Signature ​

get textures(): ReadonlyMap<string, AtlasCoords[]>

Defined in: textures/AssetManager.ts:147

A read-only map of all currently loaded textures.

Returns ​

ReadonlyMap<string, AtlasCoords[]>

Methods ​

destroy() ​

destroy(): void

Defined in: textures/AssetManager.ts:652

Destroy the texture atlas. This should free up ~4gb of gpu memory (and make all draw calls fail)

Returns ​

void


getCroppedSize() ​

getCroppedSize(id): Size

Defined in: textures/AssetManager.ts:116

Dimensions of a loaded texture, cropped to a minimal bounding box.

Parameters ​

id ​

string

The id of the texture to get the size of

Returns ​

Size

The size of the texture


getFont() ​

getFont(id): ITextShader

Defined in: textures/AssetManager.ts:372

Parameters ​

id ​

string

Returns ​

ITextShader


getSize() ​

getSize(id): Size

Defined in: textures/AssetManager.ts:100

True dimensions of a loaded texture, prior to any transparent pixel cropping.

Parameters ​

id ​

string

The id of the texture to get the size of

Returns ​

Size

The size of the texture


isCropped() ​

isCropped(id): boolean

Defined in: textures/AssetManager.ts:134

Whether the texture has been cropped for extra transparency.

Parameters ​

id ​

string

The id of the texture to be checked

Returns ​

boolean

Whether the image has been cropped (i.e. if it has uvScaledCropped)


loadBundle() ​

loadBundle(bundleId): Promise<void>

Defined in: textures/AssetManager.ts:274

Load a bundle of textures to the gpu

See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html

Parameters ​

bundleId ​

string

Returns ​

Promise<void>


loadFont() ​

loadFont(id, url, fallbackCharacter): Promise<string>

Defined in: textures/AssetManager.ts:332

Load a font for text rendering (WebGPU) or measurement only (WebGL).

Parameters ​

id ​

string

The id of the font to load

url ​

URL

The url of the font JSON to load

fallbackCharacter ​

string = "_"

The character to use as a fallback if the font does not contain a character to be rendered

Returns ​

Promise<string>

Remarks ​

On WebGPU backend, loads the full font for rendering. On WebGL backend, loads the font for text measurement only. Attempting to render text on WebGL will throw an error.


loadTexture() ​

loadTexture(id, url, options?): Promise<{ coords: AtlasCoords; id: string; }>

Defined in: textures/AssetManager.ts:193

Debug method to load a single texture.

Parameters ​

id ​

string

ID used to name the texture

url ​

URL or ImageBitmap target for the image

URL | ImageBitmap

options? ​

Partial<TextureBundleOpts>

LoadingOptions used to modify the loading process

Note: this will consume one texture atlas per texture. For more efficient loading of multiple textures, consider loadBundle

Returns ​

Promise<{ coords: AtlasCoords; id: string; }>

Throws ​

Error if using WebGL backend (use registerBundle instead)


loadTextures() ​

loadTextures(opts): Promise<void>

Defined in: textures/AssetManager.ts:175

Debug method to load a set of textures from a record of URLS.

Parameters ​

opts ​

Record<string, URL>

Returns ​

Promise<void>

Example ​

ts
await toodle.assets.loadTextures({
  "myImage": new URL("assets/image.png", "https://mywebsite.com"),
});

Deprecated ​

use registerBundle instead. or loadTexture for debugging


registerBundle() ​

registerBundle(bundleId, opts): Promise<string>

Defined in: textures/AssetManager.ts:252

Register a bundle of textures.

Parameters ​

bundleId ​

string

ID used to name the bundle

opts ​

TextureBundleOpts | AtlasBundleOpts

Returns ​

Promise<string>


unloadBundle() ​

unloadBundle(bundleId): Promise<void>

Defined in: textures/AssetManager.ts:302

Unload a bundle of textures from the gpu - this marks the gpu-side texture atlas as available for future texture loading.

Parameters ​

bundleId ​

string

The id of the bundle to unload

Returns ​

Promise<void>


validateTextureReference() ​

validateTextureReference(node): void

Defined in: textures/AssetManager.ts:381

Parameters ​

node ​

SceneNode | QuadNode

Returns ​

void