JSONSceneExporter

View source

ExtendsExporter

Exports Scene snapshot assets as JSON through the inherited Exporter contract.

The serialized document contains entity component snapshots under entities and world resource snapshots under resources. Registry-backed snapshot methods are applied while building those sections; this class does not restore scenes or mutate the source asset.

Constructor


constructor()

View source

Associates this exporter with Scene assets.

The constructor passes Scene to the inherited Exporter contract so the exporter is associated with that asset type.

Methods


serialize(asset: Scene, typeRegistry: TypeRegistry): Promise<string>

View source

Serializes a Scene snapshot asset to JSON text.

Entity snapshots are written under entities as object properties keyed by the entity IDs in Scene#entities. Each entity’s component snapshots become properties keyed by their live type IDs. Resource snapshots are written under resources, keyed by the live type IDs in Scene#resources.

For each component or resource snapshot, the matching TypeRegistry entry’s serialize method is used when it returns a non-nullish value; otherwise the original snapshot is passed through. Because this method is async, the final JSON.stringify result is returned as a Promise<string>; serialization errors from the registry method or JSON conversion are not caught here.

Examples

const exporter = new JSONSceneExporter()
const json = await exporter.serialize(scene, typeRegistry)
console.log(exporter.getExtensions()) // ['json']

Parameters

NameDescriptionDefault
asset

Scene snapshot to serialize.

—
typeRegistry

Registry used for snapshot serialization methods.

—

Returns

JSON text containing the entity and resource snapshots.

getExtensions(): string[]

View source

Returns the extension labels supported by this exporter.

This exporter supports JSON output through the json label, without a leading dot.

Returns

The supported extension labels: ['json'].