Skip to content

ObjectDescriptor

Descriptor for creating scene objects dynamically

Properties

id read-only

kind read-only

  • Type: string | null
  • The object's representation kind: 'model' | 'primitive' | 'visualMedia' | … , or null if the object has no representation. Read-only. Lets a script branch on what it fetched before editing – e.g. if (d.kind === 'model') d.asset(hi).

Instance Methods

name()

javascript
name(value: string): ObjectDescriptor

Set the object name

Parameters:

Returns: ObjectDescriptor

anchor()

javascript
anchor(anchor: Object): ObjectDescriptor

Set the anchor

Parameters:

  • anchor (Object) - Anchor descriptor created by Anchor static methods

Returns: ObjectDescriptor

asset()

javascript
asset(urlOrId: string): ObjectDescriptor

Set / replace the object's source asset, kind-routed to the right field (model → the model asset, image / video / GIF → the media source). Same-kind swap only – it does not change the object's kind: pointing a model at a video URL gives a broken model, not a video (use .representation(...) to change kind). Warns for kinds with no source (primitive, container). Accepts an HTTPS URL or an asset id from the project.

Parameters:

  • urlOrId (string)

Returns: ObjectDescriptor

representation()

javascript
representation(sourceDescriptor: ObjectDescriptor): ObjectDescriptor

Fully replace this object's visual representation with the one from a freshly built descriptor (createBox, createModel, createVideo, …) – the clean way to change kind (model → primitive, model → video). Keeps this object's identity and wiring: its id, representation id, anchor (placement), and events. Takes the source's kind and its traits – configure the new look via the factory chain, e.g. d.representation(createBox(0.1,0.1,0.1).gestures({ drag: true })).

Note: the authored transform trait rides inside the old kind and is dropped by the swap ("keeps placement" means the anchor, not the transform) – re-apply via the source chain if needed. Element-level fields on the source (.name(), .anchor(), events) are ignored; only its representation is taken.

Parameters:

Returns: ObjectDescriptor

clone()

javascript
clone(): ObjectDescriptor

Deep-copy this descriptor with a fresh id graph (element id + every nested representation id + events), so it can be added alongside the original without an id collision. Use it to spawn variants of an authored object: scene.getObjectDescriptor({ name: 'can' }).clone().transform({ position: p }), then scene.createEntity(...). The copy inherits the original's events (re-wired to the copy); clear them with copy.data.events = [] if unwanted.

Returns: ObjectDescriptor

traits() deprecated

Deprecated

Prefer the direct trait methods on the descriptor – .physics(…), .material(…), .gestures(…), .shadow(…), .transform(…), .opacity(…), .fittingBox(…), .pivot(…). They read the same, chain, and are the supported form going forward. .traits(fn) is kept only for compatibility with existing scripts and will be removed in a future runtime version.

javascript
traits(configureFn: function): ObjectDescriptor

Configure traits via a callback. Traits already on the descriptor (e.g. from createMesh({ materials: [...] })) are preserved – calls add on top.

Parameters:

  • configureFn (function) - Function that receives an ObjectTraits builder.

Returns: ObjectDescriptor

physics()

javascript
physics(options: Object): ObjectDescriptor

Give this object a physics body. See {@link ObjectTraits#physics} for the full options.

Parameters:

  • options (Object) - { mode, shape, mass, friction, restitution, … }.

Returns: ObjectDescriptor

gestures()

javascript
gestures(options: Object): ObjectDescriptor

Enable manipulation gestures (drag / rotate / resize). See {@link ObjectTraits#gestures}.

Parameters:

  • options (Object) - { drag, rotate, resize, releaseBehavior, … }.

Returns: ObjectDescriptor

material()

javascript
material(materialOrId: string | Material, target?: Object): ObjectDescriptor

Apply a material – a library id or an inline Material. See {@link ObjectTraits#material}.

Parameters:

  • materialOrId (string | Material)
  • target (Object) (optional) - Optional model / slot target.

Returns: ObjectDescriptor

shadow()

javascript
shadow(options: Object): ObjectDescriptor

Configure the object's shadows (directional + grounding). See {@link ObjectTraits#shadow}.

Parameters:

  • options (Object) - { directional, grounding }.

Returns: ObjectDescriptor

transform()

javascript
transform(transform: Object): ObjectDescriptor

Set the object's transform (position / rotation / scale). See {@link ObjectTraits#transform}.

Parameters:

  • transform (Object)

Returns: ObjectDescriptor

opacity()

javascript
opacity(opacity: number): ObjectDescriptor

Set the object's opacity (0–1). See {@link ObjectTraits#opacity}.

Parameters:

  • opacity (number)

Returns: ObjectDescriptor

fittingBox()

javascript
fittingBox(size: number): ObjectDescriptor

Scale a model to fit a box of the given size. See {@link ObjectTraits#fittingBox}.

Parameters:

  • size (number)

Returns: ObjectDescriptor

pivot()

javascript
pivot(pivot: string): ObjectDescriptor

Adjust the model's pivot. See {@link ObjectTraits#pivot}.

Parameters:

  • pivot (string)

Returns: ObjectDescriptor