示例#1
0
 //Private Methods:
 private void GetPlanes()
 {
     MLPlanes.QueryParams query = new MLPlanes.QueryParams();
     query.MaxResults     = 20;
     query.Flags          = MLPlanes.QueryFlags.Inner | MLPlanes.QueryFlags.SemanticFloor | MLPlanes.QueryFlags.SemanticCeiling;
     query.BoundsCenter   = _mainCamera.position;
     query.BoundsRotation = _mainCamera.rotation;
     query.BoundsExtents  = _planesQueryBoundsExtents;
     MLPlanes.GetPlanes(query, HandlePlanes);
 }
示例#2
0
        private void FindWalls_Enter()
        {
            //generate virtual walls:
            _virtualWalls.Clear();
            for (int i = 1; i < _plottedCorners.Count; i++)
            {
                _virtualWalls.Add(new VirtualWall(_plottedCorners[i - 1].position, _plottedCorners[i].position));
            }

            //discover winding direction:
            float angleCount = 0;

            for (int i = 1; i < _plottedCorners.Count; i++)
            {
                Vector3 centerToPrevious = Vector3.Normalize(_plottedCorners[i - 1].position - _plottedBounds.center);
                Vector3 centerToCurrent  = Vector3.Normalize(_plottedCorners[i].position - _plottedBounds.center);
                angleCount += Vector3.SignedAngle(centerToPrevious, centerToCurrent, Vector3.up);
            }
            float windingDirection = Mathf.Sign(angleCount); //1 = clockwise, -1 = counterclockwise

            //set normals:
            for (int i = 0; i < _virtualWalls.Count; i++)
            {
                _virtualWalls[i].normal = Vector3.Normalize(Quaternion.AngleAxis(90 * windingDirection, Vector3.up) * _virtualWalls[i].Vector);
            }

            //generate world plane queries:
            for (int i = 0; i < _virtualWalls.Count; i++)
            {
                //establish and cache query:
                MLPlanes.QueryParams query = new MLPlanes.QueryParams();
                query.MaxResults       = 10;
                query.Flags            = MLPlanes.QueryFlags.Vertical | MLPlanes.QueryFlags.OrientToGravity | MLPlanes.QueryFlags.Inner;
                query.BoundsCenter     = _virtualWalls[i].Center - _virtualWalls[i].normal * (maxPlaneDepthTest * .5f);
                query.BoundsRotation   = Quaternion.LookRotation(_virtualWalls[i].normal);
                query.BoundsExtents    = new Vector3(_virtualWalls[i].Vector.magnitude, _plottedCorners[i].localScale.y, maxPlaneDepthTest);
                _virtualWalls[i].query = query;
            }

            //execute world planes queries:
            _queryCount = -1;
            FindWalls_ResolveToPhysicalWalls();
        }
示例#3
0
        /// <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);
        }