Skip to main content

LensStudio:AssetInstantiator.AssetInstantiator

Class

Plugin class that manages asset instantiation, initialized with a PluginSystem and optional Descriptor.

Index

Example

// LensStudio:AssetInstantiator.AssetInstantiator is the same class exported
// at the module root (LensStudio:AssetInstantiator); this entry just
// documents it under its dotted name. See the module page for the Texture
// drop flow that imports a bundled plane mesh + material. Below: a generic
// instantiator that puts every dropped asset under a single named parent
// SceneObject — handy for AI-tool plugins that stage drops in one bucket
// for review.
import { AssetInstantiator, Descriptor } from 'LensStudio:AssetInstantiator';

const STAGED_PARENT = 'StagedDrops';

export class StagedAssetInstantiator extends AssetInstantiator {
static descriptor(): Descriptor {
const d = new Descriptor();
d.id = 'com.docs.AssetInstantiatorClassExample';
d.name = 'Staged Asset Instantiator';
d.description = 'Drops any asset under a single staging parent';
d.dependencies = [Editor.Model.IModel];
d.canInstantiate = (_asset: Editor.Assets.Asset) => true;
return d;
}

async prepareDependencies(
_asset: Editor.Assets.Asset,
_manager: Editor.Model.AssetManager,
): Promise<Editor.Assets.Asset[]> {
// Ensure the dedicated parent exists so all drops nest under it.
const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const scene = model.project.scene;
if (!scene.rootSceneObjects.find(o => o.name === STAGED_PARENT)) {
scene.createSceneObject(STAGED_PARENT);
}
return [];
}

instantiate(
asset: Editor.Assets.Asset,
scene: Editor.Assets.ObjectOwner,
target: Editor.Model.SceneObject,
): Editor.Model.Prefabable[] {
const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const parent = model.project.scene.rootSceneObjects.find(o => o.name === STAGED_PARENT) ?? target;
const obj = scene.addSceneObject(parent);
obj.name = `${asset.name} (staged ${new Date().toISOString().slice(0, 10)})`;
return [obj as unknown as Editor.Model.Prefabable];
}
}

Extends

Constructors

Constructor

new AssetInstantiator(pluginSystem, descriptor?): AssetInstantiator

Constructs an AssetInstantiator plugin instance with the given plugin system and optional descriptor.

Parameters

ParameterType
pluginSystemPluginSystem
descriptor?Descriptor

Returns

AssetInstantiator

Overrides

Editor.IPlugin.constructor

Properties

id

readonly id: string

Unique string identifier of the plugin instance.

Inherited from

IPlugin.id


pluginSystem

readonly pluginSystem: PluginSystem

The plugin system instance this instantiator is registered with.

Methods

getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

IPlugin.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

IPlugin.getTypeName


instantiate()

instantiate(asset, scene, target): Prefabable[]

Instantiates an asset into a scene under the given target scene object, returning the created prefabable objects.

Parameters

ParameterType
assetAsset
sceneObjectOwner
targetSceneObject

Returns

Prefabable[]


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

IPlugin.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

IPlugin.isSame


prepareDependencies()

prepareDependencies(asset, manager): Promise<Asset[]>

Resolves and prepares all asset dependencies required before instantiation, returning them as a promise.

Parameters

ParameterType
assetAsset
managerAssetManager

Returns

Promise<Asset[]>