public override void DrawInspectorGUI(object target)
        {
            IMixedRealitySpatialAwarenessSystem spatial            = (IMixedRealitySpatialAwarenessSystem)target;
            IMixedRealityDataProviderAccess     dataProviderAccess = (IMixedRealityDataProviderAccess)spatial;

            EditorGUILayout.LabelField("Observers", EditorStyles.boldLabel);
            int observerIndex = 0;

            var dataProviders = dataProviderAccess?.GetDataProviders();

            if (dataProviders != null)
            {
                foreach (IMixedRealitySpatialAwarenessObserver observer in dataProviders)
                {
                    GUI.color = observer.IsRunning ? enabledColor : disabledColor;

                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                    {
                        GUI.color = GetObserverColor(observerIndex);
                        GUILayout.Button(observer.Name);
                        GUI.color = observer.IsRunning ? enabledColor : disabledColor;

                        EditorGUILayout.Toggle("Running", observer.IsRunning);
                        EditorGUILayout.LabelField("Source", observer.SourceName);
                        EditorGUILayout.Toggle("Is Stationary", observer.IsStationaryObserver);
                        EditorGUILayout.FloatField("Update Interval", observer.UpdateInterval);

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Volume Properties", EditorStyles.boldLabel);
                        EditorGUILayout.EnumPopup("Volume Type", observer.ObserverVolumeType);
                        EditorGUILayout.Vector3Field("Origin", observer.ObserverOrigin);
                        EditorGUILayout.Vector3Field("Rotation", observer.ObserverRotation.eulerAngles);
                        EditorGUILayout.Vector3Field("Extents", observer.ObservationExtents);
                    }
                    observerIndex++;
                }
            }

            GUI.color = enabledColor;

            if (!Application.isPlaying)
            {
                EditorGUILayout.HelpBox("Observers will be populated once you enter play mode.", MessageType.Info);
            }
            else if (observerIndex == 0)
            {
                EditorGUILayout.LabelField("(None found)", EditorStyles.miniLabel);
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Editor Options", EditorStyles.boldLabel);
            ShowObserverBoundary = SessionState.GetBool(ShowObserverBoundaryKey, false);
            ShowObserverBoundary = EditorGUILayout.Toggle("Show Observer Boundaries", ShowObserverBoundary);
            SessionState.SetBool(ShowObserverBoundaryKey, ShowObserverBoundary);

            ShowObserverOrigin = SessionState.GetBool(ShowObserverOriginKey, false);
            ShowObserverOrigin = EditorGUILayout.Toggle("Show Observer Origins", ShowObserverOrigin);
            SessionState.SetBool(ShowObserverOriginKey, ShowObserverOrigin);
        }
 public TestSpatialAwarenessDataProvider(
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     string name,
     uint priority,
     BaseMixedRealityProfile profile) : base(spatialAwarenessSystem, name, priority, profile)
 {
 }
예제 #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="registrar">The <see cref="IMixedRealityServiceRegistrar"/> instance that loaded the service.</param>
 /// <param name="name">Friendly name of the service.</param>
 /// <param name="priority">Service priority. Used to determine order of instantiation.</param>
 /// <param name="profile">The service's configuration profile.</param>
 public GenericXRSDKSpatialMeshObserver(
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     string name   = null,
     uint priority = DefaultPriority,
     BaseMixedRealityProfile profile = null) : base(spatialAwarenessSystem, name, priority, profile)
 {
 }
예제 #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="name">Friendly name of the service.</param>
 /// <param name="priority">Service priority. Used to determine order of instantiation.</param>
 /// <param name="profile">The service's configuration profile.</param>
 public WindowsMixedRealitySpatialAwarenessSceneUnderstandingObserver(
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     string name   = null,
     uint priority = DefaultPriority,
     BaseMixedRealityProfile profile = null) : base(spatialAwarenessSystem, name, priority, profile)
 {
     ReadProfile();
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="registrar">The <see cref="IMixedRealityServiceRegistrar"/> instance that loaded the service.</param>
 /// <param name="name">Friendly name of the service.</param>
 /// <param name="priority">Service priority. Used to determine order of instantiation.</param>
 /// <param name="profile">The service's configuration profile.</param>
 public SpatialObjectMeshObserver(
     IMixedRealityServiceRegistrar registrar,
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     string name   = null,
     uint priority = DefaultPriority,
     BaseMixedRealityProfile profile = null) : base(registrar, spatialAwarenessSystem, name, priority, profile)
 {
 }
 /// <inheritdoc />
 public void Initialize(
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     int id,
     GameObject gameObject)
 {
     BaseInitialize(spatialAwarenessSystem);
     Id         = id;
     GameObject = gameObject;
 }
 public WindowsMixedRealitySpatialMeshObserver(
     IMixedRealityServiceRegistrar registrar,
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     string name   = null,
     uint priority = DefaultPriority,
     BaseMixedRealityProfile profile = null) : this(spatialAwarenessSystem, name, priority, profile)
 {
     Registrar = registrar;
 }
 /// <inheritdoc />
 public void Initialize(
     IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
     int id,
     GameObject gameObject)
 {
     base.BaseInitialize(spatialAwarenessSystem);
     Id         = id;
     EventTime  = DateTime.Now;
     GameObject = gameObject;
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="spatialAwarenessSystem">The <see cref="SpatialAwareness.IMixedRealitySpatialAwarenessSystem"/> to which the observer is providing data.</param>
        /// <param name="name">The friendly name of the data provider.</param>
        /// <param name="priority">The registration priority of the data provider.</param>
        /// <param name="profile">The configuration profile for the data provider.</param>
        protected BaseSpatialObserver(
            IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
            string name   = null,
            uint priority = DefaultPriority,
            BaseMixedRealityProfile profile = null) : base(spatialAwarenessSystem, name, priority, profile)
        {
            SpatialAwarenessSystem = spatialAwarenessSystem;

            SourceId   = (SpatialAwarenessSystem != null) ? SpatialAwarenessSystem.GenerateNewSourceId() : 0;
            SourceName = name;
        }
        public void TestGetSpatialAwarenessSystem()
        {
            TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(true);

            // Retrieve Spatial Awareness System
            IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem = null;

            MixedRealityServiceRegistry.TryGetService(out spatialAwarenessSystem);

            // Tests
            Assert.IsNotNull(spatialAwarenessSystem);
        }
        public override void DrawGizmos(object target)
        {
            if (!(ShowObserverBoundary || ShowObserverOrigin))
            {
                return;
            }

            IMixedRealitySpatialAwarenessSystem spatial            = (IMixedRealitySpatialAwarenessSystem)target;
            IMixedRealityDataProviderAccess     dataProviderAccess = (IMixedRealityDataProviderAccess)spatial;

            var dataProviders = dataProviderAccess?.GetDataProviders();

            if (dataProviders != null)
            {
                int observerIndex = 0;

                foreach (IMixedRealitySpatialAwarenessObserver observer in dataProviders)
                {
                    Gizmos.color = GetObserverColor(observerIndex);

                    if (ShowObserverBoundary)
                    {
                        switch (observer.ObserverVolumeType)
                        {
                        case VolumeType.None:
                            break;

                        case VolumeType.AxisAlignedCube:
                            Gizmos.DrawWireCube(observer.ObserverOrigin, observer.ObservationExtents);
                            break;

                        case VolumeType.Sphere:
                            Gizmos.DrawWireSphere(observer.ObserverOrigin, observer.ObservationExtents.x);
                            break;

                        case VolumeType.UserAlignedCube:
                            Gizmos.DrawWireCube(observer.ObserverOrigin, observer.ObservationExtents);
                            break;
                        }
                    }

                    Gizmos.matrix = Matrix4x4.identity;

                    if (ShowObserverOrigin)
                    {
                        Gizmos.DrawSphere(observer.ObserverOrigin, 0.1f);
                    }

                    observerIndex++;
                }
            }
        }
예제 #12
0
        private void Start()
        {
            // Get Core Spatial Awareness Services
            m_spatialAwarenessService = CoreServices.SpatialAwarenessSystem;
            if (m_spatialAwarenessService != null)
            {
                IMixedRealityDataProviderAccess dataProviderAccess = m_spatialAwarenessService as IMixedRealityDataProviderAccess;
                m_spatialAwarenessMeshObserver = dataProviderAccess.GetDataProvider <IMixedRealitySpatialAwarenessMeshObserver>();

                // Try to get "Spatial Awareness System" object (stores meshes)
                AcquireSpatailAwarenessObject();
            }
        }
 /// <summary>
 /// Resets all cached system references to null
 /// </summary>
 public static void ResetCacheReferences()
 {
     serviceCache.Clear();
     boundarySystem         = null;
     cameraSystem           = null;
     diagnosticsSystem      = null;
     focusProvider          = null;
     inputSystem            = null;
     raycastProvider        = null;
     sceneSystem            = null;
     spatialAwarenessSystem = null;
     teleportSystem         = null;
 }
예제 #14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="registrar">The <see cref="IMixedRealityServiceRegistrar"/> instance that loaded the observer.</param>
        /// <param name="spatialAwarenessSystem">The <see cref="SpatialAwareness.IMixedRealitySpatialAwarenessSystem"/> to which the observer is providing data.</param>
        /// <param name="name">The friendly name of the data provider.</param>
        /// <param name="priority">The registration priority of the data provider.</param>
        /// <param name="profile">The configuration profile for the data provider.</param>
        public BaseSpatialObserver(
            IMixedRealityServiceRegistrar registrar,
            IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem,
            string name   = null,
            uint priority = DefaultPriority,
            BaseMixedRealityProfile profile = null) : base(registrar, spatialAwarenessSystem, name, priority, profile)
        {
            if (MixedRealityToolkit.SpatialAwarenessSystem != null)
            {
                SourceId = MixedRealityToolkit.SpatialAwarenessSystem.GenerateNewSourceId();
            }
            else
            {
                Debug.LogError($"A spatial observer is registered in your service providers profile, but the spatial awareness system is turned off. Please either turn on spatial awareness or remove {name}.");
            }

            SourceName = name;
        }
예제 #15
0
        /// <inheritdoc />
        public LuminSpatialMeshObserver(string name, uint priority, LuminSpatialMeshObserverProfile profile, IMixedRealitySpatialAwarenessSystem parentService)
            : base(name, priority, profile, parentService)
        {
            meshingSettings = MlMeshing2.MLMeshingSettings.Default;

            if (MeshRecalculateNormals)
            {
                meshingSettings.flags |= MlMeshing2.MeshingFlags.ComputeNormals;
            }
        }
예제 #16
0
        /// <inheritdoc />
        public WindowsMixedRealitySpatialMeshObserver(string name, uint priority, WindowsMixedRealitySpatialMeshObserverProfile profile, IMixedRealitySpatialAwarenessSystem parentService)
            : base(name, priority, profile, parentService)
        {
#if WINDOWS_UWP
            if (profile.MeshLevelOfDetail == SpatialAwarenessMeshLevelOfDetail.Custom)
            {
                trianglesPerCubicMeter = profile.TrianglesPerCubicMeter;
            }

            if (SpatialSurfaceObserver.IsSupported())
            {
                spatialSurfaceObserver    = new SpatialSurfaceObserver();
                spatialSurfaceMeshOptions = new SpatialSurfaceMeshOptions {
                    IncludeVertexNormals = true
                };

                // TODO Determine which formats are the correct ones to use.
                var supportedVertexPositionFormats = SpatialSurfaceMeshOptions.SupportedVertexPositionFormats;
                var supportedVertexNormalFormats   = SpatialSurfaceMeshOptions.SupportedVertexNormalFormats;

                for (int i = 0; i < supportedVertexPositionFormats.Count; i++)
                {
                    if (supportedVertexPositionFormats[i] == Windows.Graphics.DirectX.DirectXPixelFormat.R16G16B16A16IntNormalized)
                    {
                        spatialSurfaceMeshOptions.VertexPositionFormat = Windows.Graphics.DirectX.DirectXPixelFormat.R16G16B16A16IntNormalized;
                        break;
                    }
                }

                for (int i = 0; i < supportedVertexNormalFormats.Count; i++)
                {
                    if (supportedVertexNormalFormats[i] == Windows.Graphics.DirectX.DirectXPixelFormat.R8G8B8A8IntNormalized)
                    {
                        spatialSurfaceMeshOptions.VertexNormalFormat = Windows.Graphics.DirectX.DirectXPixelFormat.R8G8B8A8IntNormalized;
                        break;
                    }
                }

                // If a very high detail setting with spatial mapping is used, it can be beneficial
                // to use a 32-bit unsigned integer format for indices instead of the default 16-bit.
                if (MeshLevelOfDetail == SpatialAwarenessMeshLevelOfDetail.High)
                {
                    var supportedTriangleIndexFormats = SpatialSurfaceMeshOptions.SupportedTriangleIndexFormats;

                    for (int i = 0; i < supportedTriangleIndexFormats.Count; i++)
                    {
                        if (supportedTriangleIndexFormats[i] == Windows.Graphics.DirectX.DirectXPixelFormat.R8G8B8A8IntNormalized)
                        {
                            spatialSurfaceMeshOptions.TriangleIndexFormat = Windows.Graphics.DirectX.DirectXPixelFormat.R32UInt;
                        }
                    }
                }
            }
        }
        /// <inheritdoc />
        protected BaseMixedRealitySpatialSurfaceObserver(string name, uint priority, BaseMixedRealitySurfaceObserverProfile profile, IMixedRealitySpatialAwarenessSystem parentService)
            : base(name, priority, profile, parentService)
        {
            if (profile.IsNull())
            {
                profile = MixedRealityToolkit.Instance.ActiveProfile.SpatialAwarenessProfile.GlobalSurfaceObserverProfile;
            }

            if (profile.IsNull())
            {
                throw new ArgumentNullException($"Missing a {profile.GetType().Name} profile for {name}");
            }

            SurfaceFindingMinimumArea = profile.SurfaceFindingMinimumArea;
            DisplayFloorSurfaces      = profile.DisplayFloorSurfaces;
            FloorSurfaceMaterial      = profile.FloorSurfaceMaterial;
            DisplayCeilingSurfaces    = profile.DisplayCeilingSurface;
            CeilingSurfaceMaterial    = profile.CeilingSurfaceMaterial;
            DisplayWallSurfaces       = profile.DisplayWallSurface;
            WallSurfaceMaterial       = profile.WallSurfaceMaterial;
            DisplayPlatformSurfaces   = profile.DisplayPlatformSurfaces;
            PlatformSurfaceMaterial   = profile.PlatformSurfaceMaterial;
        }
예제 #18
0
        /// <inheritdoc />
        protected BaseMixedRealitySpatialMeshObserver(string name, uint priority, BaseMixedRealitySpatialMeshObserverProfile profile, IMixedRealitySpatialAwarenessSystem parentService)
            : base(name, priority, profile, parentService)
        {
            if (profile.IsNull())
            {
                profile = MixedRealityToolkit.Instance.ActiveProfile.SpatialAwarenessProfile.GlobalMeshObserverProfile;
            }

            if (profile.IsNull())
            {
                throw new ArgumentNullException($"Missing a {profile.GetType().Name} profile for {name}");
            }

            MeshLevelOfDetail      = profile.MeshLevelOfDetail;
            MeshRecalculateNormals = profile.MeshRecalculateNormals;
            meshDisplayOption      = MixedRealityToolkit.SpatialAwarenessSystem.SpatialMeshVisibility;
            MeshVisibleMaterial    = profile.MeshVisibleMaterial;
            MeshOcclusionMaterial  = profile.MeshOcclusionMaterial;
            ObservationExtents     = profile.ObservationExtents;
            IsStationaryObserver   = profile.IsStationaryObserver;
            var additionalComponents = profile.AdditionalComponents;

            meshObjectPrefab      = profile.MeshObjectPrefab;
            spatialMeshObjectPool = new Stack <SpatialMeshObject>();

            if (additionalComponents != null)
            {
                requiredMeshComponents    = new Type[additionalComponents.Length + 3];
                requiredMeshComponents[0] = typeof(MeshFilter);
                requiredMeshComponents[1] = typeof(MeshRenderer);
                requiredMeshComponents[2] = typeof(MeshCollider);

                for (int i = 3; i < additionalComponents.Length; i++)
                {
                    var component = additionalComponents[i - 3].Type;
                    Debug.Assert(component != null);
                    requiredMeshComponents[i] = component;
                }
            }
            else
            {
                requiredMeshComponents = new[]
                {
                    typeof(MeshFilter),
                    typeof(MeshRenderer),
                    typeof(MeshCollider)
                };
            }
        }
        /// <inheritdoc />
        protected BaseMixedRealitySpatialObserverDataProvider(string name, uint priority, BaseMixedRealitySpatialObserverProfile profile, IMixedRealitySpatialAwarenessSystem parentService)
            : base(name, priority, profile, parentService)
        {
            if (profile.IsNull())
            {
                profile = MixedRealityToolkit.Instance.ActiveProfile.SpatialAwarenessProfile.GlobalMeshObserverProfile;
            }

            if (profile.IsNull())
            {
                throw new ArgumentNullException($"Missing a {profile.GetType().Name} profile for {name}");
            }

            SourceId        = MixedRealityToolkit.SpatialAwarenessSystem.GenerateNewObserverId();
            StartupBehavior = profile.StartupBehavior;
            UpdateInterval  = profile.UpdateInterval;
            PhysicsLayer    = profile.PhysicsLayer;
        }