Load an OBJ model
Updated
A low-poly tree loaded from a Wavefront OBJ (.obj) file, which carries geometry only, so an amber Standard material colours it. The script centres it and scales it to 1.6 m.
Watch the tree turn on the turntable. Drag to orbit the camera, scroll to zoom.
Load an OBJ model
#pragma lifecycle(startup, update)
const HEIGHT = 1.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(`OBJ model loaded: ${size.toFixed(2)} m tall as loaded, shown at ${HEIGHT} m`); const clips = model.getAnimationClipNames(); log('Clips:', clips.join(', ') || 'none');}
function startup() { model = self.parent; if (model.isLoaded) fit(); on('model', ({ eventType, data }) => { if (eventType === EventType.OBJ.Ready) fit(); if (eventType === EventType.OBJ.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.
ObjTree.xrproj