/// <summary> /// Begin querying for found objects. /// </summary> /// <param name="filter">Filter to use for this query.</param> /// <param name="callback">Callback used to report query results.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> private MLResult BeginObjectQueryAsync(Query.Filter filter, QueryResultsDelegate callback) { try { if (!MagicLeapNativeBindings.MLHandleIsValid(_instance.handle)) { MLPluginLog.Error("MLFoundObjects.BeginObjectQuery failed to request found objects. Reason: Tracker handle is invalid"); return(MLResult.Create(MLResult.Code.InvalidParam)); } NativeBindings.QueryFilterNative nativeQueryFilter = new NativeBindings.QueryFilterNative(); nativeQueryFilter.Data = filter; MLResult.Code resultCode = NativeBindings.MLFoundObjectQuery(_instance.handle, ref nativeQueryFilter, out ulong queryHandle); MLResult result = MLResult.Create(resultCode); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLFoundObjects.BeginObjectQuery failed to request objects. Reason: {0}", resultCode); return(result); } // Add query to the list of pendingQueries. Query query = Query.Create(callback, filter); MLFoundObjects._instance.pendingQueries.TryAdd(queryHandle, query); return(result); } catch (System.EntryPointNotFoundException) { MLPluginLog.Error("MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found"); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found")); } }
/// <summary> /// Begin querying for found objects. /// </summary> /// <param name="callback">Callback used to report query results.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> private MLResult BeginObjectQuery(QueryResultsDelegate callback) { try { if (!MagicLeapNativeBindings.MLHandleIsValid(_instance.tracker)) { MLPluginLog.Error("MLFoundObject.BeginObjectQuery failed to request found objects. Reason: Tracker handle is invalid"); return(MLResult.Create(MLResult.Code.InvalidParam)); } NativeBindings.QueryFilterNative queryFilter = new NativeBindings.QueryFilterNative(); MLResult.Code resultCode = NativeBindings.MLFoundObjectQuery(_instance.tracker, ref queryFilter, out ulong queryHandle); MLResult result = MLResult.Create(resultCode); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLFoundObject.BeginObjectQuery failed to request objects. Reason: {0}", resultCode); return(result); } // Create query object to prepresent this newly registered found object query. NativeBindings.Query query = new NativeBindings.Query(callback, queryFilter, result); MLFoundObjects._instance.pendingQueries.Add(queryHandle, query); return(result); } catch (System.EntryPointNotFoundException) { MLPluginLog.Error("MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found"); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLFoundObjects.BeginObjectQuery failed. Reason: API symbols not found")); } }
/// <summary> /// Request the list of detected found objects. /// Callback will never be called while request is still pending. /// </summary> /// <param name="queryFilter">Filter used to customize query results.</param> /// <param name="callback"> /// Callback used to report query results. /// Callback MLResult code will never be <c>MLResult.Code.Pending</c>. /// </param> /// <returns> /// MLResult.Result inside callback will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result inside callback will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result inside callback will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> public static MLResult GetObjectsAsync(Query.Filter queryFilter, QueryResultsDelegate callback) { if (MLFoundObjects.IsValidInstance()) { // Don't allow null callbacks to be registered. if (callback == null) { MLPluginLog.Error("MLFoundObjects.GetObjects failed. Reason: Passed input callback is null."); return(MLResult.Create(MLResult.Code.InvalidParam)); } MLThreadDispatch.ScheduleWork(() => { _instance.BeginObjectQueryAsync(queryFilter, callback); return(true); }); return(MLResult.Create(MLResult.Code.Ok)); } else { MLPluginLog.ErrorFormat("MLFoundObjects.GetObjects failed. Reason: No Instance for MLFoundObjects"); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLFoundObjects.GetFoundObjects failed. Reason: No Instance for MLFoundObjects")); } }
/// <summary> /// Begin querying for planes. /// </summary> /// <param name="queryParams">All values are required, omitting values may result in unexpected behavior.</param> /// <param name="callback">Callback used to report query results.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> private MLResult BeginPlaneQuery(QueryParams queryParams, QueryResultsDelegate callback) { if (!NativeBindings.MLHandleIsValid(this.planesTracker)) { MLPluginLog.Error("MLPlanes.BeginPlaneQuery failed to request planes. Reason: Tracker handle is invalid"); return(MLResult.Create(MLResult.Code.InvalidParam)); } // Convert to native plane query parameters. NativeBindings.QueryParamsNative planeQuery = NativeBindings.QueryParamsNative.Create(); planeQuery.Data = queryParams; // Register the query with the native library and store native handle. ulong handle = MagicLeapNativeBindings.InvalidHandle; MLResult.Code resultCode = NativeBindings.MLPlanesQueryBegin(this.planesTracker, ref planeQuery, ref handle); if (resultCode != MLResult.Code.Ok) { MLResult result = MLResult.Create(resultCode); MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed to request planes. Reason: {0}", result); return(result); } // Create query object to prepresent this newly registered plane query. NativeBindings.Query query = new NativeBindings.Query((QueryResultsDelegate)callback, planeQuery.MaxResults, this.IsRequestingBoundaries(planeQuery.Flags)); this.pendingQueries.Add(handle, query); return(MLResult.Create(MLResult.Code.Ok)); }
/// <summary> /// Initializes a FoundObjects.Query class with the given values. /// </summary> /// <param name="callback">The callback that should be invoked.</param> /// <param name="queryFilter">The filter applied to the query.</param> /// <returns>A FoundObjects.Query class with the given values.</returns> public static Query Create(QueryResultsDelegate callback, Filter queryFilter) { Query q = new Query(); q.Callback = callback; q.QueryFilter = queryFilter; return(q); }
/// <summary> /// Request the list of detected found objects. /// Callback will never be called while request is still pending. /// </summary> /// <param name="callback"> /// Callback used to report query results. /// Callback MLResult code will never be <c>MLResult.Code.Pending</c>. /// </param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> public static MLResult GetObjects(QueryResultsDelegate callback) { if (MLFoundObjects.IsValidInstance()) { // Don't allow null callbacks to be registered. if (callback == null) { MLPluginLog.Error("MLFoundObject.GetObjects failed. Reason: Passed input callback is null."); return(MLResult.Create(MLResult.Code.InvalidParam)); } return(_instance.BeginObjectQuery(callback)); } else { MLPluginLog.ErrorFormat("MLFoundObject.GetObjects failed. Reason: No Instance for MLFoundObject"); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLFoundObject.GetFoundObjects failed. Reason: No Instance for MLFoundObject")); } }
/// <summary> /// Request real world quad surfaces. /// Callback will never be called while request is still pending. /// </summary> /// <param name="queryParams">All values are required, omitting values may result in unexpected behavior.</param> /// <param name="callback"> /// Callback used to report query results. /// Callback MLResult code will never be <c>MLResult.Code.Pending</c>. /// </param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> public static MLResult GetPlanes(QueryParams queryParams, QueryResultsDelegate callback) { Instance.ValidateQueryParams(ref queryParams); // Planes can't have MinHoleLength less than 0.0. queryParams.MinHoleLength = Mathf.Clamp(queryParams.MinHoleLength, 0.0f, queryParams.MinHoleLength); // Planes can't have MinPlaneArea less than 0.04. queryParams.MinPlaneArea = Mathf.Clamp(queryParams.MinPlaneArea, 0.04f, queryParams.MinPlaneArea); // Don't allow null callbacks to be registered. if (callback == null) { MLPluginLog.Error("MLPlanes.GetPlanes failed. Reason: Passed input callback is null."); return(MLResult.Create(MLResult.Code.InvalidParam)); } return(Instance.BeginPlaneQuery(queryParams, callback)); }
/// <summary> /// Request real world quad surfaces. /// Callback will never be called while request is still pending. /// </summary> /// <param name="queryParams">All values are required, omitting values may result in unexpected behavior.</param> /// <param name="callback"> /// Callback used to report query results. /// Callback MLResult code will never be <c>MLResult.Code.Pending</c>. /// </param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> public static MLResult GetPlanes(QueryParams queryParams, QueryResultsDelegate callback) { if (MLPlanes.IsValidInstance()) { _instance.ValidateQueryParams(ref queryParams); // Required flag by the CAPI, has to be set or errors will occur. queryParams.Flags |= QueryFlags.Polygons; // Don't allow null callbacks to be registered. if (callback == null) { MLPluginLog.Error("MLPlanes.GetPlanes failed. Reason: Passed input callback is null."); return(MLResult.Create(MLResult.Code.InvalidParam)); } return(_instance.BeginPlaneQuery(queryParams, callback)); } else { MLPluginLog.ErrorFormat("MLPlanes.GetPlanes failed. Reason: No Instance for MLPlanes"); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPlanes.GetPlanes failed. Reason: No Instance for MLPlanes")); } }
/// <summary> /// Begin querying for planes. /// </summary> /// <param name="queryParams">All values are required, omitting values may result in unexpected behavior.</param> /// <param name="callback">Callback used to report query results.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> private MLResult BeginPlaneQuery(QueryParams queryParams, QueryResultsDelegate callback) { try { if (!NativeBindings.MLHandleIsValid(_instance.planesTracker)) { MLPluginLog.Error("MLPlanes.BeginPlaneQuery failed to request planes. Reason: Tracker handle is invalid"); return(MLResult.Create(MLResult.Code.InvalidParam)); } bool BeginQuery() { if (MLPlanes.IsValidInstance()) { NativeBindings.QueryParamsNative planeQuery = new NativeBindings.QueryParamsNative() { Data = queryParams }; ulong queryHandle = MagicLeapNativeBindings.InvalidHandle; MLResult.Code resultCode = NativeBindings.MLPlanesQueryBegin(_instance.planesTracker, ref planeQuery, ref queryHandle); if (resultCode != MLResult.Code.Ok) { MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed to request planes. Reason: {0}", MLResult.CodeToString(resultCode)); return(true); } // Create query object to prepresent this newly registered plane query. NativeBindings.Query query = new NativeBindings.Query((QueryResultsDelegate)callback, planeQuery.MaxResults, _instance.IsRequestingBoundaries(planeQuery.Flags)); bool GetPlanesResults() { if (MLPlanes.IsValidInstance()) { // Request the update. resultCode = NativeBindings.MLPlanesQueryGetResultsWithBoundaries(_instance.planesTracker, queryHandle, query.PlanesResultsUnmanaged, out uint numResults, ref query.PlaneBoundariesList); if (resultCode == MLResult.Code.Pending) { return(false); } if (resultCode == MLResult.Code.Ok) { query.ExtractPlanesFromQueryResults(numResults); resultCode = NativeBindings.MLPlanesReleaseBoundariesList(_instance.planesTracker, ref query.PlaneBoundariesList); if (resultCode == MLResult.Code.Ok) { query.Result = MLResult.Create(resultCode); if (query.Planes == null) { query.Planes = new Plane[] { }; } if (query.PlaneBoundaries == null) { query.PlaneBoundaries = new Boundaries[] { }; } MLThreadDispatch.ScheduleMain(() => { if (MLPlanes.IsValidInstance()) { callback(query.Result, query.Planes, query.PlaneBoundaries); } else { MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed. Reason: No Instance for MLPlanes"); } }); } else { MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed to release boundaries list. Reason: {0}", MLResult.CodeToString(resultCode)); } } else { MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed to query planes. Reason: {0}", MLResult.CodeToString(resultCode)); } } else { MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed. Reason: No Instance for MLPlanes"); } return(true); } MLThreadDispatch.ScheduleWork(GetPlanesResults); } else { MLPluginLog.ErrorFormat("MLPlanes.BeginPlaneQuery failed. Reason: No Instance for MLPlanes"); } return(true); } MLThreadDispatch.ScheduleWork(BeginQuery); return(MLResult.Create(MLResult.Code.Ok)); } catch (System.EntryPointNotFoundException) { MLPluginLog.Error("MLPlanes.BeginPlaneQuery failed. Reason: API symbols not found"); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPlanes.BeginPlaneQuery failed. Reason: API symbols not found")); } }
/// <summary> /// Initializes a new instance of the <see cref="Query"/> struct. /// </summary> /// <param name="callback">The callback that should be invoked.</param> /// <param name="queryFilter">The filter applied to the query.</param> /// <param name="result">The result of the query.</param> public Query(QueryResultsDelegate callback, NativeBindings.QueryFilterNative queryFilter, MLResult result) { this.Callback = callback; this.QueryFilter = queryFilter; this.Result = result; }