Пример #1
0
        public void Query(List <int> my, ref TSBBox aabb)
        {
            Stack <int> @new = this.stackPool.GetNew();

            @new.Push(this._root);
            while (@new.Count > 0)
            {
                int  num  = @new.Pop();
                bool flag = num == -1;
                if (!flag)
                {
                    DynamicTreeNode <T> dynamicTreeNode = this._nodes[num];
                    bool flag2 = aabb.Contains(ref dynamicTreeNode.AABB) > TSBBox.ContainmentType.Disjoint;
                    if (flag2)
                    {
                        bool flag3 = dynamicTreeNode.IsLeaf();
                        if (flag3)
                        {
                            my.Add(num);
                        }
                        else
                        {
                            @new.Push(dynamicTreeNode.Child1);
                            @new.Push(dynamicTreeNode.Child2);
                        }
                    }
                }
            }
            this.stackPool.GiveBack(@new);
        }
Пример #2
0
        public void BuildOctree()
        {
            this.triBoxes    = new TSBBox[this.tris.Length];
            this.rootNodeBox = new TSBBox(new TSVector(FP.PositiveInfinity, FP.PositiveInfinity, FP.PositiveInfinity), new TSVector(FP.NegativeInfinity, FP.NegativeInfinity, FP.NegativeInfinity));
            for (int i = 0; i < this.tris.Length; i++)
            {
                TSVector.Min(ref this.positions[this.tris[i].I1], ref this.positions[this.tris[i].I2], out this.triBoxes[i].min);
                TSVector.Min(ref this.positions[this.tris[i].I0], ref this.triBoxes[i].min, out this.triBoxes[i].min);
                TSVector.Max(ref this.positions[this.tris[i].I1], ref this.positions[this.tris[i].I2], out this.triBoxes[i].max);
                TSVector.Max(ref this.positions[this.tris[i].I0], ref this.triBoxes[i].max, out this.triBoxes[i].max);
                TSVector.Min(ref this.rootNodeBox.min, ref this.triBoxes[i].min, out this.rootNodeBox.min);
                TSVector.Max(ref this.rootNodeBox.max, ref this.triBoxes[i].max, out this.rootNodeBox.max);
            }
            List <Octree.BuildNode> list = new List <Octree.BuildNode>();

            list.Add(new Octree.BuildNode());
            list[0].box = this.rootNodeBox;
            TSBBox[] array = new TSBBox[8];
            for (int j = 0; j < this.tris.Length; j++)
            {
                int    num    = 0;
                TSBBox tSBBox = this.rootNodeBox;
                while (tSBBox.Contains(ref this.triBoxes[j]) == TSBBox.ContainmentType.Contains)
                {
                    int num2 = -1;
                    for (int k = 0; k < 8; k++)
                    {
                        this.CreateAABox(ref tSBBox, (Octree.EChild)k, out array[k]);
                        bool flag = array[k].Contains(ref this.triBoxes[j]) == TSBBox.ContainmentType.Contains;
                        if (flag)
                        {
                            num2 = k;
                            break;
                        }
                    }
                    bool flag2 = num2 == -1;
                    if (flag2)
                    {
                        list[num].triIndices.Add(j);
                        break;
                    }
                    int num3 = -1;
                    for (int l = 0; l < list[num].nodeIndices.Count; l++)
                    {
                        bool flag3 = list[list[num].nodeIndices[l]].childType == num2;
                        if (flag3)
                        {
                            num3 = l;
                            break;
                        }
                    }
                    bool flag4 = num3 == -1;
                    if (flag4)
                    {
                        Octree.BuildNode buildNode = list[num];
                        list.Add(new Octree.BuildNode
                        {
                            childType = num2,
                            box       = array[num2]
                        });
                        num    = list.Count - 1;
                        tSBBox = array[num2];
                        buildNode.nodeIndices.Add(num);
                    }
                    else
                    {
                        num    = list[num].nodeIndices[num3];
                        tSBBox = array[num2];
                    }
                }
            }
            this.nodes         = new Octree.Node[list.Count];
            this.nodeStackPool = new ArrayResourcePool <ushort>(list.Count);
            for (int m = 0; m < this.nodes.Length; m++)
            {
                this.nodes[m].nodeIndices = new ushort[list[m].nodeIndices.Count];
                for (int n = 0; n < this.nodes[m].nodeIndices.Length; n++)
                {
                    this.nodes[m].nodeIndices[n] = (ushort)list[m].nodeIndices[n];
                }
                this.nodes[m].triIndices = new int[list[m].triIndices.Count];
                list[m].triIndices.CopyTo(this.nodes[m].triIndices);
                this.nodes[m].box = list[m].box;
            }
            list.Clear();
        }