29#ifndef SC_SHAPE_INTERACTION_H
30#define SC_SHAPE_INTERACTION_H
32#include "ScElementSimInteraction.h"
33#include "ScShapeSim.h"
34#include "ScActorPair.h"
37#include "PxsContactManager.h"
38#include "PxsContext.h"
39#include "PxsSimpleIslandManager.h"
41#define INVALID_REPORT_PAIR_ID 0xffffffff
45class PxsContactManagerOutputIterator;
48 class ContactReportAllocationManager;
61 NEXT_FREE = ((PAIR_FLAGS_MASK << 1) & ~PAIR_FLAGS_MASK),
63 HAS_TOUCH = (NEXT_FREE << 0),
64 HAS_NO_TOUCH = (NEXT_FREE << 1),
65 TOUCH_KNOWN = (HAS_TOUCH | HAS_NO_TOUCH),
67 CONTACTS_COLLECT_POINTS = (NEXT_FREE << 2),
68 CONTACTS_RESPONSE_DISABLED = (NEXT_FREE << 3),
75 FORCE_THRESHOLD_EXCEEDED_NOW = (NEXT_FREE << 4),
76 FORCE_THRESHOLD_EXCEEDED_BEFORE = (NEXT_FREE << 5),
77 FORCE_THRESHOLD_EXCEEDED_FLAGS = FORCE_THRESHOLD_EXCEEDED_NOW | FORCE_THRESHOLD_EXCEEDED_BEFORE,
79 IS_IN_PERSISTENT_EVENT_LIST = (NEXT_FREE << 6),
80 WAS_IN_PERSISTENT_EVENT_LIST = (NEXT_FREE << 7),
81 IN_PERSISTENT_EVENT_LIST = IS_IN_PERSISTENT_EVENT_LIST | WAS_IN_PERSISTENT_EVENT_LIST,
82 IS_IN_FORCE_THRESHOLD_EVENT_LIST= (NEXT_FREE << 8),
83 IS_IN_CONTACT_EVENT_LIST = IS_IN_PERSISTENT_EVENT_LIST | IS_IN_FORCE_THRESHOLD_EVENT_LIST,
85 LL_MANAGER_RECREATE_EVENT = CONTACT_REPORT_EVENTS | CONTACTS_COLLECT_POINTS |
92 void processUserNotification(PxU32 contactEvent, PxU16 infoFlags,
bool touchLost,
const PxU32 ccdPass,
const bool useCurrentTransform,
95 void processUserNotificationSync();
97 void processUserNotificationAsync(PxU32 contactEvent, PxU16 infoFlags,
bool touchLost,
const PxU32 ccdPass,
const bool useCurrentTransform,
101 float scale,
float param_contactForce,
float param_contactNormal,
float param_contactError,
float param_contactPoint
104 PxU32 getContactPointData(
const void*& contactPatches,
const void*& contactPoints, PxU32& contactDataSize, PxU32& contactPointCount, PxU32& patchCount,
const PxReal*& impulses, PxU32 startOffset,
PxsContactManagerOutputIterator& outputs);
115 void resetManagerCachedState()
const;
121 PX_INLINE PxIntBool isReportPair()
const {
return PxIntBool(getPairFlags() & CONTACT_REPORT_EVENTS); }
122 PX_INLINE PxIntBool hasTouch()
const {
return readFlag(HAS_TOUCH); }
123 PX_INLINE PxIntBool hasCCDTouch()
const { PX_ASSERT(mManager);
return mManager->getHadCCDContact(); }
124 PX_INLINE void swapAndClearForceThresholdExceeded();
127 PX_FORCE_INLINE PxIntBool readFlag(SiFlag flag)
const {
return PxIntBool(mFlags & flag); }
132 void onShapeChangeWhileSleeping(
bool shapeOfDynamicChanged);
136 bool onActivate_(
void* data);
137 bool onDeactivate_();
139 void updateState(
const PxU8 externalDirtyFlags);
143 void clearIslandGenData();
153 PxU32 mContactReportStamp;
154 PxU32 mReportPairIndex;
156 PxU16 mReportStreamIndex;
158 void createManager(
void* contactManager);
159 PX_INLINE bool updateManager(
void* contactManager);
162 PX_FORCE_INLINE PxU32 getManagerContactState()
const {
return mFlags & LL_MANAGER_RECREATE_EVENT; }
165 PX_INLINE void setFlag(SiFlag flag,
bool value)
172 PX_FORCE_INLINE void setHasTouch() { clearFlag(HAS_NO_TOUCH); raiseFlag(HAS_TOUCH); }
173 PX_FORCE_INLINE void setHasNoTouch() { clearFlag(HAS_TOUCH); raiseFlag(HAS_NO_TOUCH); }
193 PX_ASSERT(hasTouch());
194 PX_ASSERT(isReportPair());
196 const PxU32 pairFlags = getPairFlags();
198 const PxIntBool thresholdExceeded = readFlag(ShapeInteraction::FORCE_THRESHOLD_EXCEEDED_NOW);
200 if(!notifyTouchLost && !notifyThresholdLost)
204 if (mActorPair->getTouchCount() == 1)
210 const bool useCurrentTransform =
false;
212 const PxU32 triggeredFlags = notifyTouchLost | notifyThresholdLost;
213 PX_ASSERT(triggeredFlags);
214 processUserNotification(triggeredFlags, infoFlag,
true, ccdPass, useCurrentTransform, outputs);
216 if(shapeVolumeRemoved)
218 ActorPairReport& apr = getActorPairReport();
219 ContactStreamManager& cs = apr.getContactStreamManager();
228 PxU32 newFlags = mFlags;
229 PxU32 fl = PxU32(flags) & PAIR_FLAGS_MASK;
230 newFlags &= (~PAIR_FLAGS_MASK);
239 return (mFlags & PAIR_FLAGS_MASK);
242PX_INLINE void Sc::ShapeInteraction::swapAndClearForceThresholdExceeded()
244 PxU32 flags = mFlags;
248 PxU32 nowToBefore = (flags & FORCE_THRESHOLD_EXCEEDED_NOW) << 1;
249 flags &= ~(FORCE_THRESHOLD_EXCEEDED_NOW | FORCE_THRESHOLD_EXCEEDED_BEFORE);
250 flags |= nowToBefore;
259 PX_ASSERT(mReportPairIndex != INVALID_REPORT_PAIR_ID);
260 PX_ASSERT(readFlag(IS_IN_CONTACT_EVENT_LIST));
262 Scene& scene = getScene();
264 if (readFlag(IS_IN_FORCE_THRESHOLD_EVENT_LIST))
265 scene.getNPhaseCore()->removeFromForceThresholdContactEventPairs(
this);
268 PX_ASSERT(readFlag(IS_IN_PERSISTENT_EVENT_LIST));
269 scene.getNPhaseCore()->removeFromPersistentContactEventPairs(
this);
273PX_INLINE bool Sc::ShapeInteraction::updateManager(
void* contactManager)
275 if (activeManagerAllowed())
278 createManager(contactManager);
280 return (mManager != NULL);
286PX_INLINE void Sc::ShapeInteraction::destroyManager()
290 Scene& scene = getScene();
292 PxvNphaseImplementationContext* nphaseImplementationContext = scene.getLowLevelContext()->getNphaseImplementationContext();
293 PX_ASSERT(nphaseImplementationContext);
294 nphaseImplementationContext->unregisterContactManager(mManager);
298 scene.getLowLevelContext()->destroyContactManager(mManager);
304 ShapeSimBase& shape0 = getShape0();
305 ShapeSimBase& shape1 = getShape1();
307 ActorSim& bodySim0 = shape0.getActor();
308 ActorSim& bodySim1 = shape1.getActor();
311 PX_ASSERT(bodySim0.isDynamicRigid() || bodySim0.isSoftBody() || bodySim0.isFEMCloth() || bodySim0.isParticleSystem() || bodySim0.isHairSystem());
313 const IG::IslandSim& islandSim = getScene().getSimpleIslandManager()->getSpeculativeIslandSim();
317 return (islandSim.getNode(bodySim0.getNodeIndex()).isActive() ||
318 (!bodySim1.isStaticRigid() && islandSim.getNode(bodySim1.getNodeIndex()).isActive()));
321PX_FORCE_INLINE void Sc::ShapeInteraction::sendCCDRetouch(
const PxU32 ccdPass, PxsContactManagerOutputIterator& outputs)
323 const PxU32 pairFlags = getPairFlags();
330 PX_ASSERT(mActorPair->getTouchCount());
332 mActorPair->decTouchCount();
337 mActorPair->incTouchCount();
340PX_FORCE_INLINE PxIntBool Sc::ShapeInteraction::hasKnownTouchState()
const
347 return mManager->touchStatusKnown();
349 return readFlag(TOUCH_KNOWN);
Definition PxRenderOutput.h:50
Class shared by all shape interactions for a pair of actors if contact reports are requested.
Definition ScActorPair.h:110
Class shared by all shape interactions for a pair of actors.
Definition ScActorPair.h:69
Definition ScActorSim.h:83
Definition ScElementSimInteraction.h:40
Definition ScNPhaseCore.h:193
Definition ScShapeInteraction.h:54
void processUserNotificationAsync(PxU32 contactEvent, PxU16 infoFlags, bool touchLost, const PxU32 ccdPass, const bool useCurrentTransform, PxsContactManagerOutputIterator &outputs, ContactReportAllocationManager *alloc=NULL)
Definition ScShapeInteraction.cpp:316
Definition ScShapeSimBase.h:54
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxPairFlag::Enum, PxU16 > PxPairFlags
Bitfield that contains a set of raised flags defined in PxPairFlag.
Definition PxFiltering.h:277
@ eNEXT_FREE
For internal use only.
Definition PxFiltering.h:258
@ ePOST_SOLVER_VELOCITY
Provide post solver velocities in contact reports for this collision pair.
Definition PxFiltering.h:240
@ eCONTACT_EVENT_POSE
Provide rigid body poses in contact reports for this collision pair.
Definition PxFiltering.h:256
@ ePRE_SOLVER_VELOCITY
Provide pre solver velocities in contact reports for this collision pair.
Definition PxFiltering.h:230
@ eNOTIFY_TOUCH_CCD
Call contact report callback when this collision pair is in contact during CCD passes.
Definition PxFiltering.h:145
@ eNOTIFY_THRESHOLD_FORCE_LOST
Call contact report callback when the contact force between the actors of this collision pair falls b...
Definition PxFiltering.h:184
@ eNOTIFY_TOUCH_LOST
Call contact report callback or trigger callback when this collision pair stops to be in contact.
Definition PxFiltering.h:125
@ eMODIFY_CONTACTS
Call contact modification callback for this collision pair.
Definition PxFiltering.h:71
@ eNOTIFY_THRESHOLD_FORCE_FOUND
Call contact report callback when the contact force between the actors of this collision pair exceeds...
Definition PxFiltering.h:156
@ eNOTIFY_TOUCH_FOUND
Call contact report callback or trigger callback when this collision pair starts to be in contact.
Definition PxFiltering.h:87
@ eNOTIFY_TOUCH_PERSISTS
Call contact report callback while this collision pair is in contact.
Definition PxFiltering.h:107
@ eNOTIFY_THRESHOLD_FORCE_PERSISTS
Call contact report callback when the contact force between the actors of this collision pair continu...
Definition PxFiltering.h:170