Load an FBX model and play its clip
Updated
An animated FBX (.fbx) cube on a turntable, drawn with an amber Standard material that overrides its own: the script sizes it to 0.6 m and plays the animation clip stored in the file.
Watch the cube play the rotation clip from its FBX file; the log names the clip. Drag to orbit the camera, scroll to zoom.
Load an FBX model and play its clip
#pragma lifecycle(startup, update)
const HEIGHT = 0.6; // 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(`FBX 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.FBX.Ready) fit(); if (eventType === EventType.FBX.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.
FbxCube.xrproj