|
@@ -12,7 +12,7 @@
|
|
|
#include <Jolt/Physics/Collision/CollideShape.h>
|
|
|
#include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
|
|
|
#include <Jolt/Physics/Collision/Shape/ScaledShape.h>
|
|
|
-#include <Jolt/Physics/Collision/InternalEdgeRemovingCollector.h>
|
|
|
+#include <Jolt/Physics/Collision/CollisionDispatch.h>
|
|
|
#include <Jolt/Core/QuickSort.h>
|
|
|
#include <Jolt/Geometry/ConvexSupport.h>
|
|
|
#include <Jolt/Geometry/GJKClosestPoint.h>
|
|
@@ -346,84 +346,16 @@ void CharacterVirtual::CheckCollision(RVec3Arg inPosition, QuatArg inRotation, V
|
|
|
settings.mBackFaceMode = mBackFaceMode;
|
|
|
settings.mActiveEdgeMovementDirection = inMovementDirection;
|
|
|
settings.mMaxSeparationDistance = mCharacterPadding + inMaxSeparationDistance;
|
|
|
+ settings.mActiveEdgeMode = EActiveEdgeMode::CollideOnlyWithActive;
|
|
|
|
|
|
// Body filter
|
|
|
IgnoreSingleBodyFilterChained body_filter(mInnerBodyID, inBodyFilter);
|
|
|
|
|
|
- // Collide shape
|
|
|
- if (mEnhancedInternalEdgeRemoval)
|
|
|
- {
|
|
|
- // Version that does additional work to remove internal edges
|
|
|
- settings.mActiveEdgeMode = EActiveEdgeMode::CollideWithAll;
|
|
|
- settings.mCollectFacesMode = ECollectFacesMode::CollectFaces;
|
|
|
-
|
|
|
- // This is a copy of NarrowPhaseQuery::CollideShape with additional logic to wrap the collector in an InternalEdgeRemovingCollector and flushing that collector after every body
|
|
|
- class MyCollector : public CollideShapeBodyCollector
|
|
|
- {
|
|
|
- public:
|
|
|
- MyCollector(const Shape *inShape, RMat44Arg inCenterOfMassTransform, const CollideShapeSettings &inCollideShapeSettings, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, const BodyLockInterface &inBodyLockInterface, const BodyFilter &inBodyFilter, const ShapeFilter &inShapeFilter) :
|
|
|
- CollideShapeBodyCollector(ioCollector),
|
|
|
- mShape(inShape),
|
|
|
- mCenterOfMassTransform(inCenterOfMassTransform),
|
|
|
- mBaseOffset(inBaseOffset),
|
|
|
- mCollideShapeSettings(inCollideShapeSettings),
|
|
|
- mBodyLockInterface(inBodyLockInterface),
|
|
|
- mBodyFilter(inBodyFilter),
|
|
|
- mShapeFilter(inShapeFilter),
|
|
|
- mCollector(ioCollector)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- virtual void AddHit(const ResultType &inResult) override
|
|
|
- {
|
|
|
- // See NarrowPhaseQuery::CollideShape
|
|
|
- if (mBodyFilter.ShouldCollide(inResult))
|
|
|
- {
|
|
|
- BodyLockRead lock(mBodyLockInterface, inResult);
|
|
|
- if (lock.SucceededAndIsInBroadPhase())
|
|
|
- {
|
|
|
- const Body &body = lock.GetBody();
|
|
|
- if (mBodyFilter.ShouldCollideLocked(body))
|
|
|
- {
|
|
|
- TransformedShape ts = body.GetTransformedShape();
|
|
|
- mCollector.OnBody(body);
|
|
|
- lock.ReleaseLock();
|
|
|
- ts.CollideShape(mShape, Vec3::sReplicate(1.0f), mCenterOfMassTransform, mCollideShapeSettings, mBaseOffset, mCollector, mShapeFilter);
|
|
|
-
|
|
|
- // After each body, we need to flush the InternalEdgeRemovingCollector because it uses 'ts' as context and it will go out of scope at the end of this block
|
|
|
- mCollector.Flush();
|
|
|
-
|
|
|
- UpdateEarlyOutFraction(mCollector.GetEarlyOutFraction());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // Select the right function
|
|
|
+ auto collide_shape_function = mEnhancedInternalEdgeRemoval? &NarrowPhaseQuery::CollideShapeWithInternalEdgeRemoval : &NarrowPhaseQuery::CollideShape;
|
|
|
|
|
|
- const Shape * mShape;
|
|
|
- RMat44 mCenterOfMassTransform;
|
|
|
- RVec3 mBaseOffset;
|
|
|
- const CollideShapeSettings & mCollideShapeSettings;
|
|
|
- const BodyLockInterface & mBodyLockInterface;
|
|
|
- const BodyFilter & mBodyFilter;
|
|
|
- const ShapeFilter & mShapeFilter;
|
|
|
- InternalEdgeRemovingCollector mCollector;
|
|
|
- };
|
|
|
-
|
|
|
- // Calculate bounds for shape and expand by max separation distance
|
|
|
- AABox bounds = inShape->GetWorldSpaceBounds(transform, Vec3::sReplicate(1.0f));
|
|
|
- bounds.ExpandBy(Vec3::sReplicate(settings.mMaxSeparationDistance));
|
|
|
-
|
|
|
- // Do broadphase test
|
|
|
- MyCollector collector(inShape, transform, settings, inBaseOffset, ioCollector, mSystem->GetBodyLockInterface(), body_filter, inShapeFilter);
|
|
|
- mSystem->GetBroadPhaseQuery().CollideAABox(bounds, collector, inBroadPhaseLayerFilter, inObjectLayerFilter);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Version that uses the cached active edges
|
|
|
- settings.mActiveEdgeMode = EActiveEdgeMode::CollideOnlyWithActive;
|
|
|
-
|
|
|
- mSystem->GetNarrowPhaseQuery().CollideShape(inShape, Vec3::sReplicate(1.0f), transform, settings, inBaseOffset, ioCollector, inBroadPhaseLayerFilter, inObjectLayerFilter, body_filter, inShapeFilter);
|
|
|
- }
|
|
|
+ // Collide shape
|
|
|
+ (mSystem->GetNarrowPhaseQuery().*collide_shape_function)(inShape, Vec3::sReplicate(1.0f), transform, settings, inBaseOffset, ioCollector, inBroadPhaseLayerFilter, inObjectLayerFilter, body_filter, inShapeFilter);
|
|
|
|
|
|
// Also collide with other characters
|
|
|
if (mCharacterVsCharacterCollision != nullptr)
|