feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -39,7 +39,7 @@ void Body::SetMotionType(EMotionType inMotionType)
if (mMotionType == inMotionType)
return;
JPH_ASSERT(inMotionType == EMotionType::Static || mMotionProperties != nullptr, "Body needs to be created with mAllowDynamicOrKinematic set tot true");
JPH_ASSERT(inMotionType == EMotionType::Static || mMotionProperties != nullptr, "Body needs to be created with mAllowDynamicOrKinematic set to true");
JPH_ASSERT(inMotionType != EMotionType::Static || !IsActive(), "Deactivate body first");
JPH_ASSERT(inMotionType == EMotionType::Dynamic || !IsSoftBody(), "Soft bodies can only be dynamic, you can make individual vertices kinematic by setting their inverse mass to 0");
@ -96,7 +96,7 @@ void Body::MoveKinematic(RVec3Arg inTargetPosition, QuatArg inTargetRotation, fl
void Body::CalculateWorldSpaceBoundsInternal()
{
mBounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sReplicate(1.0f));
mBounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sOne());
}
void Body::SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTimer)
@ -190,7 +190,7 @@ void Body::GetSubmergedVolume(RVec3Arg inSurfacePosition, Vec3Arg inSurfaceNorma
Plane surface_relative_to_body = Plane::sFromPointAndNormal(inSurfacePosition - mPosition, inSurfaceNormal);
// Calculate amount of volume that is submerged and what the center of buoyancy is
mShape->GetSubmergedVolume(rotation, Vec3::sReplicate(1.0f), surface_relative_to_body, outTotalVolume, outSubmergedVolume, outRelativeCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, mPosition));
mShape->GetSubmergedVolume(rotation, Vec3::sOne(), surface_relative_to_body, outTotalVolume, outSubmergedVolume, outRelativeCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, mPosition));
}
bool Body::ApplyBuoyancyImpulse(float inTotalVolume, float inSubmergedVolume, Vec3Arg inRelativeCenterOfBuoyancy, float inBuoyancy, float inLinearDrag, float inAngularDrag, Vec3Arg inFluidVelocity, Vec3Arg inGravity, float inDeltaTime)

View file

@ -31,7 +31,11 @@ class SoftBodyCreationSettings;
/// The functions that get/set the position of the body all indicate if they are relative to the center of mass or to the original position in which the shape was created.
///
/// The linear velocity is also velocity of the center of mass, to correct for this: \f$VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\f$.
class alignas(JPH_RVECTOR_ALIGNMENT) JPH_EXPORT_GCC_BUG_WORKAROUND Body : public NonCopyable
class
#ifndef JPH_PLATFORM_DOXYGEN // Doxygen gets confused here
JPH_EXPORT_GCC_BUG_WORKAROUND alignas(JPH_RVECTOR_ALIGNMENT)
#endif
Body : public NonCopyable
{
public:
JPH_OVERRIDE_NEW_DELETE
@ -281,6 +285,25 @@ public:
/// Get world space bounding box
inline const AABox & GetWorldSpaceBounds() const { return mBounds; }
#ifdef JPH_ENABLE_ASSERTS
/// Validate that the cached bounding box of the body matches the actual bounding box of the body.
/// If this check fails then there are a number of possible causes:
/// 1. Shape is being modified without notifying the system of the change. E.g. if you modify a MutableCompoundShape
/// without calling BodyInterface::NotifyShapeChanged then there will be a mismatch between the cached bounding box
/// in the broad phase and the bounding box of the Shape.
/// 2. You are calling functions postfixed with 'Internal' which are not meant to be called by the application.
/// 3. If the actual bounds and cached bounds are very close, it could mean that you have a mismatch in floating
/// point unit state between threads. E.g. one thread has flush to zero (FTZ) or denormals are zero (DAZ) set and
/// the other thread does not. Or if the rounding mode differs between threads. This can cause small differences
/// in floating point calculations. If you are using JobSystemThreadPool you can use JobSystemThreadPool::SetThreadInitFunction
/// to initialize the floating point unit state.
inline void ValidateCachedBounds() const
{
AABox actual_body_bounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sOne());
JPH_ASSERT(actual_body_bounds == mBounds, "Mismatch between cached bounding box and actual bounding box");
}
#endif // JPH_ENABLE_ASSERTS
/// Access to the motion properties
const MotionProperties *GetMotionProperties() const { JPH_ASSERT(!IsStatic()); return mMotionProperties; }
MotionProperties * GetMotionProperties() { JPH_ASSERT(!IsStatic()); return mMotionProperties; }

View file

@ -15,9 +15,10 @@ public:
JPH_OVERRIDE_NEW_DELETE
static constexpr uint32 cInvalidBodyID = 0xffffffff; ///< The value for an invalid body ID
static constexpr uint32 cBroadPhaseBit = 0x00800000; ///< This bit is used by the broadphase
static constexpr uint32 cBroadPhaseBit = 0x80000000; ///< This bit is used by the broadphase
static constexpr uint32 cMaxBodyIndex = 0x7fffff; ///< Maximum value for body index (also the maximum amount of bodies supported - 1)
static constexpr uint8 cMaxSequenceNumber = 0xff; ///< Maximum value for the sequence number
static constexpr uint cSequenceNumberShift = 23; ///< Number of bits to shift to get the sequence number
/// Construct invalid body ID
BodyID() :
@ -34,9 +35,9 @@ public:
/// Construct from index and sequence number
explicit BodyID(uint32 inID, uint8 inSequenceNumber) :
mID((uint32(inSequenceNumber) << 24) | inID)
mID((uint32(inSequenceNumber) << cSequenceNumberShift) | inID)
{
JPH_ASSERT(inID < cMaxBodyIndex); // Should not use bit pattern for invalid ID and should not use the broadphase bit
JPH_ASSERT(inID <= cMaxBodyIndex); // Should not overlap with broadphase bit or sequence number
}
/// Get index in body array
@ -51,7 +52,7 @@ public:
/// Functions querying the broadphase can (after acquiring a body lock) detect that the body has been removed (we assume that this won't happen more than 128 times in a row).
inline uint8 GetSequenceNumber() const
{
return uint8(mID >> 24);
return uint8(mID >> cSequenceNumberShift);
}
/// Returns the index and sequence number combined in an uint32

View file

@ -316,11 +316,11 @@ void BodyInterface::SetShape(const BodyID &inBodyID, const Shape *inShape, bool
{
BodyID id = body.GetID();
mBroadPhase->NotifyBodiesAABBChanged(&id, 1);
}
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
}
}
}
}
@ -346,11 +346,11 @@ void BodyInterface::NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inPreviou
{
BodyID id = body.GetID();
mBroadPhase->NotifyBodiesAABBChanged(&id, 1);
}
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
}
}
}
@ -401,11 +401,11 @@ void BodyInterface::SetPositionAndRotation(const BodyID &inBodyID, RVec3Arg inPo
{
BodyID id = body.GetID();
mBroadPhase->NotifyBodiesAABBChanged(&id, 1);
}
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
}
}
}
@ -428,11 +428,11 @@ void BodyInterface::SetPositionAndRotationWhenChanged(const BodyID &inBodyID, RV
{
BodyID id = body.GetID();
mBroadPhase->NotifyBodiesAABBChanged(&id, 1);
}
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
}
}
}
}
@ -468,11 +468,11 @@ void BodyInterface::SetPosition(const BodyID &inBodyID, RVec3Arg inPosition, EAc
{
BodyID id = body.GetID();
mBroadPhase->NotifyBodiesAABBChanged(&id, 1);
}
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
}
}
}
@ -509,11 +509,11 @@ void BodyInterface::SetRotation(const BodyID &inBodyID, QuatArg inRotation, EAct
{
BodyID id = body.GetID();
mBroadPhase->NotifyBodiesAABBChanged(&id, 1);
}
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
// Optionally activate body
if (inActivationMode == EActivation::Activate && !body.IsStatic())
ActivateBodyInternal(body);
}
}
}
@ -990,6 +990,22 @@ bool BodyInterface::GetUseManifoldReduction(const BodyID &inBodyID) const
return true;
}
void BodyInterface::SetCollisionGroup(const BodyID &inBodyID, const CollisionGroup &inCollisionGroup)
{
BodyLockWrite lock(*mBodyLockInterface, inBodyID);
if (lock.Succeeded())
lock.GetBody().SetCollisionGroup(inCollisionGroup);
}
const CollisionGroup &BodyInterface::GetCollisionGroup(const BodyID &inBodyID) const
{
BodyLockRead lock(*mBodyLockInterface, inBodyID);
if (lock.Succeeded())
return lock.GetBody().GetCollisionGroup();
else
return CollisionGroup::sInvalid;
}
TransformedShape BodyInterface::GetTransformedShape(const BodyID &inBodyID) const
{
BodyLockRead lock(*mBodyLockInterface, inBodyID);

View file

@ -28,6 +28,7 @@ class TwoBodyConstraintSettings;
class TwoBodyConstraint;
class BroadPhaseLayerFilter;
class AABox;
class CollisionGroup;
/// Class that provides operations on bodies using a body ID. Note that if you need to do multiple operations on a single body, it is more efficient to lock the body once and combine the operations.
/// All quantities are in world space unless otherwise specified.
@ -273,6 +274,12 @@ public:
bool GetUseManifoldReduction(const BodyID &inBodyID) const;
///@}
///@name Collision group
///@{
void SetCollisionGroup(const BodyID &inBodyID, const CollisionGroup &inCollisionGroup);
const CollisionGroup & GetCollisionGroup(const BodyID &inBodyID) const;
///@}
/// Get transform and shape for this body, used to perform collision detection
TransformedShape GetTransformedShape(const BodyID &inBodyID) const;

View file

@ -1014,15 +1014,15 @@ void BodyManager::Draw(const DrawSettings &inDrawSettings, const PhysicsSettings
// Draw the results of GetSupportFunction
if (inDrawSettings.mDrawGetSupportFunction)
body->mShape->DrawGetSupportFunction(inRenderer, body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), color, inDrawSettings.mDrawSupportDirection);
body->mShape->DrawGetSupportFunction(inRenderer, body->GetCenterOfMassTransform(), Vec3::sOne(), color, inDrawSettings.mDrawSupportDirection);
// Draw the results of GetSupportingFace
if (inDrawSettings.mDrawGetSupportingFace)
body->mShape->DrawGetSupportingFace(inRenderer, body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f));
body->mShape->DrawGetSupportingFace(inRenderer, body->GetCenterOfMassTransform(), Vec3::sOne());
// Draw the shape
if (inDrawSettings.mDrawShape)
body->mShape->Draw(inRenderer, body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), color, inDrawSettings.mDrawShapeColor == EShapeColor::MaterialColor, inDrawSettings.mDrawShapeWireframe || is_sensor);
body->mShape->Draw(inRenderer, body->GetCenterOfMassTransform(), Vec3::sOne(), color, inDrawSettings.mDrawShapeColor == EShapeColor::MaterialColor, inDrawSettings.mDrawShapeWireframe || is_sensor);
// Draw bounding box
if (inDrawSettings.mDrawBoundingBox)
@ -1146,9 +1146,7 @@ void BodyManager::ValidateActiveBodyBounds()
for (BodyID *id = mActiveBodies[type], *id_end = mActiveBodies[type] + mNumActiveBodies[type].load(memory_order_relaxed); id < id_end; ++id)
{
const Body *body = mBodies[id->GetIndex()];
AABox cached = body->GetWorldSpaceBounds();
AABox calculated = body->GetShape()->GetWorldSpaceBounds(body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f));
JPH_ASSERT(cached == calculated);
body->ValidateCachedBounds();
}
}
#endif // JPH_DEBUG

View file

@ -107,8 +107,8 @@ void MotionProperties::ApplyGyroscopicForceInternal(QuatArg inBodyRotation, floa
// Calculate local space inertia tensor (a diagonal in local space)
UVec4 is_zero = Vec3::sEquals(mInvInertiaDiagonal, Vec3::sZero());
Vec3 denominator = Vec3::sSelect(mInvInertiaDiagonal, Vec3::sReplicate(1.0f), is_zero);
Vec3 nominator = Vec3::sSelect(Vec3::sReplicate(1.0f), Vec3::sZero(), is_zero);
Vec3 denominator = Vec3::sSelect(mInvInertiaDiagonal, Vec3::sOne(), is_zero);
Vec3 nominator = Vec3::sSelect(Vec3::sOne(), Vec3::sZero(), is_zero);
Vec3 local_inertia = nominator / denominator; // Avoid dividing by zero, inertia in this axis will be zero
// Calculate local space angular momentum