Documentation / scene / AssetManager
Class: AssetManager
Defined in: libs/scene/src/asset/assetmanager.ts:192
Centralized asset manager for loading and caching resources.
Responsibilities:
- Abstracts resource loading via VFS (text/json/binary).
- Dispatches texture/model loading to registered loaders by MIME type.
- Caches results and uses weak references to allow GPU resources to be GC'd when unused.
- Harmonizes cross-backend constraints (e.g., WebGL non-power-of-two rules and sRGB handling).
- Provides access to built-in textures with device-restore handlers.
Threading/async model:
- All I/O is async; repeated calls are coalesced via internal promise caches keyed by URL or hash.
Constructors
Constructor
new AssetManager(
resourceManager?):AssetManager
Defined in: libs/scene/src/asset/assetmanager.ts:257
Creates an instance of AssetManager
Parameters
resourceManager?
Returns
AssetManager
Accessors
vfs
Get Signature
get vfs():
VFS
Defined in: libs/scene/src/asset/assetmanager.ts:273
VFS used to read resources (files, URLs, virtual mounts).
Returns
VFS
Methods
clearCache()
clearCache():
void
Defined in: libs/scene/src/asset/assetmanager.ts:284
Clear cached references and promises.
- Disposes any DWeakRef holders maintained by this manager.
- Empties internal maps for textures, models, and raw data (text/json/binary).
- Does not forcibly dispose GPU resources; it only clears references so they can be GC'd if no other owners are holding them.
Returns
void
releaseFontAsset()
releaseFontAsset(
url):boolean
Defined in: libs/scene/src/asset/assetmanager.ts:333
Removes a cached font asset entry by URL.
This only evicts the cache entry. It does not dispose any external references to the FontAsset.
Parameters
url
string
Resource URL or VFS path.
Returns
boolean
true if a cache entry existed and was removed.
addTextureLoader()
staticaddTextureLoader(loader):void
Defined in: libs/scene/src/asset/assetmanager.ts:347
Register a texture loader (highest priority first).
Note: This is a static registry shared by all AssetManager instances.
Parameters
loader
AbstractTextureLoader
A concrete texture loader implementation.
Returns
void
setModelLoader()
setModelLoader(
mimeType,loader):void
Defined in: libs/scene/src/asset/assetmanager.ts:355
Register a model loader (highest priority first).
Parameters
mimeType
string
loader
Returns
void
fetchTextData()
fetchTextData(
url,postProcess?,httpRequest?,options?):Promise<string>
Defined in: libs/scene/src/asset/assetmanager.ts:372
Fetch a UTF-8 text resource via VFS.
- Results are cached per resolved URL (via HttpRequest.urlResolver if provided; otherwise the raw URL).
- If cached, any provided postProcess is ignored for subsequent calls; create a separate AssetManager if you need different post-processing of the same URL.
Parameters
url
string
Resource URL or VFS path.
postProcess?
(text) => string
Optional transformation applied to the loaded text.
httpRequest?
HttpRequest
Optional HttpRequest for custom URL resolution/headers.
options?
Returns
Promise<string>
A promise that resolves to the loaded (and optionally processed) text.
fetchJsonData()
fetchJsonData<
T>(url,postProcess?,httpRequest?,options?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:397
Fetch a JSON resource via VFS.
- Parses as JSON after text load.
- Cached per resolved URL. Post-process is applied only on the first load for a given cache key.
Type Parameters
T
T = any
Parameters
url
string
Resource URL or VFS path.
postProcess?
(json) => T
Optional transformation applied to the parsed JSON object.
httpRequest?
HttpRequest
Optional HttpRequest for custom URL resolution/headers.
options?
Returns
Promise<T>
A promise that resolves to the loaded (and optionally processed) JSON value.
fetchBinaryData()
fetchBinaryData(
url,postProcess?,httpRequest?,options?):Promise<ArrayBuffer>
Defined in: libs/scene/src/asset/assetmanager.ts:421
Fetch a binary resource via VFS.
- Cached per resolved URL. Post-process is applied only on first load for a given key.
Parameters
url
string
Resource URL or VFS path.
postProcess?
(data) => ArrayBuffer
Optional transformation applied to the loaded ArrayBuffer.
httpRequest?
HttpRequest
Optional HttpRequest for custom URL resolution/headers.
options?
Returns
Promise<ArrayBuffer>
A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
fetchFontAsset()
fetchFontAsset(
url,options?):Promise<FontAsset>
Defined in: libs/scene/src/asset/assetmanager.ts:446
Fetch a font asset via VFS.
- Cached per URL only.
optionsare applied only when the font is first loaded for that URL.- If the URL is already cached, later calls ignore
optionsand reuse the cached FontAsset.
Parameters
url
string
Resource URL or VFS path.
options?
Optional MSDF atlas settings bound to the loaded FontAsset.
Returns
Promise<FontAsset>
A promise that resolves to the loaded (and optionally processed) font asset.
getFontAsset()
getFontAsset(
url):FontAsset
Defined in: libs/scene/src/asset/assetmanager.ts:470
Fetch a font asset via VFS if already cached.
Parameters
url
string
Resource URL or VFS path.
Returns
The cached FontAsset if it exists and is loaded, or null if not cached or still loading.
fetchBluePrint()
fetchBluePrint(
url,options?):Promise<Record<string,MaterialBlueprintIR>>
Defined in: libs/scene/src/asset/assetmanager.ts:474
Parameters
url
string
options?
Returns
Promise<Record<string, MaterialBlueprintIR>>
fetchMaterial()
fetchMaterial<
T>(url,options?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:490
Fetch a material resource.
Type Parameters
T
Expected concrete material type.
Parameters
url
string
Resource URL or VFS path.
options?
Returns
Promise<T>
A promise that resolves to the loaded material.
fetchPrimitive()
fetchPrimitive<
T>(url,options?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:515
Fetch a primitive resource.
Type Parameters
T
T extends Primitive = Primitive
Expected concrete primitive type.
Parameters
url
string
Resource URL or VFS path.
options?
Returns
Promise<T>
A promise that resolves to the loaded primitive.
fetchTexture()
fetchTexture<
T>(url,options?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:547
Fetch a texture resource via registered loaders.
- Chooses loader by explicit MIME type or by VFS file extension inference.
- Deduplicates in-flight requests and caches ready textures.
- If
options.textureis provided, the asset will be uploaded/blitted into that texture. - On WebGL backends, enforces constraints by repacking non-power-of-two or sRGB textures.
Type Parameters
T
T extends BaseTexture<unknown>
Expected concrete texture type.
Parameters
url
string
Resource URL or VFS path.
options?
Texture fetching options (color space, sampler, target texture).
Returns
Promise<T>
A promise that resolves to the loaded texture.
loadPrimitive()
loadPrimitive<
T>(url,vfs?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:710
Type Parameters
T
T extends Primitive = Primitive
Parameters
url
string
vfs?
VFS
Returns
Promise<T>
reloadBluePrintMaterials()
reloadBluePrintMaterials(
filter?):Promise<void>
Defined in: libs/scene/src/asset/assetmanager.ts:772
Parameters
filter?
(m) => boolean
Returns
Promise<void>
createBluePrintDAG()
createBluePrintDAG(
nodeMap,roots,links):object
Defined in: libs/scene/src/asset/assetmanager.ts:1043
Parameters
nodeMap
Record<number, IGraphNode>
roots
number[]
links
object[]
Returns
object
graph
graph:
GraphStructure=gs
nodeMap
nodeMap:
Record<number,IGraphNode>
roots
roots:
number[]
order
order:
number[]
invalidateBluePrint()
invalidateBluePrint(
path):void
Defined in: libs/scene/src/asset/assetmanager.ts:1064
Parameters
path
string
Returns
void
loadBluePrint()
loadBluePrint(
path,vfs?):Promise<Record<string,MaterialBlueprintIR>>
Defined in: libs/scene/src/asset/assetmanager.ts:1067
Parameters
path
string
vfs?
VFS
Returns
Promise<Record<string, MaterialBlueprintIR>>
loadTextureFromBuffer()
loadTextureFromBuffer<
T>(arrayBuffer,mimeType,srgb?,samplerOptions?,texture?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:1115
Load a texture directly from an ArrayBuffer or typed array.
- Chooses an appropriate loader based on the provided MIME type.
- Can upload into an existing texture if
textureis specified.
Type Parameters
T
T extends BaseTexture<unknown>
Expected concrete texture type.
Parameters
arrayBuffer
ArrayBuffer | TypedArray
Raw texture data buffer.
mimeType
string
MIME type of the texture (must be supported by a registered loader).
srgb?
boolean
If true, treat image as sRGB; otherwise linear.
samplerOptions?
SamplerOptions
Optional sampler options passed to the loader path.
texture?
BaseTexture
Optional destination texture to populate.
Returns
Promise<T>
A promise that resolves to the created or populated texture.
fetchBuiltinTexture()
fetchBuiltinTexture<
T>(name,texture?):T
Defined in: libs/scene/src/asset/assetmanager.ts:1284
Fetch a built-in texture synchronously by name.
- If this built-in was not created yet, the registered loader is invoked.
- Registers a device restore handler so the texture can be re-initialized after device loss.
- If an existing texture is provided, the loader uploads into it.
Type Parameters
T
T extends BaseTexture<unknown>
Expected concrete texture type.
Parameters
name
string
Built-in texture identifier.
texture?
T
Optional destination texture to populate.
Returns
T
The built-in texture (created or populated).
setBuiltinTextureLoader()
staticsetBuiltinTextureLoader(name,loader):void
Defined in: libs/scene/src/asset/assetmanager.ts:1312
Override or unregister the loader for a named built-in texture.
- Passing a valid loader function sets/overrides the creation path.
- Passing
undefinedremoves the loader mapping for the given name.
Parameters
name
string
Built-in texture identifier.
loader
(assetManager) => BaseTexture
Factory that creates the built-in texture using the provided AssetManager.
Returns
void
writeFileToVFSs()
writeFileToVFSs(
path,data,options,vfs?):Promise<void>
Defined in: libs/scene/src/asset/assetmanager.ts:1355
Write file to a VFS
Parameters
path
string
File path
data
string | ArrayBuffer
Data to write
options
WriteOptions
Write options
vfs?
VFS
VFS to write to
Returns
Promise<void>