Bounding Volume Hierarchy container. (BVH tree) More...
#include <bvh.hpp>
Classes | |
struct | Node |
BVH node container. More... | |
Public Member Functions | |
Bvh (const uint8 *vertices, const uint8 *indices, const Aabb &rootAabb, uint32 indexCount, uint32 vertexSize, uint32 indexSize, const f32x4 *centroids=nullptr) | |
Creates a new BVH from the triangle array. | |
Bvh (const Aabb *aabbs, const Aabb &rootAabb, uint32 aabbCount, const f32x4 *centroids=nullptr) | |
Creates a new BVH from the AABB array. | |
Bvh ()=default | |
Creates a new empty BVH. | |
const vector< Node > & | getNodes () const noexcept |
Returns BVH node array. | |
const vector< uint32 > & | getPrimitives () const noexcept |
Returns BVH primitive array. | |
const vector< f32x4 > & | getCentroids () const noexcept |
Returns BVH centroid array. | |
stack< Node * > & | getNodeStack () noexcept |
Returns BVH node stack cache. | |
void | recreate (const uint8 *vertices, const uint8 *indices, const Aabb &rootAabb, uint32 indexCount, uint32 vertexSize, uint32 indexSize, const f32x4 *centroids=nullptr) |
Recreates BVH from the triangle array. | |
void | recreate (const Aabb *aabbs, const Aabb &rootAabb, uint32 aabbCount, const f32x4 *centroids=nullptr) |
Recreates BVH from the AABB array. | |
uint32 | collectInFrustum (const Plane *planes, uint8 planeCount, uint32 *primitives, stack< Node * > *nodeStack=nullptr) |
Collects all primitives inside specified frustum. | |
void | traverse (const std::function< bool(const Bvh::Node &)> &isIntersected, const std::function< void(uint32, uint32)> &onLeaf) |
Traverses BVH tree. | |
Protected Attributes | |
vector< Node > | nodes |
vector< uint32 > | primitives |
vector< f32x4 > | centroids |
stack< Node * > | nodeStack |
Bounding Volume Hierarchy container. (BVH tree)
A data structure commonly used in ray tracing, and collision detection to efficiently manage and process large sets of geometric objects, such as triangles or 3D models. The BVH organizes these objects into a hierarchical tree of bounding volumes (usually axis-aligned bounding boxes or spheres), allowing for faster queries related to visibility, collisions, and intersections.
Bvh | ( | const uint8 * | vertices, |
const uint8 * | indices, | ||
const Aabb & | rootAabb, | ||
uint32 | indexCount, | ||
uint32 | vertexSize, | ||
uint32 | indexSize, | ||
const f32x4 * | centroids = nullptr ) |
Creates a new BVH from the triangle array.
[in] | vertices | target vertex array |
[in] | indices | target index array |
[in] | rootAabb | root node AABB |
indexCount | index array size | |
vertexSize | size of the vertex in bytes | |
indexSize | size of the index in bytes | |
[in] | centroids | precalculated centroid array |
Bvh | ( | const Aabb * | aabbs, |
const Aabb & | rootAabb, | ||
uint32 | aabbCount, | ||
const f32x4 * | centroids = nullptr ) |
Creates a new BVH from the AABB array.
[in] | aabbs | target AABB array |
[in] | rootAabb | root node AABB |
aabbCount | AABB array size | |
[in] | centroids | precalculated centroid array |
void recreate | ( | const uint8 * | vertices, |
const uint8 * | indices, | ||
const Aabb & | rootAabb, | ||
uint32 | indexCount, | ||
uint32 | vertexSize, | ||
uint32 | indexSize, | ||
const f32x4 * | centroids = nullptr ) |
Recreates BVH from the triangle array.
[in] | vertices | target vertex array |
[in] | indices | target index array |
[in] | rootAabb | root node AABB |
indexCount | index array size | |
vertexSize | size of the vertex in bytes | |
indexSize | size of the index in bytes | |
[in] | centroids | precalculated centroid array or null |
void recreate | ( | const Aabb * | aabbs, |
const Aabb & | rootAabb, | ||
uint32 | aabbCount, | ||
const f32x4 * | centroids = nullptr ) |
Recreates BVH from the AABB array.
[in] | aabbs | target AABB array |
[in] | rootAabb | root node AABB |
aabbCount | AABB array size | |
[in] | centroids | precalculated centroid array or null |
uint32 collectInFrustum | ( | const Plane * | planes, |
uint8 | planeCount, | ||
uint32 * | primitives, | ||
stack< Node * > * | nodeStack = nullptr ) |
Collects all primitives inside specified frustum.
[in] | planes | target frustum planes |
planeCount | frustum plane count | |
[out] | primitives | collected primitives array |
[in] | nodeStack | local node stack or null |
|
inline |
Traverses BVH tree.
[in] | isIntersected | calls on each node to check for intersection |
[in] | onLeaf | calls on leaf nodes to process primitives |