/// <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.")); } }
/// <summary> /// Retrieves the PCF associated with the given CFUID. /// </summary> /// <param name="cfuid">The CFUID to look up the PCF type with.</param> /// <param name="callback">Delegate used to return the resulting MLResult.Result and the closest found PCF.</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 FindPCFByCFUID(MagicLeapNativeBindings.MLCoordinateFrameUID cfuid, OnFoundSinglePCFDelegate callback, bool update = true) { if (MLPersistentCoordinateFrames.IsValidInstance()) { if (_instance.mapAllPCFs.ContainsKey(cfuid)) { PCF pcf = _instance.mapAllPCFs[cfuid]; if (update) { MLResult updateResult = pcf.Update(); if (!updateResult.IsOk) { MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFByCFUID failed to update the found PCF. Reason: {0}", updateResult); callback(MLResult.Code.PassableWorldNotFound, pcf); return(updateResult); } } callback(MLResult.Code.Ok, pcf); return(MLResult.Create(MLResult.Code.Ok)); } else { QueryFilter queryFilter = QueryFilter.Create(); queryFilter.TypesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession; queryFilter.MaxResults = int.MaxValue; queryFilter.Sorted = false; FindPCFsByFilter(queryFilter, update: update, callback: (MLResult.Code resultCode, List <PCF> pcfList) => { PCF pcfWithCFUID = pcfList.Find(pcf => pcf.CFUID == cfuid); if (pcfWithCFUID != null) { if (update) { MLResult updateResult = pcfWithCFUID.Update(); if (!updateResult.IsOk) { MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFByCFUID failed to update the found PCF. Reason: {0}", updateResult); callback(MLResult.Code.PassableWorldNotFound, pcfWithCFUID); } } callback(MLResult.Code.Ok, pcfWithCFUID); } else { callback(resultCode, null); } }); return(MLResult.Create(MLResult.Code.Ok)); } } else { MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindPCFByCFUID failed. Reason: No Instance for MLPersistentCoordinateFrames."); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindPCFByCFUID failed. Reason: No Instance for MLPersistentCoordinateFrames.")); } }