Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added leapfrog integration #311

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions physx/source/lowlevel/software/include/PxsRigidBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class PxsRigidBody
PX_FORCE_INLINE void clearFreezeFlag() { mInternalFlags &= ~eFREEZE_THIS_FRAME; }
PX_FORCE_INLINE void clearUnfreezeFlag() { mInternalFlags &= ~eUNFREEZE_THIS_FRAME; }
PX_FORCE_INLINE void clearAllFrameFlags() { mInternalFlags &= ~(eFREEZE_THIS_FRAME | eUNFREEZE_THIS_FRAME | eACTIVATE_THIS_FRAME | eDEACTIVATE_THIS_FRAME); }
PX_FORCE_INLINE void setLeapfrogAccelerationScale() { mAccelScale = 0.5f; }
PX_FORCE_INLINE void resetLeapfrogAccelerationScale() { mAccelScale = 1.0f; }

PX_FORCE_INLINE void resetSleepFilter() { mSleepAngVelAcc = mSleepLinVelAcc = PxVec3(0.0f); }

Expand Down
7 changes: 5 additions & 2 deletions physx/source/simulationcontroller/src/ScBodySim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,14 @@ bool BodySim::updateForces(PxReal dt, PxsRigidBody** updatedBodySims, PxU32* upd
if( (accDirty || velDirty) && ((simStateData = getSimStateData(false)) != NULL) )
{
VelocityMod* velmod = simStateData->getVelocityModData();
PxReal accelScale = 1.f;

//we don't have support for articulation yet
if (updatedBodySims)
{
updatedBodySims[index] = &getLowLevelBody();
PxsRigidBody& body = getLowLevelBody();
accelScale = body.mAccelScale;
updatedBodySims[index] = &body;
updatedBodyNodeIndices[index++] = getNodeIndex().index();
}

Expand All @@ -686,7 +689,7 @@ bool BodySim::updateForces(PxReal dt, PxsRigidBody** updatedBodySims, PxU32* upd

if (accDirty)
{
linVelDt += velmod->getLinearVelModPerSec()*dt;
linVelDt += velmod->getLinearVelModPerSec()*dt*accelScale;
angVelDt += velmod->getAngularVelModPerSec()*dt;
}

Expand Down
11 changes: 11 additions & 0 deletions physx/source/simulationcontroller/src/ScPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,17 @@ void Sc::Scene::afterIntegration(PxBaseTask* continuation)

const IG::IslandSim& islandSim = mSimpleIslandManager->getAccurateIslandSim();

{
// clear leapfrog acceleration scale for all active bodies
const PxU32 nbActiveBodies = islandSim.getNbActiveNodes(IG::Node::eRIGID_BODY_TYPE);
const PxNodeIndex*const activeBodies = islandSim.getActiveNodes(IG::Node::eRIGID_BODY_TYPE);
for (PxU32 i = 0; i < nbActiveBodies; ++i)
{
PxsRigidBody* body = islandSim.getRigidBody(activeBodies[i]);
body->resetLeapfrogAccelerationScale();
}
}

const PxU32 rigidBodyOffset = BodySim::getRigidBodyOffset();

const PxU32 numBodiesToDeactivate = islandSim.getNbNodesToDeactivate(IG::Node::eRIGID_BODY_TYPE);
Expand Down
2 changes: 2 additions & 0 deletions physx/source/simulationcontroller/src/ScScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,8 @@ void Sc::Scene::onBodySleep(BodySim* body)

void Sc::Scene::onBodyWakeUp(BodySim* body)
{
body->getLowLevelBody().setLeapfrogAccelerationScale();

if(!mSimulationEventCallback && !mOnSleepingStateChanged)
return;

Expand Down