Пример #1
0
        //Private Methods:
        private void DiscoverPCFs()
        {
            //interval:
            _interval++;
            _interval = _interval % 100;

            //if previous send queue isn't finished then interrupt it:
            StopCoroutine("SendPCFs");

            //clear lists:
            _localPCFs.Clear();
            _localPCFData.Clear();
            _localPCFReferences.Clear();
            _outboundPCFs.Clear();

            //get pcfs:
            MLPersistentCoordinateFrames.GetAllPCFs(out _localPCFs, QueryCount);

            //request poses:
            foreach (var item in _localPCFs)
            {
                //MLPersistentCoordinateFrames.GetPCFPosition(item, HandlePCFPoseRetrieval); sub SDK .23
                MLPersistentCoordinateFrames.GetPCFPose(item, HandlePCFPoseRetrieval);
            }
        }
Пример #2
0
        ///<summary>
        /// Starts the restoration process.
        /// </summary>
        void StartRestore()
        {
            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                SetError(result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                SetError(result);
                enabled = false;
                return;
            }

            result = MLPersistentCoordinateFrames.GetAllPCFs(out _allPCFs, MaxPCFsToBindTo);
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                MLPersistentCoordinateFrames.Stop();
                SetError(result);
                enabled = false;
                return;
            }

            StartCoroutine(TryRestoreBinding());
        }
Пример #3
0
    private IEnumerator FindAllPCFs()
    {
        float timer = 5;

        while (timer > 0)
        {
            // GetAllPCFs returns a list of PCFs that doesn't have a position yet
            MLResult result = MLPersistentCoordinateFrames.GetAllPCFs(out PCFList);
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error : MLPersistenceCoordinateFrames failed to get all PCFS. Reason {0}", result);
                yield break;
            }

            foreach (var pcf in PCFList)
            {
                result = MLPersistentCoordinateFrames.GetPCFPose(pcf, HandlePCFPositionQuery);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to get PCF position. Reason: {0}", result);
                    yield break;
                }
            }
            timer -= Time.deltaTime;
        }
        Debug.Log("OnGoingQUeriesCount " + _ongoingQueriesCount);
        Debug.Log("Exiting Coroutine");
        if (OnPCFsObtained != null)
        {
            OnPCFsObtained();
        }

        FindClosestPCF();
    }
        private static IEnumerator C_UpdatePCFs()
        {
            List <MLPCF> allPCFs;

            while (true)
            {
                MLResult result = MLPersistentCoordinateFrames.GetAllPCFs(out allPCFs);

                if (result.IsOk)
                {
                    foreach (MLPCF PCF in allPCFs)
                    {
                        if (PCFs.Find((element) => element.CFUID.Equals(PCF.CFUID)) == null)
                        {
                            OnPCFFoundHandler(PCF);
                        }
                    }
                }
                else
                {
                    Debug.Log("MLULandscape: PCFs update failed. result: " + result);
                }

                yield return(new WaitForSecondsRealtime(updatePCFsInterval));
            }
        }
Пример #5
0
        /// <summary>
        /// Coroutine to query for all PCFs and queue them for updates.
        /// Note: Getting all PCFs is highly inefficient and ill-advised. We are only
        /// doing this for demonstration/debug purposes. Do NOT do this on production code!
        /// </summary>
        IEnumerator FindAllPCFs()
        {
            while (true)
            {
                yield return(new WaitForSeconds(_secondsBetweenFindAllPCFs));

                List <MLPCF> allPCFs;
                MLResult     result = MLPersistentCoordinateFrames.GetAllPCFs(out allPCFs);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to get all PCFs. Reason: {0}", result);
                    yield break;
                }

                // MLPersistentCoordinateFrames.GetAllPCFs() returns the PCFs stored in the device.
                // We don't have their positions yet. In fact, we don't even know if they're in the
                // same landscape as the user is loaded into so we must queue the pcfs for any status updates.

                foreach (MLPCF pcf in allPCFs)
                {
                    MLPersistentCoordinateFrames.QueueForUpdates(pcf);
                    yield return(null);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Acquires list of PCFs
        /// </summary>
        /// <returns>List of PCFs</returns>
        List <MLPCF> GetPCFList()
        {
            List <MLPCF> pcfList;
            MLResult     result = MLPersistentCoordinateFrames.GetAllPCFs(out pcfList);

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("PCFVisualizer failed getting all PCFs, disabling script. Reason: {0}", result);
                enabled = false;
            }

            _countText.text = String.Format("PCF Count: {0}", pcfList.Count);
            return(pcfList);
        }
Пример #7
0
        //Coroutines:
        private IEnumerator PCFDiscovery()
        {
            //query until we get PCFs:
            while (_localPCFs.Count == 0)
            {
                MLPersistentCoordinateFrames.GetAllPCFs(out _localPCFs, QueryCount);
                yield return(null);
            }

            while (true)
            {
                DiscoverPCFs();
                yield return(new WaitForSeconds(QueryInterval));

                yield return(null);
            }
        }
Пример #8
0
        /// <summary>
        /// Coroutine to continuously query for all PCFs and their locations in debug mode.
        /// Note: Getting all PCFs is highly inefficient and ill-advised. We are only
        /// doing this for demonstration/debug purposes. Do NOT do this on production code!
        /// </summary>
        /// <returns>IEnumerator</returns>
        IEnumerator FindAllPCFs()
        {
            while (IsDebugMode)
            {
                List <MLPCF> allPCFs;
                MLResult     result = MLPersistentCoordinateFrames.GetAllPCFs(out allPCFs);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to get all PCFs. Reason: {0}", result);
                    yield break;
                }

                // MLPersistentCoordinateFrames.GetAllPCFs() returns the PCFs stored in the device.
                // We don't have their positions yet. In fact, we don't even know if they're in the
                // same landscape as the user is loaded into.

                _ongoingQueriesCount = allPCFs.Count;
                foreach (MLPCF pcf in allPCFs)
                {
                    result = MLPersistentCoordinateFrames.GetPCFPosition(pcf, HandlePCFPositionQuery);
                    // HandlePCFPositionQuery could execute immediately (when the requested PCF has been requested before)
                    // or later (when the PCF is completely new).
                    if (!result.IsOk)
                    {
                        Debug.LogErrorFormat("Error: MLPersistentCoordinateFrames failed to get PCF position. Reason: {0}", result);
                        yield break;
                    }

                    // When MLPersistentCoordinateFrames.GetPCFPosition() successfully gets the position of the PCF,
                    // MLPCF.OnCreate() gets triggered which will call HandleCreate()
                }

                // It is possible for _ongoingQueriesCount to be 0 at this point when no new PCFs have been found.
                // Such a case would cause an infinite loop in the current frame. The following yield statement
                // prevents the infinite loop in a single frame.
                yield return(null);

                while (_ongoingQueriesCount > 0)
                {
                    yield return(null);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        void Start()
        {
            MLResult result = MLPersistentStore.Start();

            if (!result.IsOk)
            {
                SetError("Failed to start persistent store. Disabling component");
                enabled = false;
                return;
            }
            result = MLPersistentCoordinateFrames.Start();
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                SetError("Failed to start coordinate frames system. disabling component");
                enabled = false;
                return;
            }

            if (_representativePrefab == null)
            {
                SetError("Error: _representativePrefab must be set");
                enabled = false;
                return;
            }

            List <MLPCF> pcfList;

            result = MLPersistentCoordinateFrames.GetAllPCFs(out pcfList, int.MaxValue);
            if (!result.IsOk)
            {
                MLPersistentStore.Stop();
                MLPersistentCoordinateFrames.Stop();
                SetError(result.ToString());
                enabled = false;
                return;
            }

            TryShowingAllPCFs(pcfList);
        }