| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/CompoundShape.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
class CollideShapeSettings; |
| 12 |
|
| 13 |
|
| 14 |
class JPH_EXPORT MutableCompoundShapeSettings final : public CompoundShapeSettings |
| 15 |
{ |
| 16 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, MutableCompoundShapeSettings) |
| 17 |
|
| 18 |
public: |
| 19 |
|
| 20 |
virtual ShapeResult Create() const override; |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class JPH_EXPORT MutableCompoundShape final : public CompoundShape |
| 33 |
{ |
| 34 |
public: |
| 35 |
JPH_OVERRIDE_NEW_DELETE |
| 36 |
|
| 37 |
|
| 38 |
MutableCompoundShape() : CompoundShape(EShapeSubType::MutableCompound) { } |
| 39 |
MutableCompoundShape(const MutableCompoundShapeSettings &inSettings, ShapeResult &outResult); |
| 40 |
|
| 41 |
|
| 42 |
Ref<MutableCompoundShape> Clone() const; |
| 43 |
|
| 44 |
|
| 45 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 46 |
virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 47 |
|
| 48 |
|
| 49 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 50 |
|
| 51 |
|
| 52 |
virtual void CollectTransformedShapes(const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const override; |
| 53 |
|
| 54 |
|
| 55 |
virtual int GetIntersectingSubShapes(const AABox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override; |
| 56 |
|
| 57 |
|
| 58 |
virtual int GetIntersectingSubShapes(const OrientedBox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const override; |
| 59 |
|
| 60 |
|
| 61 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 62 |
|
| 63 |
|
| 64 |
virtual Stats GetStats() const override { return Stats(sizeof(*this) + mSubShapes.size() * sizeof(SubShape) + mSubShapeBounds.size() * sizeof(Bounds), 0); } |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
uint AddShape(Vec3Arg inPosition, QuatArg inRotation, const Shape *inShape, uint32 inUserData = 0, uint inIndex = UINT_MAX); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
void RemoveShape(uint inIndex); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
void ModifyShape(uint inIndex, Vec3Arg inPosition, QuatArg inRotation); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
void ModifyShape(uint inIndex, Vec3Arg inPosition, QuatArg inRotation, const Shape *inShape); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
void ModifyShapes(uint inStartIndex, uint inNumber, const Vec3 *inPositions, const Quat *inRotations, uint inPositionStride = sizeof(Vec3), uint inRotationStride = sizeof(Quat)); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
void AdjustCenterOfMass(); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
static void sRegister(); |
| 111 |
|
| 112 |
protected: |
| 113 |
|
| 114 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 115 |
|
| 116 |
private: |
| 117 |
|
| 118 |
template <class BoxType> |
| 119 |
struct GetIntersectingSubShapesVisitorMC : public GetIntersectingSubShapesVisitor<BoxType> |
| 120 |
{ |
| 121 |
using GetIntersectingSubShapesVisitor<BoxType>::GetIntersectingSubShapesVisitor; |
| 122 |
|
| 123 |
using Result = UVec4; |
| 124 |
|
| 125 |
JPH_INLINE Result TestBlock(Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ) const |
| 126 |
{ |
| 127 |
return GetIntersectingSubShapesVisitor<BoxType>::TestBounds(inBoundsMinX, inBoundsMinY, inBoundsMinZ, inBoundsMaxX, inBoundsMaxY, inBoundsMaxZ); |
| 128 |
} |
| 129 |
|
| 130 |
JPH_INLINE bool ShouldVisitBlock(UVec4Arg inResult) const |
| 131 |
{ |
| 132 |
return inResult.TestAnyTrue(); |
| 133 |
} |
| 134 |
|
| 135 |
JPH_INLINE bool ShouldVisitSubShape(UVec4Arg inResult, uint inIndexInBlock) const |
| 136 |
{ |
| 137 |
return inResult[inIndexInBlock] != 0; |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
inline uint GetNumBlocks() const { return ((uint)mSubShapes.size() + 3) >> 2; } |
| 143 |
|
| 144 |
|
| 145 |
void EnsureSubShapeBoundsCapacity(); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
void CalculateSubShapeBounds(uint inStartIdx, uint inNumber); |
| 151 |
|
| 152 |
|
| 153 |
void CalculateLocalBounds(); |
| 154 |
|
| 155 |
template <class Visitor> |
| 156 |
JPH_INLINE void WalkSubShapes(Visitor &ioVisitor) const; |
| 157 |
|
| 158 |
|
| 159 |
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); |
| 160 |
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); |
| 161 |
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); |
| 162 |
|
| 163 |
struct Bounds |
| 164 |
{ |
| 165 |
Vec4 mMinX; |
| 166 |
Vec4 mMinY; |
| 167 |
Vec4 mMinZ; |
| 168 |
Vec4 mMaxX; |
| 169 |
Vec4 mMaxY; |
| 170 |
Vec4 mMaxZ; |
| 171 |
}; |
| 172 |
|
| 173 |
Array<Bounds> mSubShapeBounds; |
| 174 |
}; |
| 175 |
|
| 176 |
JPH_NAMESPACE_END |