/// <summary> /// Initializes a new instance of the <see cref="Query"/> struct. /// </summary> /// <param name="callback">The callback to trigger when query ends.</param> /// <param name="maxResults">Maximum amount of results desired.</param> /// <param name="requestBoundaries">Determines whether or not boundaries should be requested.</param> public Query(MLPlanes.QueryResultsDelegate callback, uint maxResults, bool requestBoundaries) { this.Callback = callback; this.MaxResults = maxResults; this.Planes = default; this.PlanesResultsUnmanaged = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PlaneNative)) * (int)this.MaxResults); this.PlaneBoundariesList = BoundariesListNative.Create(); this.PlaneBoundaries = default; this.Result = MLResult.Create(MLResult.Code.Ok); // Allows proper API selection based on query parameters and assigned callback. this.IsRequestingBoundaries = requestBoundaries; }
/// <summary> /// Function used to call QueryPlanes with just a GameObject. /// </summary> /// <param name="gameObject">The GameObject to use for the query parameters.</param> /// <param name="callback">The function to call when the query is done.</param> public static MLResult QueryPlanes(GameObject gameObject, MLPlanes.QueryResultsDelegate callback) { if (gameObject == null) { Debug.LogError("MLPlanesStarterKit.QueryPlanes failed because the gameObject parameter was null."); return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "gameObject parameter was null")); } _parameters.BoundsCenter = gameObject.transform.position; _parameters.BoundsRotation = gameObject.transform.rotation; _parameters.BoundsExtents = gameObject.transform.localScale; _parameters.MaxResults = 512; _parameters.MinHoleLength = 0.0f; _parameters.MinPlaneArea = 0.04f; _parameters.Flags = MLPlanes.QueryFlags.SemanticAll | MLPlanes.QueryFlags.AllOrientations; return(QueryPlanes(_parameters, callback)); }
/// <summary> /// Function used to query for planes present in the real world. /// </summary> /// <param name="parameters">The parameters to use for this query.</param> /// <param name="callback">The function to call when the query is done.</param> public static MLResult QueryPlanes(MLPlanes.QueryParams parameters, MLPlanes.QueryResultsDelegate callback) { if (MLPlanes.IsStarted) { if (isQuerying) { return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "A previous query is still in progress.")); } // Required flag by the CAPI, has to be set or errors will occur. parameters.Flags |= MLPlanes.QueryFlags.Polygons; // Planes can't have MinHoleLength less than 0.0. parameters.MinHoleLength = Mathf.Clamp(parameters.MinHoleLength, 0.0f, parameters.MinHoleLength); // Planes can't have MinPlaneArea less than 0.04. parameters.MinPlaneArea = Mathf.Clamp(parameters.MinHoleLength, 0.04f, parameters.MinPlaneArea); callback += _queryCallback; _result = MLPlanes.GetPlanes(parameters, callback); isQuerying = _result.IsOk; if (!_result.IsOk) { callback = null; Debug.LogErrorFormat("Error: MLPlanesStarterKit.QueryPlanes failed. Reason: {0}", _result); } } else { Debug.LogError("Error: MLPlanesStarterKit.QueryPlanes failed because MLPlanes was not started."); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPlanes was not started"); } return(_result); }
/// <summary> /// QueryPlanes by using boundsCenter, boundsRotation, and boundsExtents. /// </summary> /// <param name="boundsCenter">The center position to use for the bounding box which defines where planes extraction should occur.</param> /// <param name="boundsRotation">The rotation to use for the bounding box where planes extraction will occur.</param> /// <param name="boundsExtents">The size to use for the bounding box where planes extraction will occur.</param> public static MLResult QueryPlanes(Vector3 boundsCenter, Quaternion boundsRotation, Vector3 boundsExtents, MLPlanes.QueryResultsDelegate callback) { _parameters.BoundsCenter = boundsCenter; _parameters.BoundsRotation = boundsRotation; _parameters.BoundsExtents = boundsExtents; _parameters.MaxResults = 512; _parameters.MinHoleLength = 0.0f; _parameters.MinPlaneArea = 0.04f; _parameters.Flags = MLPlanes.QueryFlags.SemanticAll | MLPlanes.QueryFlags.AllOrientations; return(QueryPlanes(_parameters, callback)); }