Mesh Collada
Updated
Lets the entity’s meshes cast and/or receive shadows from lights.
- Type
ent-mesh-collada- Script class
ColladaMeshEntity- Family
- Meshes
Overview
Section titled “Overview”A Mesh Collada shows a model loaded from a Collada file (.dae), an exchange format that older modelling and CAD tools export. It works like every other model entity: the file is named by its required Collada loader component (comp-collada), reached in scripts as ColladaComponent, and the model draws with the materials stored in the file. A new Mesh Collada starts with a Shadow component that casts shadows but does not receive them.
When the model is in place, the loader sends Collada::ready; when the file cannot load, it sends Collada::error with a message. Both reach scripts through a Signal Emitter on the entity. Changing the source keeps the current model on screen until the new one is ready, and a failed replacement leaves it in place.
Collada files work, but they are larger and slower to parse than GLB. Use a Mesh Collada for files that only exist as .dae; when you can re-export, a Mesh Gltf loads faster.
What matters most:
src(Collada loader): the.daefile, as a project asset reference (ASSET-<uuid>) or a URL. Changing it reloads the model;''removes it.castandreceive(Shadow): whether the model casts and receives shadows.- A material component, if you add one, overrides every material of the model with one look.
setModelView('full' | 'hidden')shows or hides this model, andmodelViewreads which is requested.
Set it up
Section titled “Set it up”- Add a Mesh Collada entity to the scene (see Scenes and hierarchy) and name it.
- Set the loader’s
srcto the.daefile. - Place, turn and scale the entity.
- Add a Signal Emitter with a signal to follow its loading from a script, and an Animation Clip to play the clips it contains.
Examples
Section titled “Examples”Report when the model has loaded
Section titled “Report when the model has loaded”Goal: log when the Collada model is ready, and warn with the reason when it fails.
The model Turbine has a Signal Emitter whose signal is turbine.
#pragma lifecycle(startup)
function startup() { on('turbine', ({ eventType, data }) => { if (eventType === EventType.Collada.Ready) log('The turbine has loaded'); if (eventType === EventType.Collada.Error) console.warn('The turbine failed: ' + data.message); });}- The Collada loader sends
EventType.Collada.ReadyandEventType.Collada.Error. Note the capitalisation:Collada, notCOLLADA. readyis sent again after each reload, so the listener also reports every change ofsrc.
Show a model on a turntable
Section titled “Show a model on a turntable”Goal: a showroom piece that turns slowly and endlessly once it has loaded.
The Behavior entity is a child of the model, which has a Signal Emitter whose signal is exhibit.
#pragma slot(ref=secondsPerTurn, type=Number, min=2, max=120, default=20)#pragma lifecycle(startup)
let spin = null;
function start(model) { if (spin) return; spin = Tween.to(model.rotation, { y: model.rotation.y + M_TAU }, { duration: secondsPerTurn, ease: Ease.Linear, repeat: Infinity, });}
function startup() { const model = self.parent; if (model.isLoaded) start(model); on('exhibit', ({ eventType }) => { if (eventType === EventType.Collada.Ready) start(model); });}Tween.to(object, values, options)animates numbers on an object. Here it turns the entity’srotation.ybyM_TAU, a full turn in radians.Ease.Linearkeeps the speed constant, andrepeat: Infinityturns forever.- The turntable starts only once the model is there, either already loaded (
isLoaded) or whenreadyarrives. Thespincheck stops a reload from starting a second tween.
Hide and show a model with a key
Section titled “Hide and show a model with a key”Goal: press H to hide a large model, for example to see what is behind it, and press it again to bring it back.
#pragma lifecycle(startup, update)
let model;
function startup() { model = findEntity('Turbine');}
function update() { if (!Input.keyboard.isKeyReleased(Key.H)) return;
const next = model.modelView === 'hidden' ? 'full' : 'hidden'; model.setModelView(next); log('Turbine is now', next);}Input.keyboard.isKeyReleased(Key.H)is true once per key press.modelViewreads the view requested for this model;setModelViewchanges it.'hidden'also hides the entity’s children.- The view applies to this instance only: other copies of the same file stay as they are.
- Wait for
Collada::ready, or checkisLoaded, before reading bounds, nodes or clip names. ModelLoaderComponentfinds the loader of any model format, which helps scripts that work on several kinds of model.- To show a different file, change
src: an entity accepts only its own format’s loader.
Components
Section titled “Components”What a new Mesh Collada is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Shadow | comp-shadow |
Starts with | One | Lets the entity’s meshes cast and/or receive shadows from lights. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Collada | comp-collada |
Required | One | Loads a Collada .dae model. |
You can also add 70 optional components, such as Animation Clip, Animation Graph, Animation Timeline, Attribution, Basic Material, Billboard.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
cast |
true |
|
receive |
false |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
Shadow::changeCollada::readyCollada::error
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
An animated Collada (.dae) character on a turntable, with its texture beside the file: the script centres it, scales it to 1.4 m and plays the first clip stored in the file.
Watch the character turn on the turntable while it plays its clip; the log lists the clips. Drag to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Mesh Collada.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Mesh Collada'); if (!(entity instanceof ColladaMeshEntity)) return;
// Its Shadow component holds the settings listed under Props. const component = entity.getComponent(ShadowComponent); log(component.props);}