Skip to content

Commit d61d330

Browse files
MaxWang-MSkeveleigh
authored andcommitted
Merge pull request #10338 from MaxWang-MS/add-openxr-su-remoting
Enable Scene Understanding in remoting via OpenXR
1 parent ebb73c7 commit d61d330

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Assets/MRTK/Providers/Experimental/WindowsSceneUnderstanding/WindowsSceneUnderstandingObserver.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
using System.Threading;
1515
using System.Threading.Tasks;
1616
using Microsoft.MixedReality.SceneUnderstanding;
17-
#if WINDOWS_UWP
18-
using Windows.Perception.Spatial;
19-
using Windows.Perception.Spatial.Preview;
2017
#if MSFT_OPENXR
2118
using Microsoft.MixedReality.OpenXR;
19+
using Microsoft.MixedReality.OpenXR.Remoting;
2220
using Microsoft.MixedReality.Toolkit.XRSDK;
2321
using UnityEngine.XR.OpenXR;
2422
#endif // MSFT_OPENXR
23+
#if WINDOWS_UWP
24+
using Windows.Perception.Spatial;
25+
using Windows.Perception.Spatial.Preview;
2526
#endif // WINDOWS_UWP
2627
using UnityEngine.Assertions;
2728
using UnityEngine.EventSystems;
@@ -129,13 +130,12 @@ public override void Initialize()
129130
}
130131
#else
131132
base.Initialize();
132-
#if WINDOWS_UWP
133133
#if MSFT_OPENXR
134134
isOpenXRLoaderActive = LoaderHelpers.IsLoaderActive<OpenXRLoaderBase>() ?? false;
135-
#else
135+
isOpenXRRemotingConnected = AppRemoting.TryGetConnectionState(out ConnectionState state, out _) && state == ConnectionState.Connected;
136+
#elif WINDOWS_UWP
136137
isOpenXRLoaderActive = false;
137138
#endif // MSFT_OPENXR
138-
#endif // WINDOWS_UWP
139139
sceneEventData = new MixedRealitySpatialAwarenessEventData<SpatialAwarenessSceneObject>(EventSystem.current);
140140
CreateQuadFromExtents(normalizedQuadMesh, 1, 1);
141141

@@ -419,9 +419,12 @@ private enum ObserverState
419419
private System.Numerics.Matrix4x4 sceneToWorldTransformMatrix;
420420
private List<SceneObject> filteredSelectedSurfaceTypesResult = new List<SceneObject>(128);
421421
private Texture defaultTexture;
422-
#if WINDOWS_UWP
422+
#if WINDOWS_UWP || MSFT_OPENXR
423423
private bool isOpenXRLoaderActive;
424-
#endif // WINDOWS_UWP
424+
#endif // WINDOWS_UWP || MSFT_OPENXR
425+
#if MSFT_OPENXR
426+
private bool isOpenXRRemotingConnected;
427+
#endif // MSFT_OPENXR
425428

426429
#endregion Private Fields
427430

@@ -794,8 +797,13 @@ private async Task RunObserverAsync(CancellationToken cancellationToken)
794797
private System.Numerics.Matrix4x4? GetSceneToWorldTransform()
795798
{
796799
var result = System.Numerics.Matrix4x4.Identity;
797-
#if WINDOWS_UWP
800+
#if WINDOWS_UWP // On HoloLens 2 device
798801
if (isOpenXRLoaderActive)
802+
#elif MSFT_OPENXR // In editor and using OpenXR
803+
if (isOpenXRLoaderActive && isOpenXRRemotingConnected && !ShouldLoadFromFile)
804+
#else // All other cases
805+
if (false)
806+
#endif // WINDOWS_UWP
799807
{
800808
#if MSFT_OPENXR
801809
SpatialGraphNode node = SpatialGraphNode.FromStaticNodeId(sceneOriginId);
@@ -811,6 +819,7 @@ private async Task RunObserverAsync(CancellationToken cancellationToken)
811819
}
812820
else
813821
{
822+
#if WINDOWS_UWP
814823
SpatialCoordinateSystem sceneOrigin = SpatialGraphInteropPreview.CreateCoordinateSystemForNode(sceneOriginId);
815824
SpatialCoordinateSystem worldOrigin = WindowsMixedReality.WindowsMixedRealityUtilities.SpatialCoordinateSystem;
816825

@@ -824,8 +833,8 @@ private async Task RunObserverAsync(CancellationToken cancellationToken)
824833
{
825834
return null;
826835
}
827-
}
828836
#endif // WINDOWS_UWP
837+
}
829838
return result;
830839
}
831840

0 commit comments

Comments
 (0)