Esempio n. 1
0
        private int RebuildFromInternal(MeshNode[] nodes, int from, int to, bool odd)
        {
            if (to - from <= 0)
            {
                throw new ArgumentException();
            }
            if (to - from == 1)
            {
                return(this.GetBox(nodes[from]));
            }
            IntRect rect = BBTree.NodeBounds(nodes, from, to);
            int     box  = this.GetBox(rect);

            if (to - from == 2)
            {
                this.arr[box].left  = this.GetBox(nodes[from]);
                this.arr[box].right = this.GetBox(nodes[from + 1]);
                return(box);
            }
            int num;

            if (odd)
            {
                int divider = (rect.xmin + rect.xmax) / 2;
                num = BBTree.SplitByX(nodes, from, to, divider);
            }
            else
            {
                int divider2 = (rect.ymin + rect.ymax) / 2;
                num = BBTree.SplitByZ(nodes, from, to, divider2);
            }
            if (num == from || num == to)
            {
                if (!odd)
                {
                    int divider3 = (rect.xmin + rect.xmax) / 2;
                    num = BBTree.SplitByX(nodes, from, to, divider3);
                }
                else
                {
                    int divider4 = (rect.ymin + rect.ymax) / 2;
                    num = BBTree.SplitByZ(nodes, from, to, divider4);
                }
                if (num == from || num == to)
                {
                    num = (from + to) / 2;
                }
            }
            this.arr[box].left  = this.RebuildFromInternal(nodes, from, num, !odd);
            this.arr[box].right = this.RebuildFromInternal(nodes, num, to, !odd);
            return(box);
        }
Esempio n. 2
0
        private int RebuildFromInternal(TriangleMeshNode[] nodes, int[] permutation, IntRect[] nodeBounds, int from, int to, bool odd)
        {
            IntRect rect = BBTree.NodeBounds(permutation, nodeBounds, from, to);
            int     box  = this.GetBox(rect);

            if (to - from <= 4)
            {
                int num = this.tree[box].nodeOffset = this.leafNodes * 4;
                this.EnsureNodeCapacity(num + 4);
                this.leafNodes++;
                for (int i = 0; i < 4; i++)
                {
                    this.nodeLookup[num + i] = ((i >= to - from) ? null : nodes[permutation[from + i]]);
                }
                return(box);
            }
            int num2;

            if (odd)
            {
                int divider = (rect.xmin + rect.xmax) / 2;
                num2 = BBTree.SplitByX(nodes, permutation, from, to, divider);
            }
            else
            {
                int divider2 = (rect.ymin + rect.ymax) / 2;
                num2 = BBTree.SplitByZ(nodes, permutation, from, to, divider2);
            }
            if (num2 == from || num2 == to)
            {
                if (!odd)
                {
                    int divider3 = (rect.xmin + rect.xmax) / 2;
                    num2 = BBTree.SplitByX(nodes, permutation, from, to, divider3);
                }
                else
                {
                    int divider4 = (rect.ymin + rect.ymax) / 2;
                    num2 = BBTree.SplitByZ(nodes, permutation, from, to, divider4);
                }
                if (num2 == from || num2 == to)
                {
                    num2 = (from + to) / 2;
                }
            }
            this.tree[box].left  = this.RebuildFromInternal(nodes, permutation, nodeBounds, from, num2, !odd);
            this.tree[box].right = this.RebuildFromInternal(nodes, permutation, nodeBounds, num2, to, !odd);
            return(box);
        }