Skip to main content
Version: 1.0

Spatial Meshing

Spatial Meshing generates a mesh based on scanned geometry from the real world. It can be used to provide valuable spatial context and help to ground an XR experience in the space around a user. Spatial Meshing improves immersion by making it seem that real objects interact with or occlude virtual content.

How to Enable the Feature

In order to use Spatial Meshing, it has to be enabled in the OpenXR plugin settings located under Project Settings > XR Plug-in Management > OpenXR (> Android Tab) > OpenXR Feature Groups > Snapdragon Spaces > Spatial Meshing.

Spatial Meshing Feature Group

ARMeshManager (Script)

The AR Mesh Manager component must be attached to a child of the XR Origin Game Object. For more information about what AR Foundation's AR Mesh Manager component does, refer to the Unity documentation.

danger

Attaching an AR Mesh Manager component to the camera object will change the object's Scale from (1, 1, 1) to (10, 10, 10). This will cause rendering issues on headworn devices until the original camera scale is restored.

AR Mesh Manager Component

The AR Mesh Manager component has a reference to a Mesh Filter which will be generated when a mesh is available.

The Spatial Meshing feature provides support for the properties exposed by the AR Mesh Manager as outlined in the table below:

PropertySupportedNotes
DensityNoA warning will be logged in the console when building the application if the value of this property changes from its default of 0.5. The mesh is generated at a fixed resolution.
NormalsYesNormals will be generated on the CPU when this is enabled.
TangentsNoA warning will be logged in the console when building the application if this is enabled.
Texture CoordinatesNoA warning will be logged in the console when building the application if this is enabled.
ColorsNoA warning will be logged in the console when building the application if this is enabled.
Concurrent Queue SizeSee NoteA warning will be logged in the console when building the application if the value of this property changes from its default of 4. Only 1 mesh is generated by the Snapdragon Spaces Meshing Provider, so changing this has no effect.

By subscribing to the AR Mesh Manager component's meshesChanged callback, data can be retrieved about when a mesh is added, updated or removed.

Sample Code

    private ARMeshManager _meshManager;

public void Awake() {
_meshManager = FindObjectOfType<ARMeshManager>();
}

public override void OnEnable() {
...
_meshManager.meshesChanged += OnMeshesChanged;
}

public override void OnDisable() {
...
_meshManager.meshesChanged -= OnMeshesChanged;
}

void OnMeshesChanged(ARMeshesChangedEventArgs args) {
foreach (MeshFilter meshFilter in args.added) {
...
}

foreach (MeshFilter meshFilter in args.updated) {
...
}

foreach (MeshFilter meshFilter in args.removed) {
...
}
}

Limitations

  • Transparent objects such as windows are difficult to detect. When objects cannot be detected holes will appear in the mesh.
  • Highly reflective or glossy surfaces such as mirrors can be confusing. Mesh can appear to be detected behind or inside these surfaces.
  • Generated mesh will be less precise for more distant objects. Mesh will be generated up to a distance of approximately 5 meters from the user.
  • It can be challenging to generate mesh in poor light conditions, or in an environment where lighting conditions are rapidly changing (e.g. under strobe lights).
  • Mesh updates occur at fixed intervals of approximately 1500 milliseconds.