Appearance
ObjectDescriptor
Descriptor for creating scene objects dynamically
Properties
id read-only
- Type: string
- The object's id. Read-only – set at construction (or preserved by
scene.getObjectDescriptor, re-minted by.clone()). Use it to look the object up later, e.g.scene.findEntity(descriptor.id)afterscene.createEntity(descriptor).
kind read-only
- Type: string | null
- The object's representation kind:
'model'|'primitive'|'visualMedia'| … , ornullif 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): ObjectDescriptorSet the object name
Parameters:
value(string)
Returns: ObjectDescriptor
anchor()
javascript
anchor(anchor: Object): ObjectDescriptorSet the anchor
Parameters:
anchor(Object) - Anchor descriptor created by Anchor static methods
Returns: ObjectDescriptor
asset()
javascript
asset(urlOrId: string): ObjectDescriptorSet / 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): ObjectDescriptorFully 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:
sourceDescriptor(ObjectDescriptor)
Returns: ObjectDescriptor
clone()
javascript
clone(): ObjectDescriptorDeep-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): ObjectDescriptorConfigure 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): ObjectDescriptorGive 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): ObjectDescriptorEnable 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): ObjectDescriptorApply a material – a library id or an inline Material. See {@link ObjectTraits#material}.
Parameters:
Returns: ObjectDescriptor
shadow()
javascript
shadow(options: Object): ObjectDescriptorConfigure the object's shadows (directional + grounding). See {@link ObjectTraits#shadow}.
Parameters:
options(Object) -{ directional, grounding }.
Returns: ObjectDescriptor
transform()
javascript
transform(transform: Object): ObjectDescriptorSet the object's transform (position / rotation / scale). See {@link ObjectTraits#transform}.
Parameters:
transform(Object)
Returns: ObjectDescriptor
opacity()
javascript
opacity(opacity: number): ObjectDescriptorSet the object's opacity (0–1). See {@link ObjectTraits#opacity}.
Parameters:
opacity(number)
Returns: ObjectDescriptor
fittingBox()
javascript
fittingBox(size: number): ObjectDescriptorScale a model to fit a box of the given size. See {@link ObjectTraits#fittingBox}.
Parameters:
size(number)
Returns: ObjectDescriptor
pivot()
javascript
pivot(pivot: string): ObjectDescriptorAdjust the model's pivot. See {@link ObjectTraits#pivot}.
Parameters:
pivot(string)
Returns: ObjectDescriptor