Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

dev/spatial-awareness-refactor #281

Merged
merged 10 commits into from
Aug 16, 2019
2 changes: 1 addition & 1 deletion Submodules/SDK
Submodule SDK updated from 6f2898 to 681ce8
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine;
using XRTK.Definitions.Utilities;
using XRTK.Interfaces.Providers.SpatialObservers;
using XRTK.Providers.SpatialObservers;

namespace XRTK.Definitions.SpatialAwarenessSystem
{
Expand Down Expand Up @@ -31,5 +32,14 @@ public class MixedRealitySpatialAwarenessSystemProfile : BaseMixedRealityProfile
/// The list of registered <see cref="IMixedRealitySpatialObserverDataProvider"/>s.
/// </summary>
public SpatialObserverDataProviderConfiguration[] RegisteredSpatialObserverDataProviders => registeredSpatialObserverDataProviders;

[SerializeField]
[Tooltip("Indicates how the BaseMixedRealitySpatialMeshObserver is to display surface meshes within the application.")]
private SpatialMeshDisplayOptions meshDisplayOption = SpatialMeshDisplayOptions.None;

/// <summary>
/// Indicates how the <see cref="BaseMixedRealitySpatialMeshObserver"/> is to display surface meshes within the application.
/// </summary>
public SpatialMeshDisplayOptions MeshDisplayOption => meshDisplayOption;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ public abstract class BaseMixedRealitySpatialMeshObserverProfile : BaseMixedReal
/// </summary>
public bool MeshRecalculateNormals => meshRecalculateNormals;

[SerializeField]
[Tooltip("How should spatial meshes be displayed?")]
private SpatialMeshDisplayOptions meshDisplayOption = SpatialMeshDisplayOptions.None;

/// <summary>
/// Indicates how the mesh subsystem is to display surface meshes within the application.
/// </summary>
public SpatialMeshDisplayOptions MeshDisplayOption => meshDisplayOption;

[SerializeField]
[Tooltip("Material to use when displaying meshes")]
private Material meshVisibleMaterial = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public abstract class BaseMixedRealitySpatialMeshObserverProfileInspector : Base
private SerializedProperty meshLevelOfDetail;
private SerializedProperty meshTrianglesPerCubicMeter;
private SerializedProperty meshRecalculateNormals;
private SerializedProperty meshDisplayOption;
private SerializedProperty meshVisibleMaterial;
private SerializedProperty meshOcclusionMaterial;
private SerializedProperty additionalComponents;
Expand All @@ -30,7 +29,6 @@ protected override void OnEnable()
meshLevelOfDetail = serializedObject.FindProperty("meshLevelOfDetail");
meshTrianglesPerCubicMeter = serializedObject.FindProperty("meshTrianglesPerCubicMeter");
meshRecalculateNormals = serializedObject.FindProperty("meshRecalculateNormals");
meshDisplayOption = serializedObject.FindProperty("meshDisplayOption");
meshVisibleMaterial = serializedObject.FindProperty("meshVisibleMaterial");
meshOcclusionMaterial = serializedObject.FindProperty("meshOcclusionMaterial");
additionalComponents = serializedObject.FindProperty("additionalComponents");
Expand All @@ -53,7 +51,6 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(meshLevelOfDetail);
EditorGUILayout.PropertyField(meshTrianglesPerCubicMeter);
EditorGUILayout.PropertyField(meshRecalculateNormals);
EditorGUILayout.PropertyField(meshDisplayOption);
EditorGUILayout.PropertyField(meshVisibleMaterial);
EditorGUILayout.PropertyField(meshOcclusionMaterial);
EditorGUILayout.PropertyField(additionalComponents, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MixedRealitySpatialAwarenessSystemProfileInspector : BaseMixedReali
private static readonly GUIContent SpatialObserverMinusButtonContent = new GUIContent("-", "Remove Spatial Observer");

private SerializedProperty registeredSpatialObserverDataProviders;
private SerializedProperty meshDisplayOption;

private bool[] foldouts = null;

Expand All @@ -24,6 +25,7 @@ protected override void OnEnable()
base.OnEnable();

registeredSpatialObserverDataProviders = serializedObject.FindProperty("registeredSpatialObserverDataProviders");
meshDisplayOption = serializedObject.FindProperty("meshDisplayOption");
foldouts = new bool[registeredSpatialObserverDataProviders.arraySize];
}

Expand All @@ -46,6 +48,8 @@ public override void OnInspectorGUI()

thisProfile.CheckProfileLock();

EditorGUILayout.Space();
EditorGUILayout.PropertyField(meshDisplayOption);
EditorGUILayout.Space();

if (GUILayout.Button(SpatialObserverAddButtonContent, EditorStyles.miniButton))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public interface IMixedRealitySpatialAwarenessSystem : IMixedRealityEventSystem
/// </summary>
GameObject SurfacesParent { get; }

/// <summary>
/// Gets or sets the provided mesh <see cref="SpatialMeshDisplayOptions"/> on all the <see cref="DetectedSpatialObservers"/>
/// </summary>
/// <remarks>
/// Is is possible to override any previously set display options on any specific observers.
/// </remarks>
SpatialMeshDisplayOptions SpatialMeshVisibility { get; set; }

#region Observers Utilities

/// <summary>
Expand Down Expand Up @@ -77,12 +85,6 @@ public interface IMixedRealitySpatialAwarenessSystem : IMixedRealityEventSystem

#endregion Observer Events

/// <summary>
/// Sets the provided mesh <see cref="SpatialMeshDisplayOptions"/> on all the <see cref="DetectedSpatialObservers"/>
/// </summary>
/// <param name="displayOptions"></param>
void SetMeshVisibility(SpatialMeshDisplayOptions displayOptions);

#region Mesh Events

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected BaseMixedRealitySpatialMeshObserver(string name, uint priority, BaseMi
MeshLevelOfDetail = profile.MeshLevelOfDetail;
MeshTrianglesPerCubicMeter = profile.MeshTrianglesPerCubicMeter;
MeshRecalculateNormals = profile.MeshRecalculateNormals;
meshDisplayOption = profile.MeshDisplayOption;
meshDisplayOption = MixedRealityToolkit.SpatialAwarenessSystem.SpatialMeshVisibility;
StephenHodgson marked this conversation as resolved.
Show resolved Hide resolved
MeshVisibleMaterial = profile.MeshVisibleMaterial;
MeshOcclusionMaterial = profile.MeshOcclusionMaterial;
ObservationExtents = profile.ObservationExtents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using XRTK.Definitions;
using XRTK.Definitions.SpatialAwarenessSystem;
using XRTK.EventDatum.SpatialAwarenessSystem;
using XRTK.Interfaces.Providers.SpatialObservers;
Expand All @@ -23,8 +22,9 @@ public class MixedRealitySpatialAwarenessSystem : BaseEventSystem, IMixedReality
/// Constructor.
/// </summary>
/// <param name="profile"></param>
public MixedRealitySpatialAwarenessSystem(BaseMixedRealityProfile profile) : base(profile)
public MixedRealitySpatialAwarenessSystem(MixedRealitySpatialAwarenessSystemProfile profile) : base(profile)
{
spatialMeshVisibility = profile.MeshDisplayOption;
}

private GameObject spatialAwarenessParent = null;
Expand Down Expand Up @@ -52,6 +52,26 @@ public MixedRealitySpatialAwarenessSystem(BaseMixedRealityProfile profile) : bas
/// <inheritdoc />
public GameObject SurfacesParent => surfaceParent != null ? surfaceParent : (surfaceParent = CreateSecondGenerationParent("Surfaces"));

/// <inheritdoc />
public SpatialMeshDisplayOptions SpatialMeshVisibility
{
get => spatialMeshVisibility;
set
{
spatialMeshVisibility = value;

foreach (var observer in DetectedSpatialObservers)
{
if (observer is BaseMixedRealitySpatialMeshObserver meshObserver)
{
meshObserver.MeshDisplayOption = spatialMeshVisibility;
}
}
}
}

private SpatialMeshDisplayOptions spatialMeshVisibility;

/// <summary>
/// Creates a parent that is a child of the Spatial Awareness System parent so that the scene hierarchy does not get overly cluttered.
/// </summary>
Expand Down Expand Up @@ -138,18 +158,6 @@ public void RaiseSpatialAwarenessObserverLost(IMixedRealitySpatialObserverDataPr
DetectedSpatialObservers.Remove(observer);
}

/// <inheritdoc />
public void SetMeshVisibility(SpatialMeshDisplayOptions displayOptions)
{
foreach (var observer in DetectedSpatialObservers)
{
if (observer is BaseMixedRealitySpatialMeshObserver meshObserver)
{
meshObserver.MeshDisplayOption = displayOptions;
}
}
}

#endregion IMixedRealitySpatialAwarenessSystem Implementation

#region IMixedRealityService Implementation
Expand Down