/// <summary>
        /// Requests updates from the surface observer.
        /// </summary>
        private void UpdateObserver()
        {
            if (Service == null || meshSubsystem == null)
            {
                return;
            }

            using (UpdateObserverPerfMarker.Auto())
            {
                // Only update the observer if it is running.
                if (IsRunning && (outstandingMeshObject == null))
                {
                    // If we have a mesh to work on...
                    if (meshWorkQueue.Count > 0)
                    {
                        // We're using a simple first-in-first-out rule for requesting meshes, but a more sophisticated algorithm could prioritize
                        // the queue based on distance to the user or some other metric.
                        RequestMesh(meshWorkQueue.Dequeue());
                    }
                    // If enough time has passed since the previous observer update...
                    else if (Time.time - lastUpdated >= UpdateInterval)
                    {
                        // Update the observer orientation if user aligned
                        if (ObserverVolumeType == VolumeType.UserAlignedCube)
                        {
                            ObserverRotation = CameraCache.Main.transform.rotation;
                        }

                        // Update the observer location if it is not stationary
                        if (!IsStationaryObserver)
                        {
                            ObserverOrigin = CameraCache.Main.transform.position;
                        }

                        // The application can update the observer volume at any time, make sure we are using the latest.
                        ConfigureObserverVolume();

                        if (meshSubsystem.TryGetMeshInfos(meshInfos))
                        {
                            UpdateMeshes(meshInfos);
                        }

                        lastUpdated = Time.time;
                    }
                }
            }
        }
Exemplo n.º 2
0
        void Update()
        {
            if (s_MeshSubsystem.running && s_MeshSubsystem.TryGetMeshInfos(s_MeshInfos))
            {
                foreach (var meshInfo in s_MeshInfos)
                {
                    switch (meshInfo.ChangeState)
                    {
                    case MeshChangeState.Added:
                    case MeshChangeState.Updated:
                        if (!m_MeshIdToGo.TryGetValue(meshInfo.MeshId, out var go))
                        {
                            go = Instantiate(emptyMeshPrefab, target, false);
                            m_MeshIdToGo[meshInfo.MeshId] = go;
                        }

                        var mesh = go.GetComponent <MeshFilter>().mesh;
                        var col  = go.GetComponent <MeshCollider>();

                        s_MeshSubsystem.GenerateMeshAsync(meshInfo.MeshId, mesh, col, MeshVertexAttributes.Normals | MeshVertexAttributes.UVs,
                                                          result =>
                        {
                            Debug.Log("Mesh generated: " + result.Status);
                        });
                        break;

                    case MeshChangeState.Removed:
                        if (m_MeshIdToGo.TryGetValue(meshInfo.MeshId, out var meshGo))
                        {
                            Destroy(meshGo);
                            m_MeshIdToGo.Remove(meshInfo.MeshId);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        /// <inheritdoc />
        public override void Update()
        {
            base.Update();

            // Only update the observer if it is running.
            if (!IsRunning ||
                meshSubsystem == null ||
                !Application.isPlaying)
            {
                return;
            }

            // and If enough time has passed since the previous observer update
            if (!(Time.time - lastUpdated >= UpdateInterval))
            {
                return;
            }

            // Update the observer location if it is not stationary
            if (!IsStationaryObserver)
            {
                var cameraTransform = CameraCache.Main.transform;
                ObserverOrigin      = cameraTransform.position;
                ObserverOrientation = cameraTransform.rotation;
            }

            ConfigureObserverVolume();

            if (meshSubsystem.TryGetMeshInfos(meshInfos))
            {
                for (int i = 0; i < meshInfos.Count; i++)
                {
                    MeshInfo_Update(meshInfos[i]);
                }
            }

            // observer.Update(SurfaceObserver_OnSurfaceChanged);
            lastUpdated = Time.time;
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public override void Update()
        {
            base.Update();

            // Only update the observer if it is running.
            if (!IsRunning ||
                meshSubsystem == null ||
                !Application.isPlaying)
            {
                return;
            }

            // and If enough time has passed since the previous observer update
            if (!(Time.time - lastUpdated >= UpdateInterval))
            {
                return;
            }

            // Update the observer location if it is not stationary
            if (!IsStationaryObserver)
            {
                ObserverOrigin      = MixedRealityToolkit.CameraSystem.CameraRig.CameraTransform.position;
                ObserverOrientation = MixedRealityToolkit.CameraSystem.CameraRig.CameraTransform.rotation;
            }

            ConfigureObserverVolume();

            if (meshSubsystem.TryGetMeshInfos(meshInfos))
            {
                for (int i = 0; i < meshInfos.Count; i++)
                {
                    MeshInfo_Update(meshInfos[i]);
                }
            }

            lastUpdated = Time.time;
        }
Exemplo n.º 5
0
    void Update()
    {
        if (m_MeshSubsystem == null)
        {
            return;
        }

        if (!m_MeshSubsystem.running)
        {
            return;
        }

        if (m_initialized)
        {
            if (Time.time - m_lastMeshInfoUpdateTime < meshInfoUpdateInterval)
            {
                return;
            }

            if (m_MeshSubsystem.TryGetMeshInfos(m_MeshInfos))
            {
                foreach (var meshInfo in m_MeshInfos)
                {
                    switch (meshInfo.ChangeState)
                    {
                    case MeshChangeState.Added:
                    case MeshChangeState.Updated:
                        m_MeshesNeedingGeneration[meshInfo.MeshId] = meshInfo;
                        break;

                    case MeshChangeState.Removed:
                        m_MeshesNeedingGeneration.Remove(meshInfo.MeshId);

                        GameObject meshGameObject;
                        if (meshIdToGameObjectMap.TryGetValue(meshInfo.MeshId, out meshGameObject))
                        {
                            Destroy(meshGameObject);
                            meshIdToGameObjectMap.Remove(meshInfo.MeshId);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            m_lastMeshInfoUpdateTime = Time.time;
        }

        while (m_MeshesBeingGenerated.Count < meshQueueSize && m_MeshesNeedingGeneration.Count > 0)
        {
            MeshId meshId;

            if (GetNextMeshToGenerate(out meshId))
            {
                var meshGameObject = GetOrCreateGameObjectForMesh(meshId);
                var meshFilter     = meshGameObject.GetComponent <MeshFilter>();
                var mesh           = GetOrCreateMesh(meshFilter);

                var meshAttributes = (MeshVertexAttributes.Normals | MeshVertexAttributes.Colors | MeshVertexAttributes.UVs);

                m_MeshSubsystem.GenerateMeshAsync(meshId, mesh, null, meshAttributes, OnMeshGenerated);

                m_MeshesBeingGenerated.Add(meshId, m_MeshesNeedingGeneration[meshId]);
                m_MeshesNeedingGeneration.Remove(meshId);
            }
        }
    }