LensStudio:AssetInstantiator.AssetInstantiator
ClassPlugin 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
| Parameter | Type |
|---|---|
pluginSystem | PluginSystem |
descriptor? | Descriptor |
Returns
AssetInstantiator
Overrides
Editor.IPlugin.constructor
Properties
id
readonlyid:string
Unique string identifier of the plugin instance.
Inherited from
pluginSystem
readonlypluginSystem:PluginSystem
The plugin system instance this instantiator is registered with.
Methods
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
instantiate()
instantiate(
asset,scene,target):Prefabable[]
Instantiates an asset into a scene under the given target scene object, returning the created prefabable objects.
Parameters
| Parameter | Type |
|---|---|
asset | Asset |
scene | ObjectOwner |
target | SceneObject |
Returns
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
prepareDependencies()
prepareDependencies(
asset,manager):Promise<Asset[]>
Resolves and prepares all asset dependencies required before instantiation, returning them as a promise.
Parameters
| Parameter | Type |
|---|---|
asset | Asset |
manager | AssetManager |
Returns
Promise<Asset[]>