Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
AABBTreeBuilder.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
10
12
33
36{
37public:
39 class Node
40 {
41 public:
43
45 static constexpr uint cInvalidNodeIndex = ~uint(0);
46
48 inline uint GetTriangleCount() const { return mNumTriangles; }
49
51 inline bool HasChildren() const { return mChild[0] != cInvalidNodeIndex || mChild[1] != cInvalidNodeIndex; }
52
54 uint GetMinDepth(const Array<Node> &inNodes) const;
55
57 uint GetMaxDepth(const Array<Node> &inNodes) const;
58
60 uint GetNodeCount(const Array<Node> &inNodes) const;
61
63 uint GetLeafNodeCount(const Array<Node> &inNodes) const;
64
66 uint GetTriangleCountInTree(const Array<Node> &inNodes) const;
67
69 void GetTriangleCountPerNode(const Array<Node> &inNodes, float &outAverage, uint &outMin, uint &outMax) const;
70
72 float CalculateSAHCost(const Array<Node> &inNodes, float inCostTraversal, float inCostLeaf) const;
73
75 void GetNChildren(const Array<Node> &inNodes, uint inN, Array<const Node *> &outChildren) const;
76
79
81 uint mTrianglesBegin; // Index into mTriangles
82 uint mNumTriangles = 0;
83
85 uint mChild[2] = { cInvalidNodeIndex, cInvalidNodeIndex };
86
87 private:
88 friend class AABBTreeBuilder;
89
91 float CalculateSAHCostInternal(const Array<Node> &inNodes, float inCostTraversalDivSurfaceArea, float inCostLeafDivSurfaceArea) const;
92
94 void GetTriangleCountPerNodeInternal(const Array<Node> &inNodes, float &outAverage, uint &outAverageDivisor, uint &outMin, uint &outMax) const;
95 };
96
98 AABBTreeBuilder(TriangleSplitter &inSplitter, uint inMaxTrianglesPerLeaf = 16);
99
101 Node * Build(AABBTreeBuilderStats &outStats);
102
104 const Array<Node> & GetNodes() const { return mNodes; }
105
107 const Array<IndexedTriangle> &GetTriangles() const { return mTriangles; }
108
109private:
110 uint BuildInternal(const TriangleSplitter::Range &inTriangles);
111
112 TriangleSplitter & mTriangleSplitter;
113 const uint mMaxTrianglesPerLeaf;
114 Array<Node> mNodes;
115 Array<IndexedTriangle> mTriangles;
116};
117
#define JPH_EXPORT
Definition Core.h:236
unsigned int uint
Definition Core.h:453
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
A node in the tree, contains the AABox for the tree and any child nodes or triangles.
Definition AABBTreeBuilder.h:40
uint mTrianglesBegin
Triangles (if no child nodes)
Definition AABBTreeBuilder.h:81
AABox mBounds
Bounding box.
Definition AABBTreeBuilder.h:78
uint GetTriangleCount() const
Get number of triangles in this node.
Definition AABBTreeBuilder.h:48
bool HasChildren() const
Check if this node has any children.
Definition AABBTreeBuilder.h:51
Helper class to build an AABB tree.
Definition AABBTreeBuilder.h:36
const Array< IndexedTriangle > & GetTriangles() const
Get all triangles.
Definition AABBTreeBuilder.h:107
const Array< Node > & GetNodes() const
Get all nodes.
Definition AABBTreeBuilder.h:104
Axis aligned box.
Definition AABox.h:16
Definition Array.h:36
A class that splits a triangle list into two parts for building a tree.
Definition TriangleSplitter.h:14
Definition AABBTreeBuilder.h:14
int mTreeMinTrianglesPerLeaf
Minimal amount of triangles in a leaf.
Definition AABBTreeBuilder.h:29
float mSAHCost
Surface Area Heuristic cost of this tree.
Definition AABBTreeBuilder.h:19
int mMaxTrianglesPerLeaf
Configured max triangles per leaf.
Definition AABBTreeBuilder.h:26
int mMaxDepth
Maximum depth of tree (number of nodes)
Definition AABBTreeBuilder.h:21
int mLeafNodeCount
Number of leaf nodes (that contain triangles)
Definition AABBTreeBuilder.h:23
float mTreeAvgTrianglesPerLeaf
Average amount of triangles in leaf nodes.
Definition AABBTreeBuilder.h:31
int mMinDepth
Minimal depth of tree (number of nodes)
Definition AABBTreeBuilder.h:20
TriangleSplitter::Stats mSplitterStats
Stats returned by the triangle splitter algorithm.
Definition AABBTreeBuilder.h:16
int mNodeCount
Number of nodes in the tree.
Definition AABBTreeBuilder.h:22
int mTreeMaxTrianglesPerLeaf
Maximal amount of triangles in a leaf.
Definition AABBTreeBuilder.h:30
Helper struct to indicate triangle range before and after the split.
Definition TriangleSplitter.h:33
Definition TriangleSplitter.h:23