The Spatial Awareness system provides real-world environmental awareness in mixed reality applications. When introduced on Microsoft HoloLens, spatial awareness provided a collection of meshes, representing the geometry of the environment, which allowed for compelling interactions between holograms and the real-world.
Adding support for spatial awareness requires two key components of the Mixed Reality Toolkit: the spatial awareness system and a supported platform provider.
- Enable the spatial awareness system
- Register and configure one or more spatial observers
- Build and deploy to a platform that supports spatial awareness
Enable Spatial Awareness
The spatial awareness system is managed by the MixedRealityToolkit object (or another service registrar component). The steps below are not necessary for users of the default profile (DefaultMixedRealityToolkitConfigurationProfile) which has this system already enabled. The following steps presume use of the MixedRealityToolkit object. Steps required for other service registrars may be different.
The spatial awareness system is disabled by default on the default HoloLens 2 profile (DefaultHoloLens2ConfigurationProfile), and the intent of this is to avoid the visual overhead of calculating and rendering the meshes.
- Select the MixedRealityToolkit object in the scene hierarchy.
- Navigate the Inspector panel to the Spatial Awareness System section and check Enable Spatial Awareness System
- Select the Spatial Awareness System implementation
Before the spatial awareness system can provide applications with data about the real-world, at least one spatial observer must be registered. Spatial observers are generally platform specific components that may vary in the type(s) of data (ex: meshes) provided.
- Open or expand the Spatial Awareness System profile
- Click "Add Spatial Observer"
- Select the Spatial Observer implementation
Users of the default profile (DefaultMixedRealitSpatialAwarenessSystemProfile) will have the spatial awareness system pre-configured to use the WindowsMixedRealitySpatialMeshObserver from the Mixed Reality Toolkit Windows Mixed Reality Provider package.
Once the spatial observer(s) have been registered with the system, they can be configured to provide the desired data. When configuring a spatial observer, many implementations will auto-populate the observer's configuration profile with common default values.
- Open or expand the Spatial Observer profile
- Configure the desired options
The illustration in the previous step shows the configuration profile for a spatial mesh observer. Please see Configuring the Spatial Awareness Mesh Observer for more information pertaining to the specific settings available to mesh observers. Other observers may have similar settings.
Build and Deploy
Once the spatial awareness system is configured with the desired observer(s), the project can be built and deployed to the target platform.
Some platforms, including Microsoft HoloLens, provide support for remote execution from within Unity. This feature enables rapid development and testing without requiring the build and deploy step. Be sure to do final acceptance testing using a built and deployed version of the application, running on the target hardware and platform.