AssetSceneMap

View source

Runtime-only World resource for scene-local asset handle mapping.

Scene#toWorld uses this map while restoring a Scene: an AssetId for the scene asset, an asset TypeId, and a snapshot index identify the untyped Handle associated with that scene asset. The map is installed in the world on demand for scene restoration and is not part of the scene snapshot itself.

Examples

// After {@linkcode Scene#toWorld} has restored a scene with an asset ID:
const sceneMap = world.getResource(AssetSceneMap)
const handle = sceneMap.get(sceneAssetId, textureTypeId, 0)
if (handle) handle.drop()
sceneMap.clear(sceneAssetId, textureTypeId)

Constructor


constructor()

Methods


set(sceneAssetId: AssetId, assetTypeId: TypeId, snapshotIndex: number, handle: UntypedHandle): void

View source

Stores an untyped Handle for a scene asset snapshot.

The supplied handle is stored as-is under the AssetId and TypeId key; it is not cloned. An existing value at the same key is replaced without dropping the previous handle.

Parameters

NameDescriptionDefault
sceneAssetId

Scene asset ID used by Scene#toWorld.

—
assetTypeId

Asset type ID represented by the snapshot.

—
snapshotIndex

Index of the asset in the scene snapshot.

—
handle

Handle to retain for later lookup.

—

get(sceneAssetId: AssetId, assetTypeId: TypeId, snapshotIndex: number): UntypedHandle

View source

Looks up a scene-local asset handle and returns a clone of it.

The stored Handle remains in the map; the returned clone gives the caller its own reference. Returns undefined when any part of the key is not mapped.

Parameters

NameDescriptionDefault
sceneAssetId

Scene asset ID used by Scene#toWorld.

—
assetTypeId

Asset type ID represented by the snapshot.

—
snapshotIndex

Index of the asset in the scene snapshot.

—

Returns

A cloned handle, or undefined when no handle is mapped.

clear(sceneAssetId: AssetId, assetTypeId?: TypeId): void

View source

Drops mapped handles and removes scene-map entries.

With no asset type, drops handles for every type under the scene asset and removes the entire scene entry. With a TypeId, only that type is cleared; if it was the last type, its empty scene entry is removed too. Missing scene or type entries are ignored. Each stored handle is released through Handle#drop.

Parameters

NameDescriptionDefault
sceneAssetId

Scene asset ID to clear.

—
assetTypeId?

Optional asset type ID to clear only.

—