Skip to content

XR Planes

Updated

The real floors, walls and tables an AR or mixed-reality device detects.

Type
ent-xr-planes
Script class
XRPlanesEntity
Family
XR

XR Planes brings the flat surfaces of the real room into the scene: the floors, walls, tables and desks that an AR phone or a mixed-reality headset detects. Each detected plane becomes a child mesh of the entity, placed where it is in the room and kept there every frame. Virtual objects can then land on the real floor, bounce off a real table or cast shadows on it.

Planes appear only in play, during an AR or mixed-reality session, on a device that detects them. In the editor, on a desktop or in VR, the entity holds nothing. Its own transform plays no part: each surface is where it is in the room, wherever you put the entity.

How the planes look depends on the entity’s material:

  • With no material, they are hidden: never drawn, but they still collide when the entity has an XR Plane Collider.
  • With a material component, every plane is drawn with that one material: a translucent colour while you test, or a Matte Shadow material that shows only virtual shadows on the real floor.

The props that matter:

  • labels keeps only the planes with these labels, such as floor, wall or table. An empty list keeps every plane. Changing it rebuilds the planes from what is detected now.
  • receiveShadow lets the planes receive the shadows of virtual objects. Real surfaces never cast shadows themselves.

Planes are simple and widely available. For the detailed shape of furniture and walls, use XR Meshes; for the room’s light and depth, and recentering, use the XR World. A scene can hold several XR Planes entities, each keeping some labels with its own look: a floor that catches shadows and walls drawn as a hologram, for example.

  1. Add an XR Planes entity to the scene, anywhere. See Scenes and hierarchy.
  2. Set labels to the kinds of surface you need, or leave it empty for all of them.
  3. To make the planes solid for physics, add an XR Plane Collider.
  4. To see them, or catch shadows on them, add a material component and turn on receiveShadow as needed.
  5. To react to new surfaces from a script, add a Signal Emitter with a signal name.

Keep a running count of the tables the device has found.

CountTables.jx
#pragma lifecycle(startup)
let tables = 0;
function startup() {
// The XR Planes entity has a Signal Emitter with the signal 'room'.
on('room', (event) => {
if (event.data.label !== 'table') return;
if (event.eventType === EventType.XRPlanes.Detected) tables += 1;
if (event.eventType === EventType.XRPlanes.Lost) tables -= 1;
emit('hud/tables', { count: tables });
});
}

How it works:

  • Every plane sends XRPlanes::detected once when it appears and XRPlanes::lost once when it goes, including when the session ends, so the count stays right.
  • event.data.label is the device’s label for the plane; it is absent when the device gives none.
  • XRPlanes::updated, sent when a plane changes shape, does not change the count, so the script skips it.

As soon as the device finds the floor, show a hidden game board on it.

BoardOnFloor.jx
#pragma lifecycle(startup)
const spot = new THREE.Vector3();
let placed = false;
function startup() {
// This XR Planes entity has labels ['floor'] and a Signal Emitter with the signal 'floor'.
// 'Board' is an entity saved disabled.
const board = findEntity('Board');
on('floor', (event) => {
if (placed || !board || event.eventType !== EventType.XRPlanes.Detected) return;
event.data.mesh.getWorldPosition(spot);
board.setPosition(spot.x, spot.y, spot.z);
board.setEnabled(true);
placed = true;
});
}

How it works:

  • With labels: ['floor'], the entity keeps only floor planes, so every event here is about the floor.
  • event.data.mesh is the plane in the scene; getWorldPosition gives where it is in the world.
  • setPosition moves the board and any physics body on it, and setEnabled(true) shows it. placed makes it happen once.

Look through the detected planes and put a centrepiece on the biggest table.

Centrepiece.jx
#pragma lifecycle(startup)
const box = new THREE.Box3();
const size = new THREE.Vector3();
const centre = new THREE.Vector3();
function startup() {
// This XR Planes entity has labels ['table'].
const planes = findEntity('Tables').getComponent(XRPlanesComponent);
const vase = findEntity('Vase');
on('ui/place-vase', () => {
let best = null;
let bestArea = 0;
for (const mesh of planes.meshes) {
box.setFromObject(mesh).getSize(size);
const area = size.x * size.z;
if (area > bestArea) {
bestArea = area;
best = mesh;
}
}
if (!best) {
log('No table found yet among', planes.count, 'planes');
return;
}
box.setFromObject(best).getCenter(centre);
vase.setPosition(centre.x, box.max.y, centre.z);
vase.setEnabled(true);
});
}

How it works:

  • count is how many planes the entity holds now, and meshes iterates over them, each a mesh.
  • A THREE.Box3 around each mesh gives its size in the world; the largest horizontal area wins.
  • The vase is placed on the centre of that table, at the top of its box, when a UI button emits ui/place-vase.
  • Planes take a moment to appear after a session starts, and grow as the player looks around. React to XRPlanes::detected instead of reading count once in startup.
  • Nothing is sent when a plane only moves, and no lost is sent when the entity is switched off or removed: the planes go silently with it.
  • GraphicsRaycaster hits the planes only while they are drawn with a material; PhysicsRaycaster hits them through an XR Plane Collider.

What a new XR Planes 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.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
XR Planes comp-xr-planes Required One Shows detected real floors, walls and tables.

You can also add 13 optional components, such as Basic Material, Glass Material, Lambert Material, Matte Shadow Material, Normal Material, Phong Material.

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
labels []
receiveShadow false

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

  • XRPlanes::detected
  • XRPlanes::updated
  • XRPlanes::lost

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 XR Planes.

XRPlanesEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My XR Planes');
if (!(entity instanceof XRPlanesEntity)) return;
// Its XR Planes component holds the settings listed under Props.
const component = entity.getComponent(XRPlanesComponent);
log(component.props);
}