Mesh Fbx
Updated
Lets the entity’s meshes cast and/or receive shadows from lights.
- Type
ent-mesh-fbx- Script class
FBXMeshEntity- Family
- Meshes
Overview
Section titled “Overview”A Mesh Fbx shows a 3D model loaded from an FBX file, a format many modelling and animation tools export. It works like every other model entity: the file is named by its required FBX loader component (comp-fbx), reached in scripts as FBXComponent, and the model draws with the materials stored in the file. A new Mesh Fbx also starts with a Shadow component that casts shadows but does not receive them.
When the model is in place, the loader sends FBX::ready; when the file cannot load, it sends FBX::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.
FBX files work, but they are larger and slower to parse than GLB. If you can re-export a model as glTF or GLB, use a Mesh Gltf instead; keep a Mesh Fbx for files that only exist as FBX.
What matters most:
src(FBX loader): the model file, 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.
getModelRestBounds()andsetModelOffset(x, y, z): measure the model as authored, and shift it inside its entity, for example to fix a pivot exported in the wrong place.
Set it up
Section titled “Set it up”- Add a Mesh Fbx entity to the scene (see Scenes and hierarchy) and name it.
- Set the loader’s
srcto the.fbxfile. - Place, turn and scale the entity. Turn on the Shadow’s
receiveif other objects should shade it. - 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 FBX model is ready, and warn with the reason when it fails.
The model Machine has a Signal Emitter whose signal is machine.
#pragma lifecycle(startup)
function startup() { on('machine', ({ eventType, data }) => { if (eventType === EventType.FBX.Ready) log('The machine has loaded'); if (eventType === EventType.FBX.Error) console.warn('The machine failed: ' + data.message); });}- Each model format has its own event constants. For an FBX model they are
EventType.FBX.ReadyandEventType.FBX.Error. data.messageexplains why the file could not load. Thereadyevent carries no data.
Sit the model on its entity’s origin
Section titled “Sit the model on its entity’s origin”Goal: whatever pivot the file was exported with, centre the model horizontally and rest its lowest point on the entity’s origin.
The Behavior entity is a child of the model, which has a Signal Emitter whose signal is model.
#pragma lifecycle(startup)
let model;
function fit() { const bounds = model.getModelRestBounds(); if (!bounds) return;
const centerX = (bounds.min.x + bounds.max.x) / 2; const centerZ = (bounds.min.z + bounds.max.z) / 2; model.setModelOffset(-centerX, -bounds.min.y, -centerZ); log(model.name, 'is', (bounds.max.y - bounds.min.y).toFixed(2), 'm tall');}
function startup() { model = self.parent; if (model.isLoaded) fit(); on('model', ({ eventType }) => { if (eventType === EventType.FBX.Ready) fit(); });}getModelRestBounds()returns the model’s box as authored,{ min, max }in the entity’s own coordinates, orundefinedbefore it loads.setModelOffset(x, y, z)moves the drawn model inside its entity. The entity’s transform and children do not move, and the authored bounds stay the same, sofitcan run again safely.- A replacement model starts with no offset, so the script refits on every
ready.
Highlight a model with a temporary material
Section titled “Highlight a model with a temporary material”Goal: while a part is selected, draw the whole model in one glowing colour; when it is deselected, give it back its own materials.
The model Engine has a Selectable and a Signal Emitter whose signal is engine.
#pragma lifecycle(startup)
let highlight = null;
function startup() { const engine = findEntity('Engine');
on('engine', (event) => { if (event.eventType === EventType.Selectable.Select && !highlight) { highlight = new StandardMaterialComponent({ color: '#ffd166', emissive: '#ffb000', emissiveIntensity: 0.6, roughness: 0.4, }); engine.addComponent(highlight); } if (event.eventType === EventType.Selectable.Deselect && highlight) { engine.removeComponent(highlight); highlight = null; } });}- A material component on a model is an override: one material, built once, drawn on every mesh of the model.
removeComponent(highlight)takes the override away, and the model’s own materials come back. The file’s materials are never changed.SelectandDeselectcome from the Selectable, through the same Signal Emitter as the loader’s events.
- Wait for
FBX::ready, or checkisLoaded, before reading bounds, nodes or clip names. - Scripts use the global
FBXComponent, in capitals.ModelLoaderComponentfinds the loader of any model format. - Listen with the FBX constants: a script that waits for
EventType.GLTF.Readynever hears an FBX model.
Components
Section titled “Components”What a new Mesh Fbx 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. |
| Fbx | comp-fbx |
Required | One | Loads an FBX 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::changeFBX::readyFBX::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 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.
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 Fbx.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Mesh Fbx'); if (!(entity instanceof FBXMeshEntity)) return;
// Its Shadow component holds the settings listed under Props. const component = entity.getComponent(ShadowComponent); log(component.props);}