| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Geometry/IndexedTriangle.h> |
| 8 |
#include <Jolt/Core/NonCopyable.h> |
| 9 |
|
| 10 |
JPH_NAMESPACE_BEGIN |
| 11 |
|
| 12 |
|
| 13 |
class JPH_EXPORT TriangleSplitter : public NonCopyable |
| 14 |
{ |
| 15 |
public: |
| 16 |
|
| 17 |
TriangleSplitter(const VertexList &inVertices, const IndexedTriangleList &inTriangles); |
| 18 |
|
| 19 |
|
| 20 |
virtual ~TriangleSplitter() = default; |
| 21 |
|
| 22 |
struct Stats |
| 23 |
{ |
| 24 |
const char * mSplitterName = nullptr; |
| 25 |
int mLeafSize = 0; |
| 26 |
}; |
| 27 |
|
| 28 |
|
| 29 |
virtual void GetStats(Stats &outStats) const = 0; |
| 30 |
|
| 31 |
|
| 32 |
struct Range |
| 33 |
{ |
| 34 |
|
| 35 |
Range() = default; |
| 36 |
Range(uint inBegin, uint inEnd) : mBegin(inBegin), mEnd(inEnd) { } |
| 37 |
|
| 38 |
|
| 39 |
uint Count() const |
| 40 |
{ |
| 41 |
return mEnd - mBegin; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
uint mBegin; |
| 46 |
uint mEnd; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
Range GetInitialRange() const |
| 51 |
{ |
| 52 |
return Range(0, (uint)mSortedTriangleIdx.size()); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) = 0; |
| 61 |
|
| 62 |
|
| 63 |
const VertexList & GetVertices() const |
| 64 |
{ |
| 65 |
return mVertices; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
const IndexedTriangle & GetTriangle(uint inIdx) const |
| 70 |
{ |
| 71 |
return mTriangles[mSortedTriangleIdx[inIdx]]; |
| 72 |
} |
| 73 |
|
| 74 |
protected: |
| 75 |
|
| 76 |
bool SplitInternal(const Range &inTriangles, uint inDimension, float inSplit, Range &outLeft, Range &outRight); |
| 77 |
|
| 78 |
const VertexList & mVertices; |
| 79 |
const IndexedTriangleList & mTriangles; |
| 80 |
Array<Float3> mCentroids; |
| 81 |
Array<uint> mSortedTriangleIdx; |
| 82 |
}; |
| 83 |
|
| 84 |
JPH_NAMESPACE_END |