Enable/Disable Spatial Mapping at runtime in MRTK2

后端 未结 3 1362
我寻月下人不归
我寻月下人不归 2021-01-25 03:41

With the new MRTK2 I\'m looking to disable spatial mapping after we are done using it to place GameObjects. I\'m stuck on what exactly to call in the namespace or on the service

相关标签:
3条回答
  • 2021-01-25 04:10

    You can use the following code to disable/enable the spatial awareness system:

    if (disable)
    {
        // disable
        MixedRealityToolkit.SpatialAwarenessSystem.Disable();
    }
    else
    {
        // enable
        MixedRealityToolkit.SpatialAwarenessSystem.Enable()
    }
    

    You can use the following code to enable/disable just the visualization but keep the colliders on:

    foreach(var observer in MixedRealityToolkit.SpatialAwarenessSystem.GetObservers())
    {
        var meshObserver = observer as IMixedRealitySpatialAwarenessMeshObserver;
        if (meshObserver != null)
        {
            meshObserver.DisplayOption = SpatialAwarenessMeshDisplayOptions.None;
        }
    }
    

    You can read more documentation about the Spatial Awareness system in MRTK on the mrtk github.io site at Spatial Awareness System Usage guide

    0 讨论(0)
  • 2021-01-25 04:32

    Note the previous answer doesn't work due to recent changes to the MRTK framework.

    Link for SpatialAwareness DataProvidershere

    Code pasted from said link:

    IMixedRealityDataProviderAccess dataProviderAccess =
        CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess;
    
    if (dataProviderAccess != null)
    {
        IReadOnlyList<IMixedRealitySpatialAwarenessMeshObserver> observers =
            dataProviderAccess.GetDataProviders<IMixedRealitySpatialAwarenessMeshObserver>();
    
        foreach (IMixedRealitySpatialAwarenessMeshObserver observer in observers)
        {
            // Set the mesh to use the occlusion material
            observer.DisplayOption = SpatialMeshDisplayOptions.Occlusion;
        }
    }
    
    0 讨论(0)
  • 2021-01-25 04:33

    I would have expected the SuspendObservers() method to result in no new meshes being displayed. Do you see the meshes changing after suspending?

    It is by design for the meshes to remain visible until the application explicitly sets their visibility to None via the IMixedRealitySpatialAwarenessMeshObserver.DisplayOption property.

    Thanks!

    0 讨论(0)
提交回复
热议问题