Skip to content

OpenXR Spatial Entities Compiler

Compiles HoloScript spatial anchoring definitions to the OpenXR Spatial Entities extension — the Khronos standard for persistent, world-locked AR anchors across platforms.

Overview

The OpenXR Spatial Entities compiler (--target openxr-spatial) generates C++ or JSON configuration for the OpenXR XR_EXT_spatial_entity and XR_MSFT_scene_understanding extensions. These are the standard mechanisms for:

  • Persistent world anchors — objects that stay stuck to real surfaces across sessions
  • Plane detection — horizontal and vertical surface tracking
  • Scene understanding — semantic labels on detected surfaces (floor, wall, table, ceiling)
  • Cross-device persistence — anchors shared between users on Meta Quest, HoloLens, PICO, and Magic Leap
bash
holoscript compile anchors.holo --target openxr-spatial --output ./xr/

Spatial Anchor Traits

HoloScript TraitOpenXR ExtensionBehaviour
@anchorXR_EXT_spatial_entityCreate + persist spatial anchor
@world_lockedXrSpatialEntityFlagsEXTLock to physical world position
@plane_detectedXR_MSFT_scene_understandingSnap to detected plane
@trackedXrSpaceLocationFlagsTrack with 6DOF pose
@hand_trackedXR_EXT_hand_trackingHand joint anchor
@eye_trackedXR_EXT_eye_gaze_interactionGaze-stabilized anchor
@persistentxrSaveSpaceXR_EXT_spatial_entitySave anchor UUID across sessions

Example

holo
composition "PersistentARNotes" {
  template "StickyNote" {
    @anchor
    @world_locked
    @persistent

    geometry: "plane"
    scale: [0.2, 0.15, 0.01]
    color: "#ffff88"

    state {
      uuid: ""
      text: "Note content here"
    }

    on_place {
      this.uuid = spatial.createAnchor(this.position, this.rotation)
      spatial.saveAnchor(this.uuid)
    }

    on_load {
      spatial.loadAnchor(this.uuid)
    }
  }

  logic {
    on_plane_detected(plane) {
      if (plane.label == "table") {
        spawn "StickyNote" at plane.center
      }
    }
  }
}

Output

xr/
  anchors.h            # C++ OpenXR extension calls
  anchor_config.json   # Anchor UUIDs and poses
  spatial_mesh.json    # Detected planes / mesh

Generated C++ (excerpt):

cpp
// Create persistent spatial anchor
XrSpatialEntityFlagsEXT flags = XR_SPATIAL_ENTITY_PERSIST_BIT_EXT;
XrCreateSpatialEntityInfoMSFT createInfo{XR_TYPE_CREATE_SPATIAL_ENTITY_INFO_MSFT};
createInfo.pose = anchorPose;
xrCreateSpatialEntityMSFT(session, &createInfo, &spatialAnchor);
xrSaveSpatialEntityMSFT(session, &saveInfo);  // Persist across sessions

Supported Runtimes

RuntimeDeviceRequired Extension
Meta OpenXRQuest 2/3/ProXR_FB_spatial_entity
Microsoft OpenXRHoloLens 2XR_MSFT_spatial_anchor
PICO OpenXRPICO 4XR_EXT_spatial_entity
Magic Leap OpenXRMagic Leap 2XR_ML_localization_map
SteamVRIndex / ViveXR_EXT_spatial_entity (limited)

Compiler Options

OptionDefaultDescription
--oxr-runtimegenericTarget runtime: meta, msft, pico, ml
--oxr-persistencetrueEnable cross-session anchor persistence
--oxr-plane-detectiontrueEnable plane detection
--oxr-scene-meshfalseEnable full environment mesh
--oxr-sharingfalseEnable anchor sharing between users

See Also

Released under the MIT License.