Skip to content

Mesh Collada

Updated

Lets the entity’s meshes cast and/or receive shadows from lights.

Type
ent-mesh-collada
Script class
ColladaMeshEntity
Family
Meshes

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 .dae file, as a project asset reference (ASSET-<uuid>) or a URL. Changing it reloads the model; '' removes it.
  • cast and receive (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, and modelView reads which is requested.
  1. Add a Mesh Collada entity to the scene (see Scenes and hierarchy) and name it.
  2. Set the loader’s src to the .dae file.
  3. Place, turn and scale the entity.
  4. Add a Signal Emitter with a signal to follow its loading from a script, and an Animation Clip to play the clips it contains.

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.

TurbineStatus.jx
#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.Ready and EventType.Collada.Error. Note the capitalisation: Collada, not COLLADA.
  • ready is sent again after each reload, so the listener also reports every change of src.

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.

Turntable.jx
#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’s rotation.y by M_TAU, a full turn in radians.
  • Ease.Linear keeps the speed constant, and repeat: Infinity turns forever.
  • The turntable starts only once the model is there, either already loaded (isLoaded) or when ready arrives. The spin check stops a reload from starting a second tween.

Goal: press H to hide a large model, for example to see what is behind it, and press it again to bring it back.

ToggleModel.jx
#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.
  • modelView reads the view requested for this model; setModelView changes 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 check isLoaded, before reading bounds, nodes or clip names.
  • ModelLoaderComponent finds 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.

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-transform 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

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Shadow::change
  • Collada::ready
  • Collada::error

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

ColladaMeshEntity.jx
#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);
}