Documentation / scene / ResourceManager
Class: ResourceManager
Defined in: libs/scene/src/utility/serialization/manager.ts:245
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:259
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:462
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:465
Parameters
vfs
VFS
Returns
void
editorMode
Get Signature
get editorMode():
boolean
Defined in: libs/scene/src/utility/serialization/manager.ts:474
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:480
AssetManager
Returns
Methods
getClasses()
getClasses():
SerializableClass[]
Defined in: libs/scene/src/utility/serialization/manager.ts:492
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:502
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:512
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:522
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:537
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:552
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:558
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:575
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:588
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:601
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:613
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:629
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:639
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
fetchBinary()
fetchBinary(
id):Promise<ArrayBuffer>
Defined in: libs/scene/src/utility/serialization/manager.ts:659
Fetch a binary asset by ID via the asset manager.
Parameters
id
string
Asset identifier or path.
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.
serializeObject()
serializeObject(
obj,json?,asyncTasks?):Promise<any>
Defined in: libs/scene/src/utility/serialization/manager.ts:679
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:711
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:744
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:785
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:808
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:831
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:848
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:865
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.
reloadBluePrintMaterials()
reloadBluePrintMaterials(
filter?):Promise<void>
Defined in: libs/scene/src/utility/serialization/manager.ts:878
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:885
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:891
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:901
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:911
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:922
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:928
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:937
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:953
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:985
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:1000
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:1119
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:1140
Parameters
path
string
Returns
Promise<Record<string, MaterialBlueprintIR>>
clearCache()
clearCache():
void
Defined in: libs/scene/src/utility/serialization/manager.ts:1149
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:1180
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.