Example #1
0
            // Extracts an easily processable BVH tree from the packed version in the mesh data
            public BVHNode GetTree()
            {
                if (CompressedTree.Size == 0 || CompressedTree.GetArrayData() == null)
                {
                    return(null);
                }

                BVHNode root = new BVHNode();

                root.Min = new Vector3(AABBMin.X, AABBMin.Y, AABBMin.Z);
                root.Max = new Vector3(AABBMax.X, AABBMax.Y, AABBMax.Z);

                StaticAABBNode cnode = CompressedTree.GetArrayData().Elements[0];

                if ((cnode.IDX0 & 0x80) > 0)
                {
                    root.Left  = buildTree(root.Min, root.Max, 1);
                    root.Right = buildTree(root.Min, root.Max, ((((uint)cnode.IDX0 & 0x7F) << 8) | (uint)cnode.IDX1) * 2);
                }
                else
                {
                    root.IsTerminal = true;
                    root.Index      = (((uint)cnode.IDX0 & 0x7F) << 8) | (uint)cnode.IDX1;
                }

                return(root);
            }
Example #2
0
            // Recursively builds the BVH tree from the compressed packed array
            private BVHNode buildTree(Vector3 parentBBMin, Vector3 parentBBMax, uint nodeIndex)
            {
                BVHNode        node  = new BVHNode();
                StaticAABBNode cnode = CompressedTree.GetArrayData().Elements[(int)nodeIndex];

                node.Min = cnode.DecompressMin(parentBBMin, parentBBMax);
                node.Max = cnode.DecompressMax(parentBBMin, parentBBMax);

                if ((cnode.IDX0 & 0x80) > 0)
                {
                    node.Left  = buildTree(node.Min, node.Max, nodeIndex + 1);
                    node.Right = buildTree(node.Min, node.Max, nodeIndex + ((((uint)cnode.IDX0 & 0x7F) << 8) | (uint)cnode.IDX1) * 2);
                }
                else
                {
                    node.IsTerminal = true;
                    node.Index      = (((uint)cnode.IDX0 & 0x7F) << 8) | (uint)cnode.IDX1;
                }
                return(node);
            }