Exemplo n.º 1
0
 public TSBBox.ContainmentType Contains(TSBBox box)
 {
     return(this.Contains(ref box));
 }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
 public abstract int Prepare(ref TSBBox box);