Documentation / scene / AssetManager
Class: AssetManager
Defined in: libs/scene/src/asset/assetmanager.ts:210
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:279
Creates an instance of AssetManager
Parameters
resourceManager?
Returns
AssetManager
Accessors
vfs
Get Signature
get vfs():
VFS
Defined in: libs/scene/src/asset/assetmanager.ts:297
VFS used to read resources (files, URLs, virtual mounts).
Returns
VFS
Methods
clearCache()
clearCache():
void
Defined in: libs/scene/src/asset/assetmanager.ts:308
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
invalidateAsset()
invalidateAsset(
path,recursive?):number
Defined in: libs/scene/src/asset/assetmanager.ts:336
Evicts cached data loaded from a VFS path.
Existing scene objects keep their current resources. Subsequent loads read the asset again.
Parameters
path
string
Changed VFS file or directory path.
recursive?
boolean = false
Whether entries below a directory path should also be evicted.
Returns
number
Number of cache entries removed.
releaseFontAsset()
releaseFontAsset(
url):boolean
Defined in: libs/scene/src/asset/assetmanager.ts:466
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.
invalidateMaterial()
invalidateMaterial(
url):boolean
Defined in: libs/scene/src/asset/assetmanager.ts:475
Remove one material entry from cache.
Parameters
url
string
Material asset path.
Returns
boolean
true if an entry existed and was removed.
addTextureLoader()
staticaddTextureLoader(loader):void
Defined in: libs/scene/src/asset/assetmanager.ts:485
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:493
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:510
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:536
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:562
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?
Optional fetch 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:588
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:613
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:617
Parameters
url
string
options?
Returns
Promise<Record<string, MaterialBlueprintIR>>
fetchMaterial()
fetchMaterial<
T>(url,options?):Promise<T>
Defined in: libs/scene/src/asset/assetmanager.ts:634
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:660
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:693
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:862
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:924
Parameters
filter?
(m) => boolean
Returns
Promise<void>
createBluePrintDAG()
createBluePrintDAG(
nodeMap,roots,links):object
Defined in: libs/scene/src/asset/assetmanager.ts:1333
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:1354
Parameters
path
string
Returns
void
loadBluePrint()
loadBluePrint(
path,vfs?):Promise<Record<string,MaterialBlueprintIR>>
Defined in: libs/scene/src/asset/assetmanager.ts:1357
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:1410
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:1579
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:1607
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:1650
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>