Beispiel #1
0
        long QueryKNearest()
        {
            stopwatch.Reset();
            stopwatch.Start();

            Vector3 position = Vector3.one * 0.5f + Random.insideUnitSphere;
            int     k        = 13;

            results.Clear();
            query.KNearest(tree, position, k, results);

            stopwatch.Stop();

            return(stopwatch.ElapsedMilliseconds);
        }
        private void OnDrawGizmos()
        {
            if (query == null)
            {
                return;
            }

            Vector3 size = 0.2f * Vector3.one;

            for (int i = 0; i < points.Length; i++)
            {
                Gizmos.DrawCube(points[i].transform.position, size);
            }

            var resultIndices = new List <int>();

            Color markColor = Color.red;

            markColor.a  = 0.5f;
            Gizmos.color = markColor;

            switch (QueryType)
            {
            case QType.ClosestPoint: {
                query.ClosestPoint(tree, transform.position, resultIndices);
            }
            break;

            case QType.KNearest: {
                query.KNearest(tree, transform.position, K, resultIndices);
            }
            break;

            case QType.Radius: {
                query.Radius(tree, transform.position, Radius, 0, resultIndices);

                Gizmos.DrawWireSphere(transform.position, Radius);
            }
            break;

            case QType.Interval: {
                query.Interval(tree, transform.position - IntervalSize / 2f, transform.position + IntervalSize / 2f, resultIndices);

                Gizmos.DrawWireCube(transform.position, IntervalSize);
            }
            break;

            default:
                break;
            }

            for (int i = 0; i < resultIndices.Count; i++)
            {
                Gizmos.DrawCube(points[resultIndices[i]].transform.position, 2f * size);
            }

            Gizmos.color = Color.green;
            Gizmos.DrawCube(transform.position, 4f * size);

            if (DrawQueryNodes)
            {
                query.DrawLastQuery();
            }
        }