Skip to content

Kiln API / kiln / AssetStore

Class: AssetStore ​

Loads and caches assets by path. res.get(Assets).load('models/ship.glb') returns a handle at once; loading happens in the background (tracked by app.idle()). Paths are relative to the game's public/ folder.

Constructors ​

Constructor ​

ts
new AssetStore(app, options): AssetStore;

Parameters ​

ParameterType
appApp
optionsAssetOptions

Returns ​

AssetStore

Accessors ​

pending ​

Get Signature ​

ts
get pending(): number;

Number of assets still loading.

Returns ​

number

Methods ​

load() ​

ts
load<T>(path, kind?): AssetHandle<T>;

Starts loading (once per path) and returns the handle.

Type Parameters ​

Type ParameterDefault type
Tunknown

Parameters ​

ParameterType
pathstring
kindAssetKind

Returns ​

AssetHandle<T>


gltf() ​

ts
gltf(path): AssetHandle<GLTF>;

Parameters ​

ParameterType
pathstring

Returns ​

AssetHandle<GLTF>


texture() ​

ts
texture(path): AssetHandle<Texture<unknown, TextureEventMap>>;

Parameters ​

ParameterType
pathstring

Returns ​

AssetHandle<Texture<unknown, TextureEventMap>>


json() ​

ts
json<T>(path): AssetHandle<T>;

Type Parameters ​

Type ParameterDefault type
Tunknown

Parameters ​

ParameterType
pathstring

Returns ​

AssetHandle<T>


release() ​

ts
release(path): Promise<boolean>;

Replays: finishes a held load (waiting for it if needed). False if the game never requested it.

Parameters ​

ParameterType
pathstring

Returns ​

Promise<boolean>


get() ​

ts
get<T>(path): AssetHandle<T> | undefined;

The handle for a path if it was requested.

Type Parameters ​

Type ParameterDefault type
Tunknown

Parameters ​

ParameterType
pathstring

Returns ​

AssetHandle<T> | undefined


instantiate() ​

ts
instantiate(handle): Object3D<Object3DEventMap> | null;

A new instance of a loaded model's scene. Geometry and materials are shared with the cache.

Parameters ​

ParameterType
handleAssetHandle<GLTF>

Returns ​

Object3D<Object3DEventMap> | null


dispose() ​

ts
dispose(): void;

Frees GPU resources for everything loaded. Called when the app is disposed.

Returns ​

void