| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/CompoundShape.h> |
| 8 |
#include <Jolt/Physics/Collision/SortReverseAndStore.h> |
| 9 |
#include <Jolt/Math/HalfFloat.h> |
| 10 |
|
| 11 |
JPH_NAMESPACE_BEGIN |
| 12 |
|
| 13 |
class CollideShapeSettings; |
| 14 |
class TempAllocator; |
| 15 |
|
| 16 |
|
| 17 |
class JPH_EXPORT StaticCompoundShapeSettings final : public CompoundShapeSettings |
| 18 |
{ |
| 19 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, StaticCompoundShapeSettings) |
| 20 |
|
| 21 |
public: |
| 22 |
|
| 23 |
virtual ShapeResult Create() const override; |
| 24 |
|
| 25 |
|
| 26 |
ShapeResult Create(TempAllocator &inTempAllocator) const; |
| 27 |
}; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class JPH_EXPORT StaticCompoundShape final : public CompoundShape |
| 33 |
{ |
| 34 |
public: |
| 35 |
JPH_OVERRIDE_NEW_DELETE |
| 36 |
|
| 37 |
|
| 38 |
StaticCompoundShape() : CompoundShape(EShapeSubType::StaticCompound) { } |
| 39 |
StaticCompoundShape(const StaticCompoundShapeSettings &inSettings, TempAllocator &inTempAllocator, ShapeResult &outResult); |
| 40 |
|
| 41 |
|
| 42 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 43 |
virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 44 |
|
| 45 |
|
| 46 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 47 |
|
| 48 |
|
| 49 |
virtual void CollectTransformedShapes(const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const override; |
| 50 |
|
| 51 |
|
| 52 |
virtual int GetIntersectingSubShapes(const AABox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override; |
| 53 |
|
| 54 |
|
| 55 |
virtual int GetIntersectingSubShapes(const OrientedBox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override; |
| 56 |
|
| 57 |
|
| 58 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 59 |
|
| 60 |
|
| 61 |
virtual Stats GetStats() const override { return Stats(sizeof(*this) + mSubShapes.size() * sizeof(SubShape) + mNodes.size() * sizeof(Node), 0); } |
| 62 |
|
| 63 |
|
| 64 |
static void sRegister(); |
| 65 |
|
| 66 |
protected: |
| 67 |
|
| 68 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 69 |
|
| 70 |
private: |
| 71 |
|
| 72 |
template <class BoxType> |
| 73 |
struct GetIntersectingSubShapesVisitorSC : public GetIntersectingSubShapesVisitor<BoxType> |
| 74 |
{ |
| 75 |
using GetIntersectingSubShapesVisitor<BoxType>::GetIntersectingSubShapesVisitor; |
| 76 |
|
| 77 |
JPH_INLINE bool ShouldVisitNode(int inStackTop) const |
| 78 |
{ |
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
JPH_INLINE int VisitNodes(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ, UVec4 &ioProperties, int inStackTop) |
| 83 |
{ |
| 84 |
|
| 85 |
UVec4 collides = GetIntersectingSubShapesVisitor<BoxType>::TestBounds(inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ); |
| 86 |
return CountAndSortTrues(collides, ioProperties); |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
static void sPartition(uint *ioBodyIdx, AABox *ioBounds, int inNumber, int &outMidPoint); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
static void sPartition4(uint *ioBodyIdx, AABox *ioBounds, int inBegin, int inEnd, int *outSplit); |
| 98 |
|
| 99 |
|
| 100 |
static void sCollideCompoundVsShape(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter); |
| 101 |
static void sCollideShapeVsCompound(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter); |
| 102 |
static void sCastShapeVsCompound(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector); |
| 103 |
|
| 104 |
|
| 105 |
static constexpr int cStackSize = 128; |
| 106 |
|
| 107 |
template <class Visitor> |
| 108 |
JPH_INLINE void WalkTree(Visitor &ioVisitor) const; |
| 109 |
|
| 110 |
|
| 111 |
enum : uint32 |
| 112 |
{ |
| 113 |
IS_SUBSHAPE = 0x80000000, |
| 114 |
INVALID_NODE = 0x7fffffff, |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
struct Node |
| 119 |
{ |
| 120 |
void SetChildBounds(uint inIndex, const AABox &inBounds); |
| 121 |
void SetChildInvalid(uint inIndex); |
| 122 |
|
| 123 |
HalfFloat mBoundsMinX[4]; |
| 124 |
HalfFloat mBoundsMinY[4]; |
| 125 |
HalfFloat mBoundsMinZ[4]; |
| 126 |
HalfFloat mBoundsMaxX[4]; |
| 127 |
HalfFloat mBoundsMaxY[4]; |
| 128 |
HalfFloat mBoundsMaxZ[4]; |
| 129 |
uint32 mNodeProperties[4]; |
| 130 |
}; |
| 131 |
|
| 132 |
static_assert(sizeof(Node) == 64, "Node should be 64 bytes"); |
| 133 |
|
| 134 |
using Nodes = Array<Node>; |
| 135 |
|
| 136 |
Nodes mNodes; |
| 137 |
}; |
| 138 |
|
| 139 |
JPH_NAMESPACE_END |