Skip to content

Commit 08d2f92

Browse files
author
David Kline (ANALOG)
committed
implement isStationaryObserver, change default extents
1 parent 8578d80 commit 08d2f92

File tree

10 files changed

+64
-66
lines changed

10 files changed

+64
-66
lines changed

Assets/MixedRealityToolkit-Examples/Demos/SpatialAwareness/Scenes/SpatialAwarenessMeshDemo.unity

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ Prefab:
168168
your environment as a wireframe mesh.
169169
170170
171-
Glance around your space and watch the mesh data appear.'
171+
Move around your space and watch the mesh data appear.
172+
173+
174+
As you move, meshes will appear in front of you and disappear behind you. '
172175
objectReference: {fileID: 0}
173176
- target: {fileID: 114713125240876806, guid: a900c08743a94c328074df8bbe3eb63c,
174177
type: 2}

Assets/MixedRealityToolkit-Examples/Demos/SpatialAwareness/Scripts.meta

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

Assets/MixedRealityToolkit-Examples/Demos/SpatialAwareness/Scripts/SpatialObserverMover.cs

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

Assets/MixedRealityToolkit-Examples/Demos/SpatialAwareness/Scripts/SpatialObserverMover.cs.meta

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

Assets/MixedRealityToolkit-SDK/Features/SpatialAwareness/System/MixedRealitySpatialAwarenessSystem.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private void InitializeInternal()
9696
// General settings
9797
StartupBehavior = MixedRealityManager.Instance.ActiveProfile.SpatialAwarenessProfile.StartupBehavior;
9898
ObservationExtents = MixedRealityManager.Instance.ActiveProfile.SpatialAwarenessProfile.ObservationExtents;
99+
IsStationaryObserver = MixedRealityManager.Instance.ActiveProfile.SpatialAwarenessProfile.IsStationaryObserver;
99100
UpdateInterval = MixedRealityManager.Instance.ActiveProfile.SpatialAwarenessProfile.UpdateInterval;
100101

101102
// Mesh settings
@@ -373,7 +374,10 @@ public int GetHashCode(object obj)
373374
public AutoStartBehavior StartupBehavior { get; set; } = AutoStartBehavior.AutoStart;
374375

375376
/// <inheritdoc />
376-
public Vector3 ObservationExtents { get; set; } = Vector3.one * 10;
377+
public Vector3 ObservationExtents { get; set; } = Vector3.one * 3;
378+
379+
/// <inheritdoc />
380+
public bool IsStationaryObserver { get; set; } = false;
377381

378382
/// <inheritdoc />
379383
public Vector3 ObserverOrigin { get; set; } = Vector3.zero;

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealitySpatialAwarenessProfile.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ MonoBehaviour:
1313
m_EditorClassIdentifier:
1414
isCustomProfile: 0
1515
startupBehavior: 0
16-
observationExtents: {x: 10, y: 10, z: 10}
16+
observationExtents: {x: 3, y: 3, z: 3}
17+
isStationaryObserver: 0
1718
updateInterval: 3.5
1819
useMeshSystem: 1
1920
meshPhysicsLayer: 31

Assets/MixedRealityToolkit/_Core/Definitions/SpatialAwareness/MixedRealitySpatialAwarenessProfile.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ public class MixedRealitySpatialAwarenessProfile : BaseMixedRealityProfile
2525

2626
[SerializeField]
2727
[Tooltip("The dimensions of the spatial observer volume, in meters.")]
28-
private Vector3 observationExtents = new Vector3(10f, 10f, 10f);
28+
private Vector3 observationExtents = Vector3.one * 3;
2929

3030
/// <summary>
3131
/// The size of the volume, in meters per axis, from which individual observations will be made.
3232
/// </summary>
3333
public Vector3 ObservationExtents => observationExtents;
3434

35+
[SerializeField]
36+
[Tooltip("Should the spatial observer remain in a fixed location?")]
37+
private bool isStationaryObserver = false;
38+
39+
/// <summary>
40+
/// The size of the volume, in meters per axis, from which individual observations will be made.
41+
/// </summary>
42+
public bool IsStationaryObserver => isStationaryObserver;
43+
3544
[SerializeField]
3645
[Tooltip("How often, in seconds, should the spatial observer update?")]
3746
private float updateInterval = 3.5f;

Assets/MixedRealityToolkit/_Core/Devices/MixedReality/WindowsMixedRealitySpatialObserver.cs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
using Microsoft.MixedReality.Toolkit.Core.Definitions.SpatialAwarenessSystem;
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
6+
using Microsoft.MixedReality.Toolkit.Core.Interfaces.SpatialAwarenessSystem;
67
using Microsoft.MixedReality.Toolkit.Core.Managers;
8+
using Microsoft.MixedReality.Toolkit.Core.Utilities;
79
using UnityEngine;
810
using System.Collections.Generic;
911

1012
#if UNITY_WSA
1113
using UnityEngine.XR.WSA;
1214
#endif // UNITY_WSA
1315

14-
using UnityEngine.UI;
15-
1616
namespace Microsoft.MixedReality.Toolkit.Core.Devices.SpatialAwareness
1717
{
1818
public class WindowsMixedRealitySpatialObserver : BaseSpatialObserver
@@ -82,6 +82,13 @@ public override void Destroy()
8282

8383
#region IMixedRealitySpatialAwarenessObserver implementation
8484

85+
private IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem = null;
86+
87+
/// <summary>
88+
/// The currently active instance of <see cref="IMixedRealitySpatialAwarenessSystem"/>.
89+
/// </summary>
90+
private IMixedRealitySpatialAwarenessSystem SpatialAwarenessSystem => spatialAwarenessSystem ?? (spatialAwarenessSystem = MixedRealityManager.SpatialAwarenessSystem);
91+
8592
#if UNITY_WSA
8693
/// <summary>
8794
/// The surface observer providing the spatial data.
@@ -181,12 +188,14 @@ public override void StopObserving()
181188
/// </summary>
182189
private void CreateObserver()
183190
{
191+
if (SpatialAwarenessSystem == null) { return; }
192+
184193
if (observer == null)
185194
{
186195
observer = new SurfaceObserver();
187196
ConfigureObserverVolume();
188197

189-
if (MixedRealityManager.Instance.ActiveProfile.SpatialAwarenessProfile.StartupBehavior == AutoStartBehavior.AutoStart)
198+
if (SpatialAwarenessSystem.StartupBehavior == AutoStartBehavior.AutoStart)
190199
{
191200
StartObserving();
192201
}
@@ -239,6 +248,8 @@ private void CleanupObserver()
239248
/// </summary>
240249
private void UpdateObserver()
241250
{
251+
if (SpatialAwarenessSystem == null) { return; }
252+
242253
// Only update the observer if it is running.
243254
if (IsRunning && !outstandingMeshObject.HasValue)
244255
{
@@ -250,8 +261,14 @@ private void UpdateObserver()
250261
RequestMesh(meshWorkQueue.Dequeue());
251262
}
252263
// If enough time has passed since the previous observer update...
253-
else if (Time.time - lastUpdated >= MixedRealityManager.Instance.ActiveProfile.SpatialAwarenessProfile.UpdateInterval)
264+
else if (Time.time - lastUpdated >= SpatialAwarenessSystem.UpdateInterval)
254265
{
266+
// Update the observer location if it is not stationary
267+
if (!SpatialAwarenessSystem.IsStationaryObserver)
268+
{
269+
SpatialAwarenessSystem.ObserverOrigin = CameraCache.Main.transform.position;
270+
}
271+
255272
// The application can update the observer volume at any time, make sure we are using the latest.
256273
ConfigureObserverVolume();
257274

@@ -269,7 +286,6 @@ private void RequestMesh(SurfaceId surfaceId)
269286
{
270287
string meshName = ("SpatialMesh - " + surfaceId.handle);
271288

272-
// todo:
273289
SpatialMeshObject newMesh;
274290
WorldAnchor worldAnchor;
275291

@@ -298,7 +314,7 @@ private void RequestMesh(SurfaceId surfaceId)
298314
newMesh.Filter,
299315
worldAnchor,
300316
newMesh.Collider,
301-
MixedRealityManager.SpatialAwarenessSystem.MeshTrianglesPerCubicMeter,
317+
SpatialAwarenessSystem.MeshTrianglesPerCubicMeter,
302318
true);
303319

304320
if (observer.RequestMeshAsync(surfaceData, SurfaceObserver_OnDataReady))
@@ -331,7 +347,7 @@ protected void RemoveMeshObject(int id)
331347
ReclaimMeshObject(mesh);
332348

333349
// Send the mesh removed event
334-
MixedRealityManager.SpatialAwarenessSystem.RaiseMeshRemoved(id);
350+
SpatialAwarenessSystem.RaiseMeshRemoved(id);
335351
}
336352
}
337353

@@ -365,8 +381,8 @@ protected void ReclaimMeshObject(SpatialMeshObject availableMeshObject)
365381
/// </summary>
366382
private void ConfigureObserverVolume()
367383
{
368-
Vector3 newExtents = MixedRealityManager.SpatialAwarenessSystem.ObservationExtents;
369-
Vector3 newOrigin = MixedRealityManager.SpatialAwarenessSystem.ObserverOrigin;
384+
Vector3 newExtents = SpatialAwarenessSystem.ObservationExtents;
385+
Vector3 newOrigin = SpatialAwarenessSystem.ObserverOrigin;
370386

371387
if (currentObserverExtents.Equals(newExtents) &&
372388
currentObserverOrigin.Equals(newOrigin))
@@ -434,21 +450,21 @@ private void SurfaceObserver_OnDataReady(SurfaceData cookedData, bool outputWrit
434450
outstandingMeshObject = null;
435451

436452
// Apply the appropriate material to the mesh.
437-
SpatialMeshDisplayOptions displayOption = MixedRealityManager.SpatialAwarenessSystem.MeshDisplayOption;
453+
SpatialMeshDisplayOptions displayOption = SpatialAwarenessSystem.MeshDisplayOption;
438454
if (displayOption != SpatialMeshDisplayOptions.None)
439455
{
440456
meshObject.Renderer.enabled = true;
441457
meshObject.Renderer.sharedMaterial = (displayOption == SpatialMeshDisplayOptions.Visible) ?
442-
MixedRealityManager.SpatialAwarenessSystem.MeshVisibleMaterial :
443-
MixedRealityManager.SpatialAwarenessSystem.MeshOcclusionMaterial;
458+
SpatialAwarenessSystem.MeshVisibleMaterial :
459+
SpatialAwarenessSystem.MeshOcclusionMaterial;
444460
}
445461
else
446462
{
447463
meshObject.Renderer.enabled = false;
448464
}
449465

450466
// Recalculate the mesh normals if requested.
451-
if (MixedRealityManager.SpatialAwarenessSystem.MeshRecalculateNormals)
467+
if (SpatialAwarenessSystem.MeshRecalculateNormals)
452468
{
453469
meshObject.Filter.sharedMesh.RecalculateNormals();
454470
}
@@ -468,11 +484,11 @@ private void SurfaceObserver_OnDataReady(SurfaceData cookedData, bool outputWrit
468484

469485
if (sendUpdatedEvent)
470486
{
471-
MixedRealityManager.SpatialAwarenessSystem.RaiseMeshUpdated(cookedData.id.handle, meshObject.GameObject);
487+
SpatialAwarenessSystem.RaiseMeshUpdated(cookedData.id.handle, meshObject.GameObject);
472488
}
473489
else
474490
{
475-
MixedRealityManager.SpatialAwarenessSystem.RaiseMeshAdded(cookedData.id.handle, meshObject.GameObject);
491+
SpatialAwarenessSystem.RaiseMeshAdded(cookedData.id.handle, meshObject.GameObject);
476492
}
477493
}
478494
#endif // UNITY_WSA

Assets/MixedRealityToolkit/_Core/Inspectors/Profiles/MixedRealitySpatialAwarenessProfileInspector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class MixedRealitySpatialAwarenessProfileInspector : MixedRealityBaseConf
1515
// General settings
1616
private SerializedProperty startupBehavior;
1717
private SerializedProperty observationExtents;
18+
private SerializedProperty isStationaryObserver;
1819
private SerializedProperty updateInterval;
1920

2021
// Mesh settings
@@ -64,6 +65,7 @@ private void OnEnable()
6465
// General settings
6566
startupBehavior = serializedObject.FindProperty("startupBehavior");
6667
observationExtents = serializedObject.FindProperty("observationExtents");
68+
isStationaryObserver = serializedObject.FindProperty("isStationaryObserver");
6769
updateInterval = serializedObject.FindProperty("updateInterval");
6870

6971
// Mesh settings
@@ -118,6 +120,7 @@ public override void OnInspectorGUI()
118120
EditorGUILayout.LabelField("General Settings:", EditorStyles.boldLabel);
119121
EditorGUILayout.PropertyField(startupBehavior);
120122
EditorGUILayout.PropertyField(observationExtents);
123+
EditorGUILayout.PropertyField(isStationaryObserver);
121124
EditorGUILayout.PropertyField(updateInterval);
122125

123126
EditorGUILayout.Space();

Assets/MixedRealityToolkit/_Core/Interfaces/SpatialAwareness/IMixedRealitySpatialAwarenessSystem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public interface IMixedRealitySpatialAwarenessSystem : IMixedRealityEventSystem,
2525
/// </summary>
2626
Vector3 ObservationExtents { get; set; }
2727

28+
/// <summary>
29+
/// Should the observer remain stationary in the scene?
30+
/// </summary>
31+
/// <remarks>
32+
/// Set IsStationaryObserver set to false, to move the volume with the user.
33+
/// If set to true, the origin will be 0,0,0 or the last known location.
34+
/// </remarks>
35+
bool IsStationaryObserver { get; set; }
36+
2837
/// <summary>
2938
/// Gets or sets the origin of the observer.
3039
/// </summary>

0 commit comments

Comments
 (0)