コード例 #1
0
        public void Execute(int i)
        {
            int  halfLength   = BVHArray.Length / 2;
            int  leafNodeId   = halfLength + i;
            AABB leafNodeAABB = BVHArray[leafNodeId].aabb;
            int  parentIndex  = BVHArray[leafNodeId].ParentNodeIndex;
            int  wait         = 0;

            while (parentIndex != -1)
            {
                BVHNode parent = BVHArray[parentIndex];
                if (parent.IsValid < 1)
                {
                    parent.aabb           = leafNodeAABB;
                    parent.IsValid        = 1;
                    BVHArray[parentIndex] = parent;
                    break;
                }
                else
                {
                    parent.aabb           = Utils.GetEncompassingAABB(parent.aabb, leafNodeAABB);
                    parent.IsValid        = 2;
                    BVHArray[parentIndex] = parent;
                }
                leafNodeAABB = parent.aabb;
                parentIndex  = parent.ParentNodeIndex;
            }
        }
コード例 #2
0
        public void Execute(int i)
        {
            BVHNode node = BVHArray[i];

            node.ParentNodeIndex = i == 0 ? -1 : ParentIndex[i];
            BVHArray[i]          = node;
        }
コード例 #3
0
        public void Execute(int index)
        {
            /*if (index == 200 || index == 199 || index == 201 || index == 202 || index == 203)
             * {
             *  int kk = 0;
             * }*/
            int  halfBVHSize = BVHArray.Length / 2;
            int2 range       = determineRange(index);
            int  first       = range.x;
            int  last        = range.y;


            // Determine where to split the range.

            int split = findSplit(first, last);

            int childAIndex = split == first ? split + halfBVHSize : split;
            int childBIndex = (split + 1) == last ? split + halfBVHSize + 1 : split + 1;

            BVHNode thisnode = new BVHNode();

            thisnode.RightNodeIndex = childBIndex;
            thisnode.LeftNodeIndex  = childAIndex;
            thisnode.EntityId       = -1;
            thisnode.IsValid        = 0;//No AABB Updated
            BVHArray[index]         = thisnode;

            ParentIndex[childAIndex] = index;
            ParentIndex[childBIndex] = index;
        }
コード例 #4
0
            public void Execute(int index)
            {
                int  halfBVHSize = BVHArray.Length / 2;
                int2 range       = determineRange(index);
                int  first       = range.x;
                int  last        = range.y;

                // Determine where to split the range.

                int split = findSplit(first, last);

                int childAIndex = split == first ? split + halfBVHSize : split;
                int childBIndex = (split + 1) == last ? split + halfBVHSize + 1 : split + 1;

                BVHNode thisnode = BVHArray[index];

                thisnode.RightNodeIndex = childBIndex;
                thisnode.LeftNodeIndex  = childAIndex;
                thisnode.EntityId       = -1;
                thisnode.IsValid        = 0;//No AABB Updated
                BVHArray[index]         = thisnode;

                BVHNode leftnode = BVHArray[childAIndex];

                leftnode.ParentNodeIndex = index;
                BVHArray[childAIndex]    = leftnode;

                BVHNode rightnode = BVHArray[childBIndex];

                rightnode.ParentNodeIndex = index;
                BVHArray[childBIndex]     = rightnode;
            }
コード例 #5
0
            public void Execute(int i)
            {
                BVHNode bvhNode = BVHArray[i];

                bvhNode.IsValid         = 0;
                bvhNode.ParentNodeIndex = -1;
                BVHArray[i]             = bvhNode;
            }
コード例 #6
0
        public void Execute(int i)
        {
            int     halfLength  = BVHArray.Length / 2;
            int     entityindex = indexConverter[i];
            int     bvhIndex    = halfLength + i;
            BVHNode bvhNode     = BVHArray[bvhIndex];

            bvhNode.aabb           = AABB[entityindex];
            bvhNode.EntityId       = entityindex;
            bvhNode.RightNodeIndex = bvhIndex;
            bvhNode.LeftNodeIndex  = -1;
            bvhNode.IsValid        = 2;
            BVHArray[bvhIndex]     = bvhNode;
        }
コード例 #7
0
        public static bool ValidateBVH(NativeArray <BVHNode> BVHArray)
        {
            int[] used = new int[BVHArray.Length];
            used[0] = 1;
            Stack <int> nextnodes = new Stack <int>();

            nextnodes.Push(0);
            while (nextnodes.Count > 0)
            {
                int     val      = nextnodes.Pop();
                BVHNode thisnode = BVHArray[val];
                if (thisnode.LeftNodeIndex >= 0 && val != thisnode.LeftNodeIndex)
                {
                    nextnodes.Push(thisnode.LeftNodeIndex);
                    used[thisnode.LeftNodeIndex]++;
                }

                if (thisnode.RightNodeIndex >= 0 && val != thisnode.RightNodeIndex)
                {
                    nextnodes.Push(thisnode.RightNodeIndex);
                    used[thisnode.RightNodeIndex]++;
                }
            }

            bool result = true;

            for (int i = 0; i < BVHArray.Length; i++)
            {
                if (used[i] > 1)
                {
                    Debug.Log("multiple " + i);
                    result = false;
                }
            }

            DrawAABB(BVHArray);

            DrawTree(BVHArray, 0, 0);
            return(result);
        }