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

CCD contact modification faceIndex support and normal fix #505

Open
wants to merge 5 commits into
base: 3.4
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
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj
*.pdb

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

#VS files
*.vcxproj.*
*.log
*.tlog
*.map
*.exp

PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/.suo
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Browse.VC.db
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Browse.VC.db-shm
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Browse.VC.db-wal
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Browse.VC.opendb
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Solution.VC.db
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Solution.VC.db-shm
PhysX_3.4/Source/compiler/vc15win64/.vs/PhysX/v16/Solution.VC.db-wal
*.vcxproj
*.recipe
*.res
4 changes: 2 additions & 2 deletions PhysX_3.4/Include/extensions/PxMassProperties.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
Expand Down Expand Up @@ -135,7 +135,7 @@ class PxMassProperties

const PxMeshScale& s = c.scale;
mass = unscaledMass * s.scale.x * s.scale.y * s.scale.z;
centerOfMass = s.rotation.rotate(s.scale.multiply(s.rotation.rotateInv(unscaledCoM)));
centerOfMass = s.rotation.rotateInv(s.scale.multiply(s.rotation.rotate(unscaledCoM)));
inertiaTensor = scaleInertia(unscaledInertiaTensorCOM, s.rotation, s.scale);
}
break;
Expand Down
22 changes: 11 additions & 11 deletions PhysX_3.4/Source/LowLevel/software/src/PxsCCD.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
Expand Down Expand Up @@ -1005,7 +1005,7 @@ class PxsCCDAdvanceTask : public Cm::Task
mCCDContext->getCCDContactModifyCallback())
{

PX_ALIGN(16, PxU8 dataBuffer[sizeof(PxModifiableContact) + sizeof(PxContactPatch)]);
PX_ALIGN(16, PxU8 dataBuffer[sizeof(PxModifiableContact) + sizeof(PxContactPatch) + 2* sizeof(PxU32)]); // add 2 PxU32 to support faceIndex, stored in the last U32

PxContactPatch* patch = reinterpret_cast<PxContactPatch*>(dataBuffer);
PxModifiableContact* point = reinterpret_cast<PxModifiableContact*>(patch + 1);
Expand All @@ -1026,15 +1026,17 @@ class PxsCCDAdvanceTask : public Cm::Task
patch->nbContacts = 1;

patch->materialFlags = 0;
patch->internalFlags = 0; //44 //Can be a U16

patch->internalFlags = PxU32(PxContactPatch::eMODIFIABLE); //44 //Can be a U16
if (pair.mG1 == PxGeometryType::eTRIANGLEMESH || pair.mG1 == PxGeometryType::eHEIGHTFIELD)
{
patch->internalFlags |= PxContactPatch::eHAS_FACE_INDICES;
PxU32* faceIndexBuffer = (reinterpret_cast<PxU32*>(point + 1)) + 1;
*faceIndexBuffer = pair.mFaceIndex;
}

point->contact = pair.mMinToiPoint;
point->normal = pair.mMinToiNormal;
point->normal = -pair.mMinToiNormal; //CCD normal is reversed

//KS - todo - reintroduce face indices!!!!
//point.internalFaceIndex0 = PXC_CONTACT_NO_FACE_INDEX;
//point.internalFaceIndex1 = pair.mFaceIndex;
point->materialIndex0 = pair.mMaterialIndex0;
point->materialIndex1 = pair.mMaterialIndex1;
point->dynamicFriction = pair.mDynamicFriction;
Expand All @@ -1055,7 +1057,7 @@ class PxsCCDAdvanceTask : public Cm::Task
pair.mStaticFriction = point->staticFriction;
pair.mRestitution = point->restitution;
pair.mMinToiPoint = point->contact;
pair.mMinToiNormal = point->normal;
pair.mMinToiNormal = -point->normal; //reverse back normal from contact modification

}

Expand Down Expand Up @@ -2053,5 +2055,3 @@ void PxsCCDContext::runCCDModifiableContact(PxModifiableContact* PX_RESTRICT con


} //namespace physx


7 changes: 3 additions & 4 deletions PhysX_3.4/Source/LowLevelDynamics/src/DyContactPrep4.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
Expand Down Expand Up @@ -532,7 +532,8 @@ static void setupFinalizeSolverConstraints4(PxSolverContactDesc* PX_RESTRICT des
const Vec4V dotDelAngVel0 = V4MulAdd(delAngVel0X, delAngVel0X, V4MulAdd(delAngVel0Y, delAngVel0Y, V4Mul(delAngVel0Z, delAngVel0Z)));
const Vec4V dotRaXnAngVel0 = V4MulAdd(raXnZ, angVelT20, V4MulAdd(raXnY, angVelT10, V4Mul(raXnX, angVelT00)));

Vec4V unitResponse = V4MulAdd(invMass0D0, angDom0, dotDelAngVel0);
Vec4V unitResponse = V4MulAdd(dotDelAngVel0, angDom0, invMass0D0);

Vec4V vrel = V4Add(relNorVel, dotRaXnAngVel0);


Expand Down Expand Up @@ -1528,5 +1529,3 @@ SolverConstraintPrepState::Enum createFinalizeSolverContacts4(
}

}


54 changes: 42 additions & 12 deletions PhysX_3.4/Source/PhysXExtensions/src/ExtJoint.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
Expand Down Expand Up @@ -211,6 +211,26 @@ namespace Ext
return actor->getGlobalPose();
}

static PxTransform getBodyPose(const PxRigidActor* actor)
{
if (!actor)
return PxTransform(PxIdentity);
else if (actor->is<PxRigidStatic>())
return actor->getGlobalPose();
else
return actor->getGlobalPose() * static_cast<const PxRigidBody*>(actor)->getCMassLocalPose();
}

static PxTransform getComLocal(PxRigidActor* actor)
{
if (!actor)
return PxTransform(PxIdentity);
else if (actor->getType() == PxActorType::eRIGID_DYNAMIC || actor->getType() == PxActorType::eARTICULATION_LINK)
return static_cast<PxRigidBody*>(actor)->getCMassLocalPose();
else
return PxTransform(PxIdentity);
}

void getActorVelocity(const PxRigidActor* actor, PxVec3& linear, PxVec3& angular) const
{
if(!actor || actor->is<PxRigidStatic>())
Expand All @@ -224,13 +244,13 @@ namespace Ext
}


PxTransform getRelativeTransform() const
PxTransform getRelativeTransform() const
{
PxRigidActor* actor0, * actor1;
mPxConstraint->getActors(actor0, actor1);
const PxTransform t0 = getGlobalPose(actor0) * mLocalPose[0];
const PxTransform t1 = getGlobalPose(actor1) * mLocalPose[1];
return t0.transformInv(t1);
PxTransform c2b0 = getGlobalPose(actor0).transform(mLocalPose[0]),
c2b1 = getGlobalPose(actor1).transform(mLocalPose[1]);
return c2b0.transformInv(c2b1);
}

PxVec3 getRelativeLinearVelocity() const
Expand All @@ -239,26 +259,36 @@ namespace Ext
PxVec3 l0, a0, l1, a1;
mPxConstraint->getActors(actor0, actor1);

PxTransform t0 = getCom(actor0), t1 = getCom(actor1);
//COM to world
PxTransform t0 = getBodyPose(actor0),
t1 = getBodyPose(actor1);

//joint frame to COM
PxTransform c2b0 = getComLocal(actor0).transformInv(mLocalPose[0]),
c2b1 = getComLocal(actor1).transformInv(mLocalPose[1]);

getActorVelocity(actor0, l0, a0);
getActorVelocity(actor1, l1, a1);

PxVec3 p0 = t0.q.rotate(mLocalPose[0].p),
p1 = t1.q.rotate(mLocalPose[1].p);
return t0.transformInv(l1 - a1.cross(p1) - l0 + a0.cross(p0));
PxVec3 cv0ToWorld = l0 + a0.cross(t0.rotate(c2b0.p)),
cv1ToWorld = l1 + a1.cross(t1.rotate(c2b1.p));

PxQuat q0 = t0.q * c2b0.q;

return q0.rotateInv(cv1ToWorld - cv0ToWorld);
}

PxVec3 getRelativeAngularVelocity() const
PxVec3 getRelativeAngularVelocity() const
{
PxRigidActor* actor0, * actor1;
PxVec3 l0, a0, l1, a1;
mPxConstraint->getActors(actor0, actor1);

PxTransform t0 = getCom(actor0);
PxQuat cq0 = getGlobalPose(actor0).q * mLocalPose[0].q;
getActorVelocity(actor0, l0, a0);
getActorVelocity(actor1, l1, a1);

return t0.transformInv(a1 - a0);
return cq0.rotateInv(a1 - a0);
}


Expand Down
Loading