Path: blob/master/thirdparty/jolt_physics/Jolt/TriangleSplitter/TriangleSplitter.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Geometry/IndexedTriangle.h>7#include <Jolt/Core/NonCopyable.h>89JPH_NAMESPACE_BEGIN1011/// A class that splits a triangle list into two parts for building a tree12class JPH_EXPORT TriangleSplitter : public NonCopyable13{14public:15/// Constructor16TriangleSplitter(const VertexList &inVertices, const IndexedTriangleList &inTriangles);1718/// Virtual destructor19virtual ~TriangleSplitter() = default;2021struct Stats22{23const char * mSplitterName = nullptr;24int mLeafSize = 0;25};2627/// Get stats of splitter28virtual void GetStats(Stats &outStats) const = 0;2930/// Helper struct to indicate triangle range before and after the split31struct Range32{33/// Constructor34Range() = default;35Range(uint inBegin, uint inEnd) : mBegin(inBegin), mEnd(inEnd) { }3637/// Get number of triangles in range38uint Count() const39{40return mEnd - mBegin;41}4243/// Start and end index (end = 1 beyond end)44uint mBegin;45uint mEnd;46};4748/// Range of triangles to start with49Range GetInitialRange() const50{51return Range(0, (uint)mSortedTriangleIdx.size());52}5354/// Split triangles into two groups left and right, returns false if no split could be made55/// @param inTriangles The range of triangles (in mSortedTriangleIdx) to process56/// @param outLeft On return this will contain the ranges for the left subpart. mSortedTriangleIdx may have been shuffled.57/// @param outRight On return this will contain the ranges for the right subpart. mSortedTriangleIdx may have been shuffled.58/// @return Returns true when a split was found59virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) = 0;6061/// Get the list of vertices62const VertexList & GetVertices() const63{64return mVertices;65}6667/// Get triangle by index68const IndexedTriangle & GetTriangle(uint inIdx) const69{70return mTriangles[mSortedTriangleIdx[inIdx]];71}7273protected:74/// Helper function to split triangles based on dimension and split value75bool SplitInternal(const Range &inTriangles, uint inDimension, float inSplit, Range &outLeft, Range &outRight);7677const VertexList & mVertices; ///< Vertices of the indexed triangles78const IndexedTriangleList & mTriangles; ///< Unsorted triangles79Array<Float3> mCentroids; ///< Unsorted centroids of triangles80Array<uint> mSortedTriangleIdx; ///< Indices to sort triangles81};8283JPH_NAMESPACE_END848586