Documentation / scene / ResourceManager
Class: ResourceManager
Defined in: libs/scene/src/utility/serialization/manager.ts:271
Manages serialization and deserialization of engine objects to/from JSON, including asset resolution via a virtual file system (VFS) and asset manager.
Remarks
- Keeps a registry of serializable classes and their properties.
- Converts object graphs to JSON using per-class metadata and property accessors.
- Supports async asset embedding/export and lazy deserialization via phases.
- Maps loaded assets/objects back to their source IDs for caching and deduplication.
Typical workflow:
- Construct with a
VFS. - Optionally
registerClassfor custom types. - Use
serializeObjectanddeserializeObjectto convert between runtime objects and JSON. - Use
saveScene/loadScenefor scene I/O.
Caching:
getAssetIdreturns the known source ID for an allocated asset when available.
Threading:
- Methods returning Promises perform async I/O using the provided
VFS/AssetManager.
Constructors
Constructor
new ResourceManager(
vfs,editorMode?):ResourceManager
Defined in: libs/scene/src/utility/serialization/manager.ts:287
Create a ResourceManager bound to a virtual file system.
Parameters
vfs
VFS
Virtual file system used for reading/writing assets and scenes.
editorMode?
boolean = false
Returns
ResourceManager
Accessors
VFS
Get Signature
get VFS():
VFS
Defined in: libs/scene/src/utility/serialization/manager.ts:506
The virtual file system used by this manager.
Remarks
Used by asset fetchers and scene save/load operations.
Returns
VFS
Set Signature
set VFS(
vfs):void
Defined in: libs/scene/src/utility/serialization/manager.ts:509
Parameters
vfs
VFS
Returns
void
editorMode
Get Signature
get editorMode():
boolean
Defined in: libs/scene/src/utility/serialization/manager.ts:523
Wethether editor mode is enabled
Remarks
In editor mode, some properties will be disabled
Returns
boolean
assetManager
Get Signature
get assetManager():
AssetManager
Defined in: libs/scene/src/utility/serialization/manager.ts:529
AssetManager
Returns
Methods
getClasses()
getClasses():
SerializableClass[]
Defined in: libs/scene/src/utility/serialization/manager.ts:541
Get the list of all registered serializable classes.
Returns
An array of SerializableClass metadata.
Remarks
Includes built-in classes registered during construction and any custom classes registered via registerClass.
getClassByConstructor()
getClassByConstructor(
ctor):SerializableClass
Defined in: libs/scene/src/utility/serialization/manager.ts:551
Get serialization metadata by a constructor function.
Parameters
ctor
GenericConstructor
The class constructor to look up.
Returns
The SerializableClass metadata, or null if not found.
getClassByObject()
getClassByObject(
obj):SerializableClass
Defined in: libs/scene/src/utility/serialization/manager.ts:561
Get serialization metadata by an object instance.
Parameters
obj
object
The object whose constructor will be used for the lookup.
Returns
The SerializableClass metadata, or null if not found.
getClassByName()
getClassByName(
className):SerializableClass
Defined in: libs/scene/src/utility/serialization/manager.ts:571
Get serialization metadata by class name.
Parameters
className
string
Fully qualified class name as stored in JSON.
Returns
The SerializableClass metadata, or null if not found.
getClassByProperty()
getClassByProperty(
prop):SerializableClass
Defined in: libs/scene/src/utility/serialization/manager.ts:586
Find the class that owns a given property accessor.
Parameters
prop
Property accessor to search for.
Returns
The SerializableClass that declares the property, or null if unknown.
getPropertiesByClass()
getPropertiesByClass(
cls):PropertyAccessor[]
Defined in: libs/scene/src/utility/serialization/manager.ts:601
Get the properties declared on a given class.
Parameters
cls
Serializable class metadata.
Returns
An array of PropertyAccessor entries, or null if none.
getAllPropertiesByClass()
getAllPropertiesByClass(
cls):PropertyAccessor[]
Defined in: libs/scene/src/utility/serialization/manager.ts:607
Get all properties declared on a class, including inherited serializable properties.
Parameters
cls
Returns
getPropertyByClass()
getPropertyByClass(
cls,name):PropertyAccessor
Defined in: libs/scene/src/utility/serialization/manager.ts:624
Get a property accessor by class and property name.
Parameters
cls
Serializable class metadata.
name
string
Property name to search for.
Returns
The PropertyAccessor, or null if not found.
getPropertyByName()
getPropertyByName(
name):PropertyAccessor
Defined in: libs/scene/src/utility/serialization/manager.ts:637
Get a property accessor by its canonical path.
Parameters
name
string
Canonical property path.
Returns
The PropertyAccessor, or null if not found.
Remarks
The canonical path format is /ClassName/propName.
getPropertyName()
getPropertyName(
prop):string
Defined in: libs/scene/src/utility/serialization/manager.ts:650
Get the canonical path for a property accessor.
Parameters
prop
Property accessor.
Returns
string
The canonical path, or null if unknown.
Remarks
Returns a string like /ClassName/propName if the property is registered.
registerClass()
registerClass(
cls):void
Defined in: libs/scene/src/utility/serialization/manager.ts:662
Register a serializable class and its properties.
Parameters
cls
Serializable class metadata to register.
Returns
void
Remarks
- No effect if the class is already registered.
- Also registers the class's properties with canonical paths.
getAssetId()
getAssetId(
asset):string
Defined in: libs/scene/src/utility/serialization/manager.ts:678
Get the known asset ID previously associated with a loaded/allocated asset.
Parameters
asset
unknown
Asset instance (e.g., texture, model group) to look up.
Returns
string
The asset ID string, or null if unknown.
Remarks
Returns null if the asset was not loaded or tracked by this manager.
setAssetId()
setAssetId(
asset,id?):void
Defined in: libs/scene/src/utility/serialization/manager.ts:688
Associate an asset ID to a loaded/allocated asset.
Parameters
asset
unknown
Asset instance (e.g., texture, model group) to set Id.
id?
string
Asset ID to associated to this asset.
Returns
void
getMaterialRefsByAssetId()
getMaterialRefsByAssetId(
id):Set<DWeakRef<Material>>
Defined in: libs/scene/src/utility/serialization/manager.ts:705
Parameters
id
string
Returns
Set<DWeakRef<Material>>
syncMaterialReferences()
syncMaterialReferences(
source):void
Defined in: libs/scene/src/utility/serialization/manager.ts:727
Parameters
source
Returns
void
syncMaterialUniformReferences()
syncMaterialUniformReferences(
source):void
Defined in: libs/scene/src/utility/serialization/manager.ts:764
Parameters
source
Returns
void
syncMaterialPropertyReferences()
syncMaterialPropertyReferences(
source,prop):Promise<void>
Defined in: libs/scene/src/utility/serialization/manager.ts:814
Parameters
source
prop
Returns
Promise<void>
trackMaterialReference()
trackMaterialReference(
material,id?):void
Defined in: libs/scene/src/utility/serialization/manager.ts:863
Parameters
material
id?
string
Returns
void
fetchBinary()
fetchBinary(
path,options?):Promise<ArrayBuffer>
Defined in: libs/scene/src/utility/serialization/manager.ts:914
Fetch a binary asset by ID via the asset manager.
Parameters
path
string
VFS path.
options?
Optional fetch options
Returns
Promise<ArrayBuffer>
A Promise that resolves to the binary content, or null if not found.
Remarks
- Associates the returned data with the given ID for future reverse lookup.
- The ID is typically a VFS path or locator.
fetchJsonData()
fetchJsonData<
T>(path,options?):Promise<T>
Defined in: libs/scene/src/utility/serialization/manager.ts:932
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
path
string
Resource URL or VFS path.
options?
Optional fetch options
Returns
Promise<T>
A promise that resolves to the loaded JSON value.
serializeObject()
serializeObject(
obj,json?,asyncTasks?):Promise<any>
Defined in: libs/scene/src/utility/serialization/manager.ts:952
Serialize an object to a JSON structure using registered class metadata.
Parameters
obj
any
The object to serialize.
json?
any
Optional existing JSON object to fill.
asyncTasks?
Promise<unknown>[]
Optional list to collect async tasks for embedded asset export.
Returns
Promise<any>
The serialized JSON structure.
Remarks
- Throws if the object's class is not registered.
- Populates
asyncTaskswith pending I/O tasks for embedded resources.
serializeObjectProps()
serializeObjectProps(
obj,json?,asyncTasks?,info?):Promise<any>
Defined in: libs/scene/src/utility/serialization/manager.ts:984
Serialize object properties into a JSON structure.
Parameters
obj
any
The target object to serialize.
json?
any
The JSON structure to populate.
asyncTasks?
Promise<unknown>[]
Optional list to collect async tasks for embedded asset export.
info?
Optional serialization metadata for the object's class.
Returns
Promise<any>
A Promise that resolves when serialization is complete.
deserializeObject()
deserializeObject<
T>(ctx,json):Promise<T>
Defined in: libs/scene/src/utility/serialization/manager.ts:1017
Deserialize a JSON structure into an object instance.
Type Parameters
T
T extends object
Parameters
ctx
any
Context object passed to custom constructors/resolvers.
json
Record<string, unknown>
The serialized JSON structure.
Returns
Promise<T>
A Promise resolving to the reconstructed object instance, or null on failure.
Remarks
- Uses the
ClassNamefield to locate the registered class. - Supports custom
createFuncand phased property loading.
deserializeObjectProps()
deserializeObjectProps(
obj,json,info?):Promise<void>
Defined in: libs/scene/src/utility/serialization/manager.ts:1058
Deserialize object properties from JSON into an existing object instance.
Parameters
obj
any
The target object to populate.
json
any
The JSON structure containing serialized properties.
info?
Optional serialization metadata for the object's class.
Returns
Promise<void>
fetchModel()
fetchModel(
path,scene,options?):Promise<SceneNode>
Defined in: libs/scene/src/utility/serialization/manager.ts:1081
Load a model by ID and track the allocation for reverse lookup.
Parameters
path
string
scene
Scene into which the model is loaded.
options?
Optional model fetch options.
Returns
Promise<SceneNode>
A Promise resolving to the loaded model object, or null if failed.
loadTextureFromBuffer()
loadTextureFromBuffer<
T>(arrayBuffer,mimeType,srgb?,samplerOptions?,texture?):Promise<T>
Defined in: libs/scene/src/utility/serialization/manager.ts:1104
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.
fetchTexture()
fetchTexture<
T>(id,options?):Promise<T>
Defined in: libs/scene/src/utility/serialization/manager.ts:1121
Load a texture by ID and track the allocation for reverse lookup.
Type Parameters
T
T extends TextureCube<unknown> | Texture2D<unknown> | Texture2DArray<unknown>
Parameters
id
string
Texture identifier or path.
options?
Optional texture fetch options.
Returns
Promise<T>
A Promise resolving to the loaded texture, or null if failed.
fetchMaterial()
fetchMaterial<
T>(id,options?):Promise<T>
Defined in: libs/scene/src/utility/serialization/manager.ts:1138
Load a material by ID and track the allocation for reverse lookup.
Type Parameters
T
T extends Material = MeshMaterial
Parameters
id
string
Material identifier or path.
options?
overrideVFS?
VFS
Returns
Promise<T>
A Promise resolving to the loaded material, or null if failed.
invalidateMaterial()
invalidateMaterial(
id):void
Defined in: libs/scene/src/utility/serialization/manager.ts:1150
Remove one material from the asset cache.
Parameters
id
string
Material identifier or path.
Returns
void
reloadBluePrintMaterials()
reloadBluePrintMaterials(
filter?):Promise<void>
Defined in: libs/scene/src/utility/serialization/manager.ts:1159
Reload specific blue print materials
Parameters
filter?
(m) => boolean
Determine whether a blue print material should reload.
Returns
Promise<void>
invalidateBluePrint()
invalidateBluePrint(
path):void
Defined in: libs/scene/src/utility/serialization/manager.ts:1166
Mark specific blue print as changed
Parameters
path
string
BluePrint file path
Returns
void
setModelLoader()
setModelLoader(
mimeType,loader):void
Defined in: libs/scene/src/utility/serialization/manager.ts:1172
Register a model loader by MIME type.
Parameters
mimeType
string
loader
Returns
void
fetchPrimitive()
fetchPrimitive<
T>(id,options?):Promise<T>
Defined in: libs/scene/src/utility/serialization/manager.ts:1182
Load a primitive by ID and track the allocation for reverse lookup.
Type Parameters
T
T extends Primitive = Primitive
Parameters
id
string
Primitive identifier or path.
options?
overrideVFS?
VFS
Returns
Promise<T>
A Promise resolving to the loaded primitive, or null if failed.
fetchFontAsset()
fetchFontAsset(
path,options?):Promise<FontAsset>
Defined in: libs/scene/src/utility/serialization/manager.ts:1192
Load a font asset by path and track the allocation for reverse lookup.
Parameters
path
string
options?
Returns
Promise<FontAsset>
getFontAsset()
getFontAsset(
path):FontAsset
Defined in: libs/scene/src/utility/serialization/manager.ts:1203
Returns the cached font asset if it is already loaded.
Parameters
path
string
Returns
releaseFontAsset()
releaseFontAsset(
asset):boolean
Defined in: libs/scene/src/utility/serialization/manager.ts:1209
Releases a cached font asset.
Parameters
asset
unknown
Returns
boolean
loadPrefabContent()
loadPrefabContent(
path):Promise<{type:string;data:object; }>
Defined in: libs/scene/src/utility/serialization/manager.ts:1218
Load a prefab content.
Parameters
path
string
Path to the prefab JSON file in VFS.
Returns
Promise<{ type: string; data: object; }>
A Promise resolving to the prefab json object, or null on failure.
instantiatePrefab()
instantiatePrefab(
parent,path):Promise<SceneNode>
Defined in: libs/scene/src/utility/serialization/manager.ts:1243
Instantiate a prefab from a JSON file via VFS.
Parameters
parent
Parent node to attach the instantiated prefab to.
path
string
Path to the prefab JSON file in VFS.
Returns
Promise<SceneNode>
A Promise resolving to the instantiated SceneNode, or null on failure.
loadScene()
loadScene(
filename):Promise<Scene>
Defined in: libs/scene/src/utility/serialization/manager.ts:1275
Load a scene from a JSON file via VFS.
Parameters
filename
string
Path to the scene JSON file in VFS.
Returns
Promise<Scene>
A Promise resolving to the loaded Scene.
Remarks
- Deserializes the scene graph.
- Attaches scripts referenced by nodes after load (asynchronous).
saveScene()
saveScene(
scene,filename):Promise<void>
Defined in: libs/scene/src/utility/serialization/manager.ts:1290
Save a scene to a JSON file via VFS.
Parameters
scene
Scene to serialize and save.
filename
string
Destination path in VFS.
Returns
Promise<void>
Remarks
- Collects async export tasks for embedded resources and awaits them.
- Writes a UTF-8 JSON representation to VFS.
createBluePrintDAG()
createBluePrintDAG(
nodeMap,roots,links):BlueprintDAG
Defined in: libs/scene/src/utility/serialization/manager.ts:1417
Parameters
nodeMap
Record<number, IGraphNode>
roots
number[]
links
object[]
Returns
loadBluePrint()
loadBluePrint(
path):Promise<Record<string,MaterialBlueprintIR>>
Defined in: libs/scene/src/utility/serialization/manager.ts:1438
Parameters
path
string
Returns
Promise<Record<string, MaterialBlueprintIR>>
clearCache()
clearCache():
void
Defined in: libs/scene/src/utility/serialization/manager.ts:1447
Clear cached allocations and asset-manager caches.
Returns
void
Remarks
Useful when reloading content or changing VFS mounts.
findAnimationTarget()
findAnimationTarget(
node,track):object
Defined in: libs/scene/src/utility/serialization/manager.ts:1520
Find the object targeted by an animation track starting from a node.
Parameters
node
Root node used as the starting point.
track
Property track containing a target path.
Returns
object
The resolved target object, or null if not found.
Remarks
- Parses a target path like
prop/subprop[0]/childwhere indexed entries requireobject_arraytype and non-indexed entries requireobjecttype. - Returns
nullif any segment cannot be resolved through registered metadata.