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
Overview
Section titled “Overview”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:
labelskeeps only the planes with these labels, such asfloor,wallortable. An empty list keeps every plane. Changing it rebuilds the planes from what is detected now.receiveShadowlets 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.
Set it up
Section titled “Set it up”- Add an XR Planes entity to the scene, anywhere. See Scenes and hierarchy.
- Set
labelsto the kinds of surface you need, or leave it empty for all of them. - To make the planes solid for physics, add an XR Plane Collider.
- To see them, or catch shadows on them, add a material component and turn on
receiveShadowas needed. - To react to new surfaces from a script, add a Signal Emitter with a signal name.
Examples
Section titled “Examples”Count the tables in the room
Section titled “Count the tables in the room”Keep a running count of the tables the device has found.
#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::detectedonce when it appears andXRPlanes::lostonce when it goes, including when the session ends, so the count stays right. event.data.labelis 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.
Put the game board on the floor
Section titled “Put the game board on the floor”As soon as the device finds the floor, show a hidden game board on it.
#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.meshis the plane in the scene;getWorldPositiongives where it is in the world.setPositionmoves the board and any physics body on it, andsetEnabled(true)shows it.placedmakes it happen once.
Find the largest table
Section titled “Find the largest table”Look through the detected planes and put a centrepiece on the biggest table.
#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:
countis how many planes the entity holds now, andmeshesiterates over them, each a mesh.- A
THREE.Box3around 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::detectedinstead of readingcountonce instartup. - Nothing is sent when a plane only moves, and no
lostis sent when the entity is switched off or removed: the planes go silently with it. GraphicsRaycasterhits the planes only while they are drawn with a material;PhysicsRaycasterhits them through an XR Plane Collider.
Components
Section titled “Components”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- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| XR Planes | comp- |
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 |
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.
XRPlanes::detectedXRPlanes::updatedXRPlanes::lost
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.
Counts the real tables an AR device detects from the XR Planes events, and emits the count on hud/tables for a HUD to show.
This one needs AR: in a headset or AR phone that labels planes, each table found raises the count. On a desktop no planes are detected.
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 XR Planes.
#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);}