Skip to content

Commit 7d84217

Browse files
authored
Merge pull request #9390 from MaxWang-MS/su_2.6
Fix issues associated with the new SU package
2 parents dc5660c + 26c7be2 commit 7d84217

File tree

8 files changed

+89
-90
lines changed

8 files changed

+89
-90
lines changed

Assets/MRTK/Examples/Experimental/SceneUnderstanding/Scenes/SceneUnderstandingExample.unity

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,7 +3831,7 @@ MonoBehaviour:
38313831
m_OnCullStateChanged:
38323832
m_PersistentCalls:
38333833
m_Calls: []
3834-
m_text: HoloLens 2 Only
3834+
m_text: HoloLens 2 & Unity 2019.4+ Only
38353835
m_isRightToLeft: 0
38363836
m_fontAsset: {fileID: 11400000, guid: f137eba12ee10834cb19632437cfdb2e, type: 2}
38373837
m_sharedMaterial: {fileID: 21433621844796372, guid: f137eba12ee10834cb19632437cfdb2e,
@@ -3901,10 +3901,10 @@ MonoBehaviour:
39013901
m_margin: {x: -0.4731984, y: 0.000020836515, z: -0.99050045, w: 1.3652543}
39023902
m_textInfo:
39033903
textComponent: {fileID: 1155140273}
3904-
characterCount: 15
3904+
characterCount: 31
39053905
spriteCount: 0
3906-
spaceCount: 2
3907-
wordCount: 3
3906+
spaceCount: 5
3907+
wordCount: 6
39083908
linkCount: 0
39093909
lineCount: 1
39103910
pageCount: 1
@@ -4926,22 +4926,22 @@ PrefabInstance:
49264926
- target: {fileID: 2113875699234556495, guid: 18470d71939382448be2ecd06efa9662,
49274927
type: 3}
49284928
propertyPath: m_textInfo.characterCount
4929-
value: 699
4929+
value: 541
49304930
objectReference: {fileID: 0}
49314931
- target: {fileID: 2113875699234556495, guid: 18470d71939382448be2ecd06efa9662,
49324932
type: 3}
49334933
propertyPath: m_textInfo.spaceCount
4934-
value: 94
4934+
value: 76
49354935
objectReference: {fileID: 0}
49364936
- target: {fileID: 2113875699234556495, guid: 18470d71939382448be2ecd06efa9662,
49374937
type: 3}
49384938
propertyPath: m_textInfo.wordCount
4939-
value: 92
4939+
value: 76
49404940
objectReference: {fileID: 0}
49414941
- target: {fileID: 2113875699234556495, guid: 18470d71939382448be2ecd06efa9662,
49424942
type: 3}
49434943
propertyPath: m_textInfo.lineCount
4944-
value: 18
4944+
value: 13
49454945
objectReference: {fileID: 0}
49464946
- target: {fileID: 2113875699234556495, guid: 18470d71939382448be2ecd06efa9662,
49474947
type: 3}
@@ -4961,14 +4961,10 @@ PrefabInstance:
49614961
49624962
<size=24><b>Important - Required packages</b></size>
49634963
4964-
Use Nuget for Unity tool to get the Dot Net WinRT and SceneUnderstanding packages.
4965-
Please remember to Click Mixed Reality Toolkit -> Utilities -> Windows Mixed
4966-
Reality -> Check Configuration and Mixed Reality Toolkit -> Utilities -> Scene
4967-
Understanding -> Check Configuration after importing those two packages.
4968-
4969-
4970-
Uncheck ''Should Load From File'' in the DemoSceneUnderstandingObserverProfile
4971-
which can be accessed from MRTK''s Spatial Awareness profile.'
4964+
Use MixedReality Feature Tool to get the Dot Net WinRT and Scene Understanding
4965+
packages. The Scene Understanding package may not be available at MRTK 2.6
4966+
launch time but will be released soon after. Please check issue #9402 on the
4967+
MRTK-Unity GitHub repository for updates on its availability.'
49724968
objectReference: {fileID: 0}
49734969
- target: {fileID: 2113875699234556495, guid: 18470d71939382448be2ecd06efa9662,
49744970
type: 3}
@@ -6250,8 +6246,8 @@ Transform:
62506246
m_PrefabAsset: {fileID: 0}
62516247
m_GameObject: {fileID: 2139668523}
62526248
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
6253-
m_LocalPosition: {x: 0.11993182, y: 0.08893815, z: -0.018035235}
6254-
m_LocalScale: {x: 0.08666847, y: 0.016785234, z: 0.04809894}
6249+
m_LocalPosition: {x: 0.0793, y: 0.08893815, z: -0.018}
6250+
m_LocalScale: {x: 0.168, y: 0.016785234, z: 0.04809894}
62556251
m_Children: []
62566252
m_Father: {fileID: 615958088}
62576253
m_RootOrder: 1

Assets/MRTK/Providers/Experimental/WindowsSceneUnderstanding/Editor/MRTK.WSU.Editor.asmdef

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
"overrideReferences": false,
1616
"precompiledReferences": [],
1717
"autoReferenced": true,
18-
"defineConstraints": []
18+
"defineConstraints": [
19+
"UNITY_2019_4_OR_NEWER"
20+
],
21+
"versionDefines": [],
22+
"noEngineReferences": false
1923
}

Assets/MRTK/Providers/Experimental/WindowsSceneUnderstanding/Editor/WindowsSceneUnderstandingConfigChecker.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

Assets/MRTK/Providers/Experimental/WindowsSceneUnderstanding/Editor/WindowsSceneUnderstandingConfigChecker.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/MRTK/Providers/Experimental/WindowsSceneUnderstanding/MRTK.WSU.asmdef

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"references": [
44
"Microsoft.MixedReality.Toolkit",
55
"Microsoft.MixedReality.Toolkit.Async",
6-
"Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared"
6+
"Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared",
7+
"Microsoft.MixedReality.SceneUnderstanding.Projections.Editor",
8+
"Microsoft.MixedReality.SceneUnderstanding.Projections.WSA"
79
],
810
"optionalUnityReferences": [],
911
"includePlatforms": [
@@ -15,5 +17,15 @@
1517
"overrideReferences": false,
1618
"precompiledReferences": [],
1719
"autoReferenced": true,
18-
"defineConstraints": []
20+
"defineConstraints": [
21+
"UNITY_2019_4_OR_NEWER"
22+
],
23+
"versionDefines": [
24+
{
25+
"name": "com.microsoft.mixedreality.sceneunderstanding",
26+
"expression": "",
27+
"define": "SCENE_UNDERSTANDING_PRESENT"
28+
}
29+
],
30+
"noEngineReferences": false
1931
}

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

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@
3131

3232
namespace Microsoft.MixedReality.Toolkit.WindowsSceneUnderstanding.Experimental
3333
{
34+
/// <summary>
35+
/// A Spatial Awareness observer with Scene Understanding capabilities.
36+
/// </summary>
37+
/// <remarks>
38+
/// Only works with HoloLens 2 and Unity 2019.4+
39+
/// </remarks>
3440
[MixedRealityDataProvider(
3541
typeof(IMixedRealitySpatialAwarenessSystem),
3642
SupportedPlatforms.WindowsUniversal,
3743
"Windows Scene Understanding Observer",
3844
"Experimental/WindowsSceneUnderstanding/Profiles/DefaultSceneUnderstandingObserverProfile.asset",
3945
"MixedRealityToolkit.Providers",
4046
true)]
47+
[HelpURL("https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/spatial-awareness/scene-understanding")]
4148
public class WindowsSceneUnderstandingObserver :
4249
BaseSpatialObserver,
4350
IMixedRealitySceneUnderstandingObserver
@@ -97,25 +104,33 @@ private void ReadProfile()
97104
OrientScene = profile.OrientScene;
98105
}
99106

100-
#if SCENE_UNDERSTANDING_PRESENT
101-
102107
#region IMixedRealityService
103108

109+
#if SCENE_UNDERSTANDING_PRESENT
110+
104111
/// <inheritdoc />
105112
public override void Reset()
106113
{
107114
CleanupObserver();
108115
Initialize();
109116
}
110117

118+
#endif // SCENE_UNDERSTANDING_PRESENT
119+
111120
/// <inheritdoc />
112121
public override void Initialize()
113122
{
123+
#if !SCENE_UNDERSTANDING_PRESENT
124+
if (Application.isPlaying)
125+
{
126+
Debug.LogWarning("The required package Microsoft.MixedReality.SceneUnderstanding is not installed or properly configured. Please visit https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/spatial-awareness/scene-understanding for more information.");
127+
}
128+
#else
114129
base.Initialize();
115130
sceneEventData = new MixedRealitySpatialAwarenessEventData<SpatialAwarenessSceneObject>(EventSystem.current);
116131
CreateQuadFromExtents(normalizedQuadMesh, 1, 1);
117132

118-
var accessStatus = SceneObserver.RequestAccessAsync().GetAwaiter().GetResult();
133+
SceneObserverAccessStatus accessStatus = Task.Run(RequestAccess).GetAwaiter().GetResult();
119134
if (accessStatus == SceneObserverAccessStatus.Allowed)
120135
{
121136
IsRunning = true;
@@ -131,20 +146,25 @@ public override void Initialize()
131146
{
132147
observerState = ObserverState.GetScene;
133148
}
149+
#endif // SCENE_UNDERSTANDING_PRESENT
134150
}
135151

136152
/// <inheritdoc />
137153
public override void Enable()
138154
{
155+
#if SCENE_UNDERSTANDING_PRESENT
156+
base.Enable();
139157
// Terminate the background thread when we stop in editor.
140158
cancelToken = cancelTokenSource.Token;
141159

142-
// there is odd behavior with WaitForBackgroundTask
143-
// it will sometimes run on the main thread unless we start it this way
144-
task = RunObserverAsync(cancelToken);
145-
task.ConfigureAwait(true);
160+
task = Task.Run(() => RunObserverAsync(cancelToken));
161+
#else
162+
IsEnabled = false;
163+
#endif // SCENE_UNDERSTANDING_PRESENT
146164
}
147165

166+
#if SCENE_UNDERSTANDING_PRESENT
167+
148168
/// <inheritdoc />
149169
public override void Update()
150170
{
@@ -171,8 +191,12 @@ public override void Destroy()
171191
CleanupObserver();
172192
}
173193

194+
#endif // SCENE_UNDERSTANDING_PRESENT
195+
174196
#endregion IMixedRealityService
175197

198+
#if SCENE_UNDERSTANDING_PRESENT
199+
176200
#region BaseService
177201

178202
/// <inheritdoc />
@@ -280,7 +304,7 @@ public IReadOnlyDictionary<int, SpatialAwarenessSceneObject> SceneObjects
280304
public void SaveScene(string filenamePrefix)
281305
{
282306
#if WINDOWS_UWP && SCENE_UNDERSTANDING_PRESENT
283-
SaveToFile(filenamePrefix);
307+
Task.Run(() => SaveToFile(filenamePrefix));
284308
#else // WINDOWS_UWP
285309
Debug.LogWarning("SaveScene() only supported at runtime! Ignoring request.");
286310
#endif // WINDOWS_UWP
@@ -523,6 +547,11 @@ protected virtual void SendSceneObjectRemoved(int id)
523547
SpatialAwarenessSystem?.HandleEvent(sceneEventData, OnSceneObjectRemoved);
524548
}
525549

550+
private async Task<SceneObserverAccessStatus> RequestAccess()
551+
{
552+
return await SceneObserver.RequestAccessAsync();
553+
}
554+
526555
/// <summary>
527556
/// Sets up and starts update timers
528557
/// </summary>
@@ -630,7 +659,7 @@ private async Task RunObserverAsync(CancellationToken cancellationToken)
630659
}
631660
await new WaitForBackgroundThread();
632661
{
633-
scene = GetSceneAsync(previousScene);
662+
scene = await GetSceneAsync(previousScene);
634663
previousScene = scene;
635664
sceneOriginId = scene.OriginSpatialGraphNodeId;
636665
}
@@ -761,7 +790,7 @@ private System.Numerics.Matrix4x4 GetSceneToWorldTransform()
761790
/// </summary>
762791
/// <param name="previousScene">The previous scene</param>
763792
/// <returns>The retrieved scene</returns>
764-
private Scene GetSceneAsync(Scene previousScene)
793+
private async Task<Scene> GetSceneAsync(Scene previousScene)
765794
{
766795
Scene scene = null;
767796

@@ -795,18 +824,13 @@ private Scene GetSceneAsync(Scene previousScene)
795824
RequestedMeshLevelOfDetail = LevelOfDetailToMeshLOD(WorldMeshLevelOfDetail)
796825
};
797826

798-
// Ideally you'd call SceneObserver.ComputeAsync() like this:
799-
// scene = await SceneObserver.ComputeAsync(...);
800-
// however this has been problematic (buggy?)
801-
// For the time being we force it to be synchronous with the ...GetAwaiter().GetResult() pattern
802-
803827
if (UsePersistentObjects && previousScene != null)
804828
{
805-
scene = SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius, previousScene).GetAwaiter().GetResult();
829+
scene = await SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius, previousScene);
806830
}
807831
else
808832
{
809-
scene = SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius).GetAwaiter().GetResult();
833+
scene = await SceneObserver.ComputeAsync(sceneQuerySettings, QueryRadius);
810834
}
811835
}
812836

@@ -1301,7 +1325,7 @@ private async void SaveToFile(string prefix)
13011325
RequestedMeshLevelOfDetail = LevelOfDetailToMeshLOD(WorldMeshLevelOfDetail)
13021326
};
13031327

1304-
var serializedScene = SceneObserver.ComputeSerializedAsync(sceneQuerySettings, QueryRadius).GetAwaiter().GetResult();
1328+
var serializedScene = await SceneObserver.ComputeSerializedAsync(sceneQuerySettings, QueryRadius);
13051329
var bytes = new byte[serializedScene.Size];
13061330
serializedScene.GetData(bytes);
13071331
var timestamp = DateTime.Now.ToString("yyyyMMdd_hhmmss");

Documentation/ReleaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ see our updated [Input Simulation Service documentation](InputSimulation/InputSi
4545

4646
![Teleport Gesture](Images/ReleaseNotes/HandTeleport.gif)
4747

48+
### Scene Understanding now available in MRTK as an experimental spatial awareness observer
49+
50+
Experimental support of [Scene Understanding](https://docs.microsoft.com/en-us/windows/mixed-reality/scene-understanding) is introduced in MRTK 2.6. Users can incorporate the scene understanding capabilities of HoloLens 2 as a spatial awareness observer in MRTK based projects. Please read the [Scene Understanding documentation](SpatialAwareness/SceneUnderstanding.md) for more information.
51+
52+
> [!IMPORTANT]
53+
> Scene Understanding is only supported on HoloLens 2 and Unity 2019.4 and higher.
54+
>
55+
> This feature requires the Scene Understanding package, which may not be available at the launch date of MRTK 2.6 but will be available soon after via the [Mixed Reality Feature Tool](https://aka.ms/MRFeatureTool). Please see [this issue](https://github.com/microsoft/MixedRealityToolkit-Unity/issues/9402) for updates on its availability.
56+
4857
### Runtime profile switching support
4958

5059
MRTK now allows profile switching both before the initialization of the MRTK instance (i.e. Pre MRTK initialization profile switch) and after a profile has been in active use (i.e. Active profile switch). The former switch can be used to enable select components based on capabilities of the hardware, while the latter can be used to modify experience as the user enters a subpart of the application. Please read the [documentation on profile switching](MixedRealityConfigurationGuide.md#changing-profiles-at-runtime) for more information and code samples.

Documentation/SpatialAwareness/SceneUnderstanding.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Some expected use cases of this technology are:
88
* Provide physics engine friendly geometry as quads
99
* Accelerate development by avoiding the need to write similar algorithms
1010

11-
Currently Scene Understanding is available as an __experimental__ feature. It is integrated into MRTK as a [spatial observer](SpatialAwarenessGettingStarted.md#register-observers) called [`WindowsSceneUnderstandingObserver`](xref:Microsoft.MixedReality.Toolkit.WindowsSceneUnderstanding.Experimental.WindowsSceneUnderstandingObserver).
11+
Currently Scene Understanding is available as an __experimental__ feature. It is integrated into MRTK as a [spatial observer](SpatialAwarenessGettingStarted.md#register-observers) called [`WindowsSceneUnderstandingObserver`](xref:Microsoft.MixedReality.Toolkit.WindowsSceneUnderstanding.Experimental.WindowsSceneUnderstandingObserver). Scene Understanding works both with the Legacy XR pipeline and the XR SDK pipeline. In both cases the `WindowsSceneUnderstandingObserver` is used.
1212

1313
## Observer overview
1414

@@ -17,10 +17,7 @@ When asked, the [`WindowsSceneUnderstandingObserver`](xref:Microsoft.MixedRealit
1717
## Setup
1818

1919
1. Ensure the platform is set to UWP in build settings.
20-
1. Ensure dotnetwinrt is installed.
21-
1. Acquire the SceneUnderstanding package that contains the binaries required for the feature
22-
1. In the menu bar click Mixed Reality Toolkit -> Utilities -> Windows Mixed Reality -> Check Configuration (this operation may take a while)
23-
1. In the menu bar click Mixed Reality Toolkit -> Utilities -> Scene Understanding -> Check Configuration (this operation may take a while)
20+
1. Acquire the Scene Understanding package via [Mixed Reality Feature Tool](https://aka.ms/MRFeatureTool). Note the package may not be available at the launch date of MRTK 2.6 but will be available soon after. Please see [this issue](https://github.com/microsoft/MixedRealityToolkit-Unity/issues/9402) for updates on its availability.
2421

2522
## Using Scene Understanding
2623

@@ -37,6 +34,9 @@ The scene demonstrates the following:
3734
* Saving scene data to device for offline development
3835
* Loading previously saved scene data (.bytes files) to support in-editor development workflow
3936

37+
> [!NOTE]
38+
> The sample scene is based on the Legacy XR pipeline. If you are using the XR SDK pipeline you should modify the profiles accordingly. The provided Scene Understanding Spatial Awareness System profile (`DemoSceneUnderstandingSystemProfile`) and the Scene Understanding Observer profiles (`DefaultSceneUnderstandingObserverProfile` and `DemoSceneUnderstandingObserverProfile`) works for both pipelines.
39+
4040
#### Configuring the observer service
4141

4242
Select the 'MixedRealityToolkit' game object and check the inspector.

0 commit comments

Comments
 (0)