Пример #1
0
        /// <summary>
        /// Retrieves the closest known PCF of the types provided by the typesMask to the given position.
        /// </summary>
        /// <param name="position">The position of the object we want to anchor.</param>
        /// <param name="pcf">Stores the resulting PCF.</param>
        /// <param name="typesMask">The bitmask of which PCF types to consider.</param>
        /// <param name="update">Determines if the PCF should have it's pose and state updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if a valid PCF was found.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to an invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to other internal error.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldLowMapQuality</c> if map quality is too low for content persistence. Continue building the map.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldUnableToLocalize</c> if currently unable to localize into any map. Continue building the map.
        /// </returns>
        public static MLResult FindClosestPCF(Vector3 position, out PCF pcf, PCF.Types typesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession, bool update = true)
        {
            pcf = null;

            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                QueryFilter queryFilter = QueryFilter.Create();
                queryFilter.TargetPoint = position;
                queryFilter.TypesMask   = typesMask;
                queryFilter.Sorted      = true;

                MLResult result = FindPCFsByFilter(queryFilter, out List <PCF> pcfList, update);

                if (!result.IsOk || pcfList.Count == 0)
                {
                    if (result.Result == MLResult.Code.PassableWorldLowMapQuality || result.Result == MLResult.Code.PassableWorldUnableToLocalize)
                    {
                        MLPluginLog.WarningFormat("Map quality not sufficient enough for MLPersistentCoordinateFrames.FindClosestPCF. Reason: {0}", result);
                    }
                    else
                    {
                        MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: {0}", result);
                    }
                }
                else
                {
                    pcf = pcfList[0];
                }

                return(result);
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }
Пример #2
0
        /// <summary>
        /// Returns a list of all the PCFs of the types provided by the typesMask inside the current map.
        /// </summary>
        /// <param name="pcfList">Stores the resulting list of PCFs.</param>
        /// <param name="maxResults">The max number of PCFs to get.</param>
        /// <param name="typesMask">The bitmask of which PCF types to consider.</param>
        /// <param name="update">Determines if the PCFs should have their pose updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if all the PCFs from the current map have been found successfully.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to other internal error.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldLowMapQuality</c> if map quality is too low for content persistence. Continue building the map.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldUnableToLocalize</c> if currently unable to localize into any map. Continue building the map.
        /// </returns>
        public static MLResult FindAllPCFs(out List <PCF> pcfList, uint maxResults = int.MaxValue, PCF.Types typesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession, bool update = true)
        {
            pcfList = new List <PCF>();

            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                QueryFilter queryFilter = QueryFilter.Create();
                queryFilter.TypesMask  = typesMask;
                queryFilter.MaxResults = maxResults;
                queryFilter.Sorted     = false;

                MLResult result = FindPCFsByFilter(queryFilter, out pcfList, update);

                if (!result.IsOk)
                {
                    if (result.Result == MLResult.Code.PassableWorldLowMapQuality || result.Result == MLResult.Code.PassableWorldUnableToLocalize)
                    {
                        MLPluginLog.Warning("Map quality not sufficient enough for MLPersistentCoordinateFrames.FindAllPCFs.");
                    }
                    else
                    {
                        MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindAllPCFs failed. Reason: {0}", result);
                    }
                }

                return(result);
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindAllPCFs failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindAllPCFs failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }
        /// <summary>
        /// Returns a list of all the PCFs of the types provided by the typesMask inside the current map.
        /// </summary>
        /// <param name="callback">Delegate used to return the resulting MLResult.Result and list of found PCFs.</param>
        /// <param name="maxResults">The max number of PCFs to get.</param>
        /// <param name="typesMask">The bitmask of which PCF types to consider.</param>
        /// <param name="update">Determines if the PCFs should have their pose updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if all the PCFs from the current map have been found successfully.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to no API instance being found.
        /// </returns>
        public static MLResult FindAllPCFs(OnFoundMultiPCFDelegate callback, uint maxResults = int.MaxValue, PCF.Types typesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession, bool update = true)
        {
            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                QueryFilter queryFilter = QueryFilter.Create();
                queryFilter.TypesMask  = typesMask;
                queryFilter.MaxResults = maxResults;
                queryFilter.Sorted     = false;

                FindPCFsByFilter(queryFilter, callback, update);
                return(MLResult.Create(MLResult.Code.Ok));
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindAllPCFs failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindAllPCFs failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }
Пример #4
0
        /// <summary>
        /// Retrieves the type of the PCF associated with the given CFUID.
        /// </summary>
        /// <param name="cfuid">The CFUID to look up the PCF type with.</param>
        /// <param name="type">Stores the type of PCF associated with the given CFUID.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if a valid PCF was found.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to an invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to other internal error.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldLowMapQuality</c> if map quality is too low for content persistence. Continue building the map.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldNotFound</c> if the passed CFUID is not available.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldUnableToLocalize</c> if currently unable to localize into any map. Continue building the map.
        /// </returns>
        public static MLResult GetPCFTypeByCFUID(MagicLeapNativeBindings.MLCoordinateFrameUID cfuid, out PCF.Types type)
        {
            type = 0;

            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                try
                {
                    NativeBindings.FrameStateNative nativeState = NativeBindings.FrameStateNative.Create();
                    MLResult.Code resultCode = NativeBindings.MLPersistentCoordinateFramesGetFrameState(_instance.nativeTracker, in cfuid, ref nativeState);
                    if (!MLResult.IsOK(resultCode))
                    {
                        if (resultCode == MLResult.Code.PassableWorldLowMapQuality || resultCode == MLResult.Code.PassableWorldUnableToLocalize)
                        {
                            MLPluginLog.WarningFormat("Map quality not sufficient enough for MLPersistentCoordinateFrames.GetPCFTypeByCFUID. Reason: {0}", MLResult.CodeToString(resultCode));
                        }
                        else
                        {
                            MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.GetPCFTypeByCFUID failed. Reason: {0}", MLResult.CodeToString(resultCode));
                        }

                        return(MLResult.Create(resultCode, string.Format("MLPersistentCoordinateFrames.GetPCFTypeByCFUID failed. Reason: {0}", MLResult.CodeToString(resultCode))));
                    }
                    else
                    {
                        type = nativeState.Type;
                        return(MLResult.Create(resultCode));
                    }
                }
                catch (EntryPointNotFoundException)
                {
                    MLPluginLog.Error("MLPersistentCoordinateFrames.GetPCFTypeByCFUID failed. Reason: API symbols not found.");
                    return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.GetPCFTypeByCFUID failed. Reason: API symbols not found."));
                }
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.GetPCFTypeByCFUID failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.GetPCFTypeByCFUID failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }
        /// <summary>
        /// Retrieves the closest known PCF of the types provided by the typesMask to the given position.
        /// </summary>
        /// <param name="position">The position of the object we want to anchor.</param>
        /// <param name="callback">Delegate used to return the resulting MLResult.Result and the closest found PCF.</param>
        /// <param name="typesMask">The bitmask of which PCF types to consider.</param>
        /// <param name="update">Determines if the PCF should have it's pose and state updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if a valid PCF was found.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to no API instance being found.
        /// </returns>
        public static MLResult FindClosestPCF(Vector3 position, OnFoundSinglePCFDelegate callback, PCF.Types typesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession, bool update = true)
        {
            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                QueryFilter queryFilter = QueryFilter.Create();
                queryFilter.TargetPoint = position;
                queryFilter.TypesMask   = typesMask;
                queryFilter.Sorted      = true;

                FindPCFsByFilter(queryFilter, update: update, callback: (MLResult.Code resultCode, List <PCF> pcfList) =>
                {
                    callback?.Invoke(resultCode, pcfList[0]);
                });

                return(MLResult.Create(MLResult.Code.Ok));
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }