29#ifndef GU_PCM_CONTACT_CONVEX_COMMON_H
30#define GU_PCM_CONTACT_CONVEX_COMMON_H
32#define PCM_MAX_CONTACTPATCH_SIZE 32
34#include "geomutils/PxContactBuffer.h"
35#include "GuVecCapsule.h"
36#include "GuPCMTriangleContactGen.h"
37#include "GuTriangleCache.h"
38#include "foundation/PxInlineArray.h"
46#define MAX_CACHE_SIZE 128
49#define LOCAL_PCM_CONTACTS_SIZE 960
69 PxU32 mNumContactPatch;
77 const aos::FloatVArg contactDist,
78 const aos::FloatVArg replaceBreakingThreshold,
87 mContactDist(contactDist),
88 mReplaceBreakingThreshold(replaceBreakingThreshold),
89 mConvexTransform(convexTransform),
90 mMeshTransform(meshTransform),
91 mMultiManifold(multiManifold),
92 mContactBuffer(contactBuffer),
93 mDeferredContacts(deferredContacts),
94 mRenderOutput(renderOutput)
102 mMeshToConvex = mConvexTransform.transformInv(mMeshTransform);
105 for(PxU32 i=0; i<PCM_MAX_CONTACTPATCH_SIZE; ++i)
107 mContactPatchPtr[i] = &mContactPatch[i];
109 mManifoldContacts = PX_CP_TO_MPCP(contactBuffer.contacts);
111 mSqReplaceBreakingThreshold = FMul(replaceBreakingThreshold, replaceBreakingThreshold);
113 mAcceptanceEpsilon = FLoad(0.996f);
117 template <PxU32 TriangleCount,
typename Derived>
120 PxU32 count = cache.mNumTriangles;
121 PxVec3* verts = cache.mVertices;
122 PxU32* vertInds = cache.mIndices;
123 PxU32* triInds = cache.mTriangleIndex;
124 PxU8* edgeFlags = cache.mEdgeFlags;
127 (
static_cast<Derived*
>(
this))->processTriangle(verts, *triInds, *edgeFlags, vertInds);
135 void prioritizeContactPatches();
136 void addManifoldPointToPatch(
const aos::Vec3VArg currentPatchNormal,
const aos::FloatVArg maxPen,
const PxU32 previousNumContacts);
137 void processContacts(
const PxU8 maxContactPerManifold,
const bool isNotLastPatch =
true);
144PX_FORCE_INLINE void PCMMeshContactGeneration::addManifoldPointToPatch(
const aos::Vec3VArg currentPatchNormal,
const aos::FloatVArg maxPen,
const PxU32 previousNumContacts)
148 bool foundPatch =
false;
150 if(mNumContactPatch > 0)
155 if(FAllGrtr(V3Dot(mContactPatch[mNumContactPatch-1].mPatchNormal, currentPatchNormal), mAcceptanceEpsilon))
161 for(PxU32 i = patch.mStartIndex; i<patch.mEndIndex; ++i)
163 for(PxU32 j = previousNumContacts; j<mNumContacts; ++j)
165 Vec3V dif = V3Sub(mManifoldContacts[j].mLocalPointB, mManifoldContacts[i].mLocalPointB);
166 FloatV d = V3Dot(dif, dif);
167 if(FAllGrtr(mSqReplaceBreakingThreshold, d))
169 if(FAllGrtr(V4GetW(mManifoldContacts[i].mLocalNormalPen), V4GetW(mManifoldContacts[j].mLocalNormalPen)))
172 mManifoldContacts[i] = mManifoldContacts[j];
174 mManifoldContacts[j] = mManifoldContacts[mNumContacts-1];
180 patch.mEndIndex = mNumContacts;
181 patch.mPatchMaxPen = FMin(patch.mPatchMaxPen, maxPen);
189 mContactPatch[mNumContactPatch].mStartIndex = previousNumContacts;
190 mContactPatch[mNumContactPatch].mEndIndex = mNumContacts;
191 mContactPatch[mNumContactPatch].mPatchMaxPen = maxPen;
192 mContactPatch[mNumContactPatch++].mPatchNormal = currentPatchNormal;
200PX_FORCE_INLINE void PCMMeshContactGeneration::prioritizeContactPatches()
205 for(PxU32 i=1; i<mNumContactPatch; ++i)
207 const PxU32 indexi = i-1;
208 if(FAllGrtr(mContactPatchPtr[indexi]->mPatchMaxPen, mContactPatchPtr[i]->mPatchMaxPen))
211 PCMContactPatch* tmp = mContactPatchPtr[indexi];
212 mContactPatchPtr[indexi] = mContactPatchPtr[i];
213 mContactPatchPtr[i] = tmp;
215 for(PxI32 j=PxI32(i-2); j>=0; j--)
217 const PxU32 indexj = PxU32(j+1);
218 if(FAllGrtrOrEq(mContactPatchPtr[indexj]->mPatchMaxPen, mContactPatchPtr[j]->mPatchMaxPen))
221 PCMContactPatch* temp = mContactPatchPtr[indexj];
222 mContactPatchPtr[indexj] = mContactPatchPtr[j];
223 mContactPatchPtr[j] = temp;
230PX_FORCE_INLINE void PCMMeshContactGeneration::processContacts(
const PxU8 maxContactPerManifold,
bool isNotLastPatch)
234 if(mNumContacts != 0)
237 prioritizeContactPatches();
239 mMultiManifold.refineContactPatchConnective(mContactPatchPtr, mNumContactPatch, mManifoldContacts, mAcceptanceEpsilon);
241 mMultiManifold.reduceManifoldContactsInDifferentPatches(mContactPatchPtr, mNumContactPatch, mManifoldContacts, mNumContacts, mSqReplaceBreakingThreshold);
243 mMultiManifold.addManifoldContactPoints(mManifoldContacts, mNumContacts, mContactPatchPtr, mNumContactPatch, mSqReplaceBreakingThreshold, mAcceptanceEpsilon, maxContactPerManifold);
246 mNumContactPatch = 0;
251 for(PxU32 i=0; i<PCM_MAX_CONTACTPATCH_SIZE; ++i)
253 mContactPatchPtr[i] = &mContactPatch[i];
264 PxU32 mTriangleIndex;
270 #pragma warning(push)
271 #pragma warning( disable : 4324 )
284 bool mIdtConvexScale;
285 bool mSilhouetteEdgesAreActive;
288 const aos::FloatVArg contactDistance,
289 const aos::FloatVArg replaceBreakingThreshold,
300 bool silhouetteEdgesAreActive,
303 ) :
PCMMeshContactGeneration(contactDistance, replaceBreakingThreshold, convexTransform, meshTransform, multiManifold, contactBuffer,
304 delayedContacts, renderOutput),
307 mConvexScaling(convexScaling),
308 mIdtConvexScale(idtConvexScale),
309 mSilhouetteEdgesAreActive(silhouetteEdgesAreActive)
314 const Vec3V hullCenterLocal = V3LoadU(mPolyData.mCenter);
316 mHullCenterMesh = mMeshToConvex.transformInv(hullCenterLocal);
320 const aos::FloatVArg contactDist,
aos::Vec3V& patchNormal);
322 bool generatePolyDataContactManifold(
Gu::TriangleV& localTriangle,
const PxU32 featureIndex,
const PxU32 triangleIndex,
const PxU8 triFlags,
Gu::MeshPersistentContact* manifoldContacts, PxU32& numContacts,
const aos::FloatVArg contactDist,
aos::Vec3V& patchNormal);
323 void generateLastContacts();
324 void addContactsToPatch(
const aos::Vec3VArg patchNormal,
const PxU32 previousNumContacts);
326 bool processTriangle(
const PxVec3* verts, PxU32 triangleIndex, PxU8 triFlags,
const PxU32* vertInds);
331 static bool processTriangle(
const Gu::PolygonalData& polyData,
SupportLocal* polyMap,
const PxVec3* verts,
const PxU32 triangleIndex, PxU8 triFlags,
const aos::FloatVArg inflation,
const bool isDoubleSided,
346 return aos::FAllGrtrOrEq(mSquareDist, data.mSquareDist) ==0;
359 const aos::Vec3VArg sphereCenter,
360 const aos::FloatVArg sphereRadius,
361 const aos::FloatVArg contactDist,
362 const aos::FloatVArg replaceBreakingThreshold,
371 contactBuffer, deferredContacts, renderOutput),
372 mSphereCenter(sphereCenter),
373 mSphereRadius(sphereRadius)
376 const FloatV inflatedSphereRadius = FAdd(sphereRadius, contactDist);
377 mSqInflatedSphereRadius = FMul(inflatedSphereRadius, inflatedSphereRadius);
380 bool processTriangle(
const PxVec3* verts, PxU32 triangleIndex, PxU8 triFlags,
const PxU32* vertInds);
381 void generateLastContacts();
382 void addToPatch(
const aos::Vec3VArg contactP,
const aos::Vec3VArg patchNormal,
397 const aos::FloatVArg contactDist,
398 const aos::FloatVArg replaceBreakingThreshold,
406 ) :
PCMMeshContactGeneration(contactDist, replaceBreakingThreshold, sphereTransform, meshTransform, multiManifold, contactBuffer,
407 deferredContacts, renderOutput),
411 mInflatedRadius = FAdd(capsule.radius, contactDist);
412 mSqInflatedRadius = FMul(mInflatedRadius, mInflatedRadius);
415 void generateEEContacts(
const aos::Vec3VArg a,
const aos::Vec3VArg b,
const aos::Vec3VArg c,
const aos::Vec3VArg normal,
const PxU32 triangleIndex,
416 const aos::Vec3VArg p,
const aos::Vec3VArg q,
const aos::FloatVArg sqInflatedRadius,
const PxU32 previousNumContacts,
Gu::MeshPersistentContact* manifoldContacts, PxU32& numContacts);
418 void generateEE(
const aos::Vec3VArg p,
const aos::Vec3VArg q,
const aos::FloatVArg sqInflatedRadius,
const aos::Vec3VArg normal,
const PxU32 triangleIndex,
421 static void generateContacts(
const aos::Vec3VArg a,
const aos::Vec3VArg b,
const aos::Vec3VArg c,
const aos::Vec3VArg planeNormal,
const aos::Vec3VArg normal,
422 const PxU32 triangleIndex,
const aos::Vec3VArg p,
const aos::Vec3VArg q,
const aos::FloatVArg inflatedRadius,
Gu::MeshPersistentContact* manifoldContacts, PxU32& numContacts);
424 static void generateEEContactsMTD(
const aos::Vec3VArg a,
const aos::Vec3VArg b,
const aos::Vec3VArg c,
const aos::Vec3VArg normal,
const PxU32 triangleIndex,
425 const aos::Vec3VArg p,
const aos::Vec3VArg q,
const aos::FloatVArg inflatedRadius,
Gu::MeshPersistentContact* manifoldContacts, PxU32& numContacts);
427 static void generateEEMTD(
const aos::Vec3VArg p,
const aos::Vec3VArg q,
const aos::FloatVArg inflatedRadius,
const aos::Vec3VArg normal,
const PxU32 trianlgeIndex,
430 bool processTriangle(
const PxVec3* verts,
const PxU32 triangleIndex, PxU8 triFlags,
const PxU32* vertInds);
432 static bool processTriangle(
const TriangleV& triangle,
const PxU32 triangleIndex,
const CapsuleV& capsule,
const aos::FloatVArg inflatedRadius,
const PxU8 triFlag,
Gu::MeshPersistentContact* manifoldContacts, PxU32& numContacts);
Definition CmScaling.h:61
Definition GuVecCapsule.h:53
Definition GuConvexSupportTable.h:83
Definition GuConvexSupportTable.h:52
Definition GuVecTriangle.h:46
Definition PxInlineArray.h:43
Definition PxRenderOutput.h:50
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition GuTriangleCache.h:96
Definition GuPCMContactConvexCommon.h:260
Definition GuShapeConvex.h:45
Definition GuPCMContactConvexCommon.h:340
Definition GuTriangleCache.h:172
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77