Load a Collada model
Updated
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.
Load a Collada model
#pragma lifecycle(startup, update)
const HEIGHT = 1.4; // metreslet model;
function fit() { if (!model.isLoaded) return; // Measure at scale 1, no offset (file units and up axis are already converted). model.scale.setScalar(1); model.rotation.y = 0; model.setModelOffset(0, 0, 0); model.updateMatrixWorld(true); const box = new THREE.Box3().setFromObject(model); const size = box.max.y - box.min.y; const scale = HEIGHT / size; const base = model.position; model.setModelOffset(-(box.min.x + box.max.x) / 2 + base.x, -box.min.y + base.y, -(box.min.z + box.max.z) / 2 + base.z); model.scale.setScalar(scale); log(`Collada model loaded: ${size.toFixed(2)} m tall as loaded, shown at ${HEIGHT} m`); const clips = model.getAnimationClipNames(); log('Clips:', clips.join(', ') || 'none'); if (clips.length && !model.getComponent(AnimationClipComponent)) { model.addComponent(new AnimationClipComponent({ layer: clips[0], autoplay: true, repeat: 'repeat' })); }}
function startup() { model = self.parent; if (model.isLoaded) fit(); on('model', ({ eventType, data }) => { if (eventType === EventType.Collada.Ready) fit(); if (eventType === EventType.Collada.Error) log('Could not load the model:', data.message); });}
function update(dt) { model.rotation.y += dt * 0.4;}Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
ColladaTrooper.xrproj