A common question when working with Spatial Awareness (aka Spatial Mapping) in MRTK is how to access the spatial observers to configure them individually.
The question arises since the GetObserver methods of the IMixedRealitySpatialAwarenessSystem interface are marked as obsolete.
The version 2.0.0 release of MRTK has standardized the pattern for accessing data providers across services in order to
The following example demonstrates this pattern to access spatial awareness mesh observers.
if (CoreServices.SpatialAwarenessSystem != null)
{
IMixedRealityDataProviderAccess dataProviderAccess =
CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess;
if (dataProviderAccess != null)
{
IReadOnlyList<IMixedRealitySpatialAwarenessMeshObserver> observers =
dataProviderAccess.GetDataProviders<IMixedRealitySpatialAwarenessMeshObserver>();
// Modify the observer(s)
foreach (IMixedRealitySpatialAwarenessMeshObserver observer in observers)
{
// Set the mesh to use the occlusion material
observer.DisplayOption = SpatialMeshDisplayOptions.Occlusion;
}
}
}