RavEngine
Loading...
Searching...
No Matches
ScScene.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef SC_SCENE_H
30#define SC_SCENE_H
31
32#include "PxPhysXConfig.h"
33#include "PxScene.h"
34#include "PxSceneDesc.h"
35#include "PxSimulationEventCallback.h"
36#include "foundation/PxPool.h"
37#include "foundation/PxHashSet.h"
38#include "foundation/PxHashMap.h"
39#include "CmTask.h"
40#include "CmFlushPool.h"
41#include "CmPreallocatingPool.h"
42#include "foundation/PxBitMap.h"
43#include "ScIterators.h"
44#include "PxsMaterialManager.h"
45#include "PxvManager.h"
46#include "ScBodyCore.h"
47#include "PxAggregate.h"
48#include "PxsContext.h"
49#include "PxsIslandSim.h"
50#include "GuPrunerTypedef.h"
51
52#define PX_MAX_DOMINANCE_GROUP 32
53
55
56namespace physx
57{
58 class NpShape;
59
60// PT: TODO: move INVALID_FILTER_PAIR_INDEX out of public API
62{
63 PX_FORCE_INLINE PxFilterInfo() : filterFlags(0), pairFlags(0), filterPairIndex(INVALID_FILTER_PAIR_INDEX) {}
64 PX_FORCE_INLINE PxFilterInfo(PxFilterFlags filterFlags_) : filterFlags(filterFlags_), pairFlags(0), filterPairIndex(INVALID_FILTER_PAIR_INDEX) {}
65
66 PxFilterFlags filterFlags;
67 PxPairFlags pairFlags;
68 PxU32 filterPairIndex;
69};
70
71struct PxTriggerPair;
72
73class PxsIslandManager;
77
79
80#if PX_SUPPORT_GPU_PHYSX
83#endif
84
85namespace IG
86{
87 class SimpleIslandManager;
88 class NodeIndex;
89 typedef PxU32 EdgeIndex;
90}
91
92class PxsCCDContext;
93
94namespace Cm
95{
96 class IDPool;
97}
98
99namespace Bp
100{
101 class AABBManagerBase;
102 class BroadPhase;
103 class BoundsArray;
104}
105
106namespace Dy
107{
108 class FeatherstoneArticulation;
109 class Context;
110#if PX_SUPPORT_GPU_PHYSX
111 class SoftBody;
112 class FEMCloth;
113 class ParticleSystem;
114 class HairSystem;
115#endif
116}
117
118namespace Sc
119{
120 class ActorSim;
121 class ElementSim;
122 class Interaction;
123
124 class ShapeCore;
125 class RigidCore;
126 class StaticCore;
127 class ConstraintCore;
128 class ArticulationCore;
129 class ArticulationJointCore;
130 class ArticulationSpatialTendonCore;
131 class ArticulationFixedTendonCore;
132 class ArticulationSensorCore;
133 class LLArticulationPool;
134 class LLArticulationRCPool;
135 class LLSoftBodyPool;
136 class LLFEMClothPool;
137 class LLParticleSystemPool;
138 class LLHairSystemPool;
139
140 class BodyCore;
141 class SoftBodyCore;
142 class FEMClothCore;
143 class ParticleSystemCore;
144 class HairSystemCore;
145
146 class NPhaseCore;
147 class ConstraintInteraction;
148
149 class BodySim;
150 class ShapeSim;
151 class RigidSim;
152 class StaticSim;
153 class ConstraintSim;
154 struct ConstraintGroupNode;
155 class ConstraintProjectionManager;
156 struct TriggerPairExtraData;
157 class ObjectIDTracker;
158 class ActorPairReport;
159 class ContactStreamManager;
160 class SqBoundsManager;
161 class ShapeInteraction;
162 class ElementInteractionMarker;
163 class ArticulationSim;
164 class SoftBodySim;
165 class FEMClothSim;
166 class ParticleSystemSim;
167 class HairSystemSim;
168
169 class SimStats;
170
171 struct SimStateData;
172
174 {
175 BodySim* bodySim;
176 StaticSim*staticSim;
177 ShapeSim* shapeSim;
178 ptrdiff_t staticActorOffset;
179 ptrdiff_t staticShapeTableOffset;
180 ptrdiff_t dynamicActorOffset;
181 ptrdiff_t dynamicShapeTableOffset;
182 ptrdiff_t shapeOffset;
183 };
184
186 {
187 PxInlineArray<ShapeSim*, 64> bufferedShapes;
189 };
190
192 {
193 enum Enum
194 {
195 eOVERLAP = 0, // corresponds to ShapeInteraction
196 eTRIGGER, // corresponds to TriggerInteraction
197 eMARKER, // corresponds to ElementInteractionMarker
198 eTRACKED_IN_SCENE_COUNT, // not a real type, interactions above this limit are tracked in the scene
199 eCONSTRAINTSHADER, // corresponds to ConstraintInteraction
200 eARTICULATION, // corresponds to ArticulationJointSim
201
202 eINVALID
203 };
204 };
205
207 {
208 enum Enum
209 {
210 eSCENE_SIP_STATES_DIRTY_DOMINANCE = (1<<1),
211 eSCENE_SIP_STATES_DIRTY_VISUALIZATION = (1<<2),
212 eSCENE_DEFAULT = 0
213 };
214 };
215
217 {
218 enum Enum
219 {
220 eCOMPLETE,
221 eCOLLIDE,
222 eFETCHCOLLIDE,
223 eADVANCE,
224 eFETCHRESULT
225 };
226 };
227
228 struct SqBoundsSync;
229 struct SqRefFinder;
230
232 {
233 IG::EdgeIndex mIndex;
234 PxU32 mCount;
235
237 };
238
239 class Scene : public PxUserAllocated
240 {
241 struct SimpleBodyPair
242 {
243 ActorSim* body1;
244 ActorSim* body2;
245 PxU32 body1ID;
246 PxU32 body2ID;
247 };
248
249 PX_NOCOPY(Scene)
250
251 //---------------------------------------------------------------------------------
252 // External interface
253 //---------------------------------------------------------------------------------
254 public:
255 void release();
256
257 PX_FORCE_INLINE void setGravity(const PxVec3& g) { mGravity = g; mBodyGravityDirty = true; }
258 PX_FORCE_INLINE PxVec3 getGravity() const { return mGravity; }
259 PX_FORCE_INLINE void setElapsedTime(const PxReal t) { mDt = t; mOneOverDt = t > 0.0f ? 1.0f/t : 0.0f; }
260
261 void setBounceThresholdVelocity(const PxReal t);
262 PxReal getBounceThresholdVelocity() const;
263
264 void setPublicFlags(PxSceneFlags flags);
265 PX_FORCE_INLINE PxSceneFlags getPublicFlags() const { return mPublicFlags; }
266 PX_FORCE_INLINE PxSceneFlags getFlags() const { return mPublicFlags; }
267
268 PxSolverType::Enum getSolverType() const;
269
270 void setFrictionType(PxFrictionType::Enum model);
271 PxFrictionType::Enum getFrictionType() const;
272 PX_FORCE_INLINE void setPCM(bool enabled) { mLLContext->setPCM(enabled); }
273 PX_FORCE_INLINE void setContactCache(bool enabled) { mLLContext->setContactCache(enabled); }
274
275 void addStatic(StaticCore&, NpShape*const *shapes, PxU32 nbShapes, size_t shapePtrOffset, PxBounds3* uninflatedBounds);
276 void removeStatic(StaticCore&, PxInlineArray<const ShapeCore*,64>& removedShapes, bool wakeOnLostTouch);
277
278 void addBody(BodyCore&, NpShape*const *shapes, PxU32 nbShapes, size_t shapePtrOffset, PxBounds3* uninflatedBounds, bool compound);
279 void removeBody(BodyCore&, PxInlineArray<const ShapeCore*,64>& removedShapes, bool wakeOnLostTouch);
280
281 // Batch insertion API.
282 // the bounds generated here are the uninflated bounds for the shapes, *if* they are trigger or sim shapes.
283 // It's up to the caller to ensure the bounds array is big enough.
284 // Some care is required in handling these since sim and SQ tweak the bounds in slightly different ways.
285
286 void startBatchInsertion(BatchInsertionState&);
287 void addStatic(PxActor* actor, BatchInsertionState&, PxBounds3* outBounds);
288 void addBody(PxActor* actor, BatchInsertionState&, PxBounds3* outBounds, bool compound);
289 void finishBatchInsertion(BatchInsertionState&);
290
291 // Batch remove helpers
292 PX_FORCE_INLINE void setBatchRemove(BatchRemoveState* bs) { mBatchRemoveState = bs; }
293 PX_FORCE_INLINE BatchRemoveState* getBatchRemove() const { return mBatchRemoveState; }
294
295 void addConstraint(ConstraintCore&, RigidCore*, RigidCore*);
296 void removeConstraint(ConstraintCore&);
297
298 void addSoftBody(SoftBodyCore&);
299 void removeSoftBody(SoftBodyCore&);
300
301 void addFEMCloth(FEMClothCore&);
302 void removeFEMCloth(FEMClothCore&);
303
304 void addParticleSystem(ParticleSystemCore&);
305 void removeParticleSystem(ParticleSystemCore&);
306
307 void addHairSystem(HairSystemCore&);
308 void removeHairSystem(HairSystemCore&);
309
310 void addArticulation(ArticulationCore&, BodyCore& root);
311 void removeArticulation(ArticulationCore&);
312
313 void addArticulationJoint(ArticulationJointCore&, BodyCore& parent, BodyCore& child);
314 void removeArticulationJoint(ArticulationJointCore&);
315
316 void addArticulationTendon(ArticulationSpatialTendonCore&);
317 void removeArticulationTendon(ArticulationSpatialTendonCore&);
318
319 void addArticulationTendon(ArticulationFixedTendonCore&);
320 void removeArticulationTendon(ArticulationFixedTendonCore&);
321
322 void addArticulationSensor(ArticulationSensorCore&);
323 void removeArticulationSensor(ArticulationSensorCore&);
324
325 void addArticulationSimControl(ArticulationCore& core);
326 void removeArticulationSimControl(ArticulationCore& core);
327 void addSoftBodySimControl(SoftBodyCore& core);
328 void removeSoftBodySimControl(SoftBodyCore& core);
329 void addFEMClothSimControl(FEMClothCore& core);
330 void removeFEMClothSimControl(FEMClothCore& core);
331 void addParticleSystemSimControl(ParticleSystemCore& core);
332 void removeParticleSystemSimControl(ParticleSystemCore& core);
333 void addHairSystemSimControl(HairSystemCore& core);
334 void removeHairSystemSimControl(HairSystemCore& core);
335
336 void updateBodySim(BodySim& sim);
337
338 PX_FORCE_INLINE PxU32 getNbArticulations() const { return mArticulations.size(); }
339 PX_FORCE_INLINE ArticulationCore* const* getArticulations() { return mArticulations.getEntries(); }
340
341#if PX_SUPPORT_GPU_PHYSX
342 PX_FORCE_INLINE PxU32 getNbSoftBodies() const { return mSoftBodies.size(); }
343 PX_FORCE_INLINE SoftBodyCore* const* getSoftBodies() { return mSoftBodies.getEntries(); }
344
345 PX_FORCE_INLINE PxU32 getNbFEMCloths() const { return mFEMCloths.size(); }
346 PX_FORCE_INLINE FEMClothCore* const* getFEMCloths() { return mFEMCloths.getEntries(); }
347
348 PX_FORCE_INLINE PxU32 getNbParticleSystems() const { return mParticleSystems.size(); }
349 PX_FORCE_INLINE ParticleSystemCore* const* getParticleSystems() { return mParticleSystems.getEntries(); }
350
351 PX_FORCE_INLINE PxU32 getNbHairSystems() const { return mHairSystems.size(); }
352 PX_FORCE_INLINE HairSystemCore* const* getHairSystems() { return mHairSystems.getEntries(); }
353#endif
354
355 PX_FORCE_INLINE PxU32 getNbConstraints() const { return mConstraints.size(); }
356 PX_FORCE_INLINE ConstraintCore*const* getConstraints() const { return mConstraints.getEntries(); }
357 PX_FORCE_INLINE ConstraintCore*const* getConstraints() { return mConstraints.getEntries(); }
358
359 void initContactsIterator(ContactIterator&, PxsContactManagerOutputIterator&);
360
361 // Simulation events
362 void setSimulationEventCallback(PxSimulationEventCallback* callback);
363 PxSimulationEventCallback* getSimulationEventCallback() const;
364
365 // Contact modification
366 PX_FORCE_INLINE void setContactModifyCallback(PxContactModifyCallback* callback) { mLLContext->setContactModifyCallback(callback); }
367 PX_FORCE_INLINE PxContactModifyCallback* getContactModifyCallback() const { return mLLContext->getContactModifyCallback(); }
368
369 void setCCDContactModifyCallback(PxCCDContactModifyCallback* callback);
370 PxCCDContactModifyCallback* getCCDContactModifyCallback() const;
371
372 void setCCDMaxPasses(PxU32 ccdMaxPasses);
373 PxU32 getCCDMaxPasses() const;
374
375 void setCCDThreshold(PxReal t);
376 PxReal getCCDThreshold() const;
377
378 // Broad-phase callback
379 PX_FORCE_INLINE void setBroadPhaseCallback(PxBroadPhaseCallback* callback) { mBroadPhaseCallback = callback; }
380 PX_FORCE_INLINE PxBroadPhaseCallback* getBroadPhaseCallback() const { return mBroadPhaseCallback; }
381
382 // Broad-phase management
383 void finishBroadPhase(PxBaseTask* continuation);
384 void finishBroadPhaseStage2(const PxU32 ccdPass);
385 void preallocateContactManagers(PxBaseTask* continuation);
386
387 void islandInsertion(PxBaseTask* continuation);
388 void registerContactManagers(PxBaseTask* continuation);
389 void registerInteractions(PxBaseTask* continuation);
390 void registerSceneInteractions(PxBaseTask* continuation);
391
392 void secondPassNarrowPhase(PxBaseTask* continuation);
393
394 // Groups
395 void setDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2, const PxDominanceGroupPair& dominance);
396 PxDominanceGroupPair getDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2) const;
397
398 void setSolverBatchSize(PxU32 solverBatchSize);
399 PxU32 getSolverBatchSize() const;
400
401 void setSolverArticBatchSize(PxU32 solverBatchSize);
402 PxU32 getSolverArticBatchSize() const;
403
404 void setDynamicsDirty();
405
406 PX_FORCE_INLINE void setVisualizationParameter(PxVisualizationParameter::Enum param, PxReal value)
407 {
408 mVisualizationParameterChanged = true;
409 mLLContext->setVisualizationParameter(param, value);
410 }
411
412 PX_FORCE_INLINE PxReal getVisualizationParameter(PxVisualizationParameter::Enum param) const { return mLLContext->getVisualizationParameter(param); }
413 PX_FORCE_INLINE void setVisualizationCullingBox(const PxBounds3& box) { mLLContext->setVisualizationCullingBox(box); }
414 PX_FORCE_INLINE const PxBounds3& getVisualizationCullingBox() const { return mLLContext->getVisualizationCullingBox(); }
415 PX_FORCE_INLINE PxReal getVisualizationScale() const { return mLLContext->getRenderScale(); }
416
417 // Run
418 void simulate(PxReal timeStep, PxBaseTask* continuation);
419 void advance(PxReal timeStep, PxBaseTask* continuation);
420 void collide(PxReal timeStep, PxBaseTask* continuation);
421 void endSimulation();
422 void flush(bool sendPendingReports);
423 void fireBrokenConstraintCallbacks();
424 void fireTriggerCallbacks();
425 void fireQueuedContactCallbacks();
426 void fireOnAdvanceCallback();
427
429 getQueuedContactPairHeaders();
430
431 bool fireOutOfBoundsCallbacks();
432 void prepareOutOfBoundsCallbacks();
433 void postCallbacksPreSync();
434 void postReportsCleanup();
435 void fireCallbacksPostSync();
436 void syncSceneQueryBounds(SqBoundsSync& sync, SqRefFinder& finder);
437
438 PxU32 getDefaultContactReportStreamBufferSize() const;
439
440 void setCCDMaxSeparation(PxReal separation);
441 PxReal getCCDMaxSeparation() const;
442 void setMaxBiasCoefficient(PxReal coeff);
443 PxReal getMaxBiasCoefficient() const;
444 void setFrictionOffsetThreshold(PxReal t);
445 PxReal getFrictionOffsetThreshold() const;
446 void setFrictionCorrelationDistance(PxReal t);
447 PxReal getFrictionCorrelationDistance() const;
448
449 PX_FORCE_INLINE void setLimits(const PxSceneLimits& limits) { mLimits = limits; }
450 PX_FORCE_INLINE const PxSceneLimits& getLimits() const { return mLimits; }
451
452 void visualizeStartStep();
453 PX_FORCE_INLINE PxRenderBuffer& getRenderBuffer() { return mLLContext->getRenderBuffer(); }
454
455 void setNbContactDataBlocks(PxU32 blockCount);
456 PxU32 getNbContactDataBlocksUsed() const;
457 PxU32 getMaxNbContactDataBlocksUsed() const;
458 PxU32 getMaxNbConstraintDataBlocksUsed() const;
459
460 void setMaxArticulationLinks(const PxU32 maxLinks) { mMaxNbArticulationLinks = maxLinks; }
461 PxU32 getMaxArticulationLinks() const { return mMaxNbArticulationLinks; }
462
463 void setScratchBlock(void* addr, PxU32 size);
464
465// PX_ENABLE_SIM_STATS
466 void getStats(PxSimulationStatistics& stats) const;
467 PX_FORCE_INLINE SimStats& getStatsInternal() { return *mStats; }
468// PX_ENABLE_SIM_STATS
469
470 void buildActiveActors();
471 void buildActiveAndFrozenActors();
472 PxActor** getActiveActors(PxU32& nbActorsOut);
473 void setActiveActors(PxActor** actors, PxU32 nbActors);
474
475 PxActor** getActiveSoftBodyActors(PxU32& nbActorsOut);
476 void setActiveSoftBodyActors(PxActor** actors, PxU32 nbActors);
477
478 //PxActor** getActiveFEMClothActors(PxU32& nbActorsOut);
479 //void setActiveFEMClothActors(PxActor** actors, PxU32 nbActors);
480
481 PxActor** getFrozenActors(PxU32& nbActorsOut);
482
483 void finalizeContactStreamAndCreateHeader(PxContactPairHeader& header,
484 const ActorPairReport& aPair,
485 ContactStreamManager& cs, PxU32 removedShapeTestMask);
486
487 PxTaskManager* getTaskManagerPtr() const { return mTaskManager; }
488 PxCudaContextManager* getCudaContextManager() const { return mCudaContextManager; }
489
490 void shiftOrigin(const PxVec3& shift);
491
492 PX_FORCE_INLINE PxPool<SimStateData>* getSimStateDataPool() { return mSimStateDataPool; }
493
494 PX_FORCE_INLINE bool isCollisionPhaseActive() const { return mIsCollisionPhaseActive; }
495 PX_FORCE_INLINE void setCollisionPhaseToActive() { PX_ASSERT(!mIsCollisionPhaseActive); mIsCollisionPhaseActive = true; }
496 PX_FORCE_INLINE void setCollisionPhaseToInactive() { PX_ASSERT(mIsCollisionPhaseActive); mIsCollisionPhaseActive = false; }
497
498 //---------------------------------------------------------------------------------
499 // Miscellaneous
500 //---------------------------------------------------------------------------------
501 //internal public methods:
502 public:
503 Scene(const PxSceneDesc& desc, PxU64 contextID);
504 ~Scene() {} //use release() plz.
505
506 void preAllocate(PxU32 nbStatics, PxU32 nbBodies, PxU32 nbStaticShapes, PxU32 nbDynamicShapes);
507
508 PX_FORCE_INLINE PxsContext* getLowLevelContext() { return mLLContext; }
509 PX_FORCE_INLINE const PxsContext* getLowLevelContext() const { return mLLContext; }
510
511 PX_FORCE_INLINE Dy::Context* getDynamicsContext() { return mDynamicsContext; }
512 PX_FORCE_INLINE const Dy::Context* getDynamicsContext() const { return mDynamicsContext; }
513
514 PX_FORCE_INLINE PxsSimulationController* getSimulationController() { return mSimulationController; }
515 PX_FORCE_INLINE const PxsSimulationController* getSimulationController() const { return mSimulationController; }
516
517 PX_FORCE_INLINE Bp::AABBManagerBase* getAABBManager() { return mAABBManager; }
518 PX_FORCE_INLINE const Bp::AABBManagerBase* getAABBManager() const { return mAABBManager; }
519 PX_FORCE_INLINE PxArray<BodySim*>& getCcdBodies() { return mCcdBodies; }
520
521 PX_FORCE_INLINE IG::SimpleIslandManager* getSimpleIslandManager() { return mSimpleIslandManager; }
522 PX_FORCE_INLINE const IG::SimpleIslandManager* getSimpleIslandManager() const { return mSimpleIslandManager; }
523
524 PX_FORCE_INLINE SimulationStage::Enum getSimulationStage() const { return mSimulationStage; }
525 PX_FORCE_INLINE void setSimulationStage(SimulationStage::Enum stage) { mSimulationStage = stage; }
526
527 void addShape_(RigidSim&, ShapeCore&);
528 void removeShape_(ShapeSim&, bool wakeOnLostTouch);
529
530 void registerShapeInNphase(RigidCore* rigidCore, const ShapeCore& shapeCore, const PxU32 transformCacheID);
531 void unregisterShapeFromNphase(const ShapeCore& shapeCore, const PxU32 transformCacheID);
532
533 void notifyNphaseOnUpdateShapeMaterial(const ShapeCore& shapeCore);
534
535 // Get an array of the active actors.
536 PX_FORCE_INLINE BodyCore*const* getActiveBodiesArray() const { return mActiveBodies.begin(); }
537 PX_FORCE_INLINE PxU32 getNumActiveBodies() const { return mActiveBodies.size(); }
538
539#if PX_SUPPORT_GPU_PHYSX
540 PX_FORCE_INLINE SoftBodyCore*const* getActiveSoftBodiesArray() const { return mActiveSoftBodies.begin(); }
541 PX_FORCE_INLINE PxU32 getNumActiveSoftBodies() const { return mActiveSoftBodies.size(); }
542
543 PX_FORCE_INLINE FEMClothCore*const* getActiveFEMClothsArray() const { return mActiveFEMCloths.begin(); }
544 PX_FORCE_INLINE PxU32 getNumActiveFEMCloths() const { return mActiveFEMCloths.size(); }
545
546 PX_FORCE_INLINE HairSystemCore*const* getActiveHairSystemsArray() const { return mActiveHairSystems.begin(); }
547 PX_FORCE_INLINE PxU32 getNumActiveHairSystems() const { return mActiveHairSystems.size(); }
548#endif
549
550 PX_FORCE_INLINE BodyCore*const* getActiveCompoundBodiesArray() const { return mActiveCompoundBodies.begin(); }
551 PX_FORCE_INLINE PxU32 getNumActiveCompoundBodies() const { return mActiveCompoundBodies.size(); }
552
553 PX_FORCE_INLINE PxU32 getNbInteractions(InteractionType::Enum type) const { return mInteractions[type].size(); }
554 PX_FORCE_INLINE PxU32 getNbActiveInteractions(InteractionType::Enum type) const { return mActiveInteractionCount[type]; }
555 // Get all interactions of a certain type
556 PX_FORCE_INLINE Interaction** getInteractions(InteractionType::Enum type) { return mInteractions[type].begin(); }
557 PX_FORCE_INLINE Interaction** getActiveInteractions(InteractionType::Enum type) { return mInteractions[type].begin(); }
558
559 void registerInteraction(Interaction* interaction, bool active);
560 void unregisterInteraction(Interaction* interaction);
561
562 void notifyInteractionActivated(Interaction* interaction);
563 void notifyInteractionDeactivated(Interaction* interaction);
564
565 // for pool management of interaction arrays, a major cause of dynamic allocation
566 void** allocatePointerBlock(PxU32 size);
567 void deallocatePointerBlock(void**, PxU32 size);
568 private:
569 // Get the number of active one-way dominator actors
570 PX_FORCE_INLINE PxU32 getActiveKinematicBodiesCount() const { return mActiveKinematicBodyCount; }
571
572 // Get an iterator to the active one-way dominator actors
573 PX_FORCE_INLINE BodyCore*const* getActiveKinematicBodies() const { return mActiveBodies.begin(); }
574
575 // Get the number of active non-kinematic actors
576 PX_FORCE_INLINE PxU32 getActiveDynamicBodiesCount() const { return mActiveBodies.size() - mActiveKinematicBodyCount; }
577
578 // Get the active non-kinematic actors
579 PX_FORCE_INLINE BodyCore*const* getActiveDynamicBodies() const { return mActiveBodies.begin() + mActiveKinematicBodyCount; }
580
581#if PX_SUPPORT_GPU_PHYSX
582 // Get the active soft body actors
583 PX_FORCE_INLINE SoftBodyCore*const* getActiveSoftBodies() const { return mActiveSoftBodies.begin(); }
584
585 // Get the active FEM-cloth actors
586 PX_FORCE_INLINE FEMClothCore*const* getActiveFEMCloths() const { return mActiveFEMCloths.begin(); }
587#endif
588
589 void swapInteractionArrayIndices(PxU32 id1, PxU32 id2, InteractionType::Enum type);
590 public:
591 PxReal getLengthScale() const;
592
593 PX_FORCE_INLINE PxBitMap& getDirtyShapeSimMap() { return mDirtyShapeSimMap; }
594
595 void addDirtyArticulationSim(ArticulationSim* artiSim);
596 void removeDirtyArticulationSim(ArticulationSim* artiSim);
597
598 void addToActiveList(ActorSim& actor);
599 void removeFromActiveList(ActorSim& actor);
600 void removeFromActiveCompoundBodyList(BodySim& actor);
601 void swapInActiveBodyList(BodySim& body); // call when an active body gets switched from dynamic to kinematic or vice versa
602
603 void addBrokenConstraint(ConstraintCore*);
604 void addActiveBreakableConstraint(ConstraintSim*, ConstraintInteraction*);
605 void removeActiveBreakableConstraint(ConstraintSim*);
606 //the Actor should register its top level shapes with these.
607 void removeBody(BodySim&);
608
609 void raiseSceneFlag(SceneInternalFlag::Enum flag) { mInternalFlags |= flag; }
610
611 //lists of actors woken up or put to sleep last simulate
612 void onBodyWakeUp(BodySim* body);
613 void onBodySleep(BodySim* body);
614
615 PX_FORCE_INLINE bool isValid() const { return (mLLContext != NULL); }
616
617 void addToLostTouchList(ActorSim& body1, ActorSim& body2);
618
619 PxU32 createAggregate(void* userData, PxU32 maxNumShapes, PxAggregateFilterHint filterHint);
620
621 void deleteAggregate(PxU32 id);
622
623 Dy::FeatherstoneArticulation* createLLArticulation(ArticulationSim* sim);
624 void destroyLLArticulation(Dy::FeatherstoneArticulation&);
625
626#if PX_SUPPORT_GPU_PHYSX
627 Dy::SoftBody* createLLSoftBody(SoftBodySim* sim);
628 void destroyLLSoftBody(Dy::SoftBody& softBody);
629
630 Dy::FEMCloth* createLLFEMCloth(FEMClothSim* sim);
631 void destroyLLFEMCloth(Dy::FEMCloth& femCloth);
632
633 Dy::ParticleSystem* createLLParticleSystem(ParticleSystemSim* sim);
634 void destroyLLParticleSystem(Dy::ParticleSystem& softBody);
635
636 Dy::HairSystem* createLLHairSystem(HairSystemSim* sim);
637 void destroyLLHairSystem(Dy::HairSystem& hairSystem);
638#endif
639
640 PX_FORCE_INLINE PxPool<ConstraintInteraction>* getConstraintInteractionPool() const { return mConstraintInteractionPool; }
641 public:
642 PX_FORCE_INLINE const PxsMaterialManager& getMaterialManager() const { return mMaterialManager; }
643 PX_FORCE_INLINE PxsMaterialManager& getMaterialManager() { return mMaterialManager; }
644#if PX_SUPPORT_GPU_PHYSX
645 PX_FORCE_INLINE const PxsFEMMaterialManager& getFEMMaterialManager() const { return mFEMMaterialManager; }
646 PX_FORCE_INLINE PxsFEMMaterialManager& getFEMMaterialManager() { return mFEMMaterialManager; }
647
648 PX_FORCE_INLINE const PxsFEMClothMaterialManager& getFEMClothMaterialManager() const { return mFEMClothMaterialManager; }
649 PX_FORCE_INLINE PxsFEMClothMaterialManager& getFEMClothMaterialManager() { return mFEMClothMaterialManager; }
650
651 PX_FORCE_INLINE const PxsPBDMaterialManager& getPBDMaterialManager() const { return mPBDMaterialManager; }
652 PX_FORCE_INLINE PxsPBDMaterialManager& getPBDMaterialManager() { return mPBDMaterialManager; }
653
654 PX_FORCE_INLINE const PxsFLIPMaterialManager& getFLIPMaterialManager() const { return mFLIPMaterialManager; }
655 PX_FORCE_INLINE PxsFLIPMaterialManager& getFLIPMaterialManager() { return mFLIPMaterialManager; }
656
657 PX_FORCE_INLINE const PxsMPMMaterialManager& getMPMMaterialManager() const { return mMPMMaterialManager; }
658 PX_FORCE_INLINE PxsMPMMaterialManager& getMPMMaterialManager() { return mMPMMaterialManager; }
659
660 PX_FORCE_INLINE const PxsCustomMaterialManager& getCustomMaterialManager() const { return mCustomMaterialManager; }
661 PX_FORCE_INLINE PxsCustomMaterialManager& getCustomMaterialManager() { return mCustomMaterialManager; }
662#endif
663 // Collision filtering
664 void setFilterShaderData(const void* data, PxU32 dataSize);
665 PX_FORCE_INLINE const void* getFilterShaderDataFast() const { return mFilterShaderData; }
666 PX_FORCE_INLINE PxU32 getFilterShaderDataSizeFast() const { return mFilterShaderDataSize; }
667 PX_FORCE_INLINE PxSimulationFilterShader getFilterShaderFast() const { return mFilterShader; }
668 PX_FORCE_INLINE PxSimulationFilterCallback* getFilterCallbackFast() const { return mFilterCallback; }
669 PX_FORCE_INLINE PxPairFilteringMode::Enum getKineKineFilteringMode() const { return mKineKineFilteringMode; }
670 PX_FORCE_INLINE PxPairFilteringMode::Enum getStaticKineFilteringMode() const { return mStaticKineFilteringMode; }
671
672 PX_FORCE_INLINE PxU32 getTimeStamp() const { return mTimeStamp; }
673 PX_FORCE_INLINE PxU32 getReportShapePairTimeStamp() const { return mReportShapePairTimeStamp; }
674
675 PX_FORCE_INLINE PxReal getOneOverDt() const { return mOneOverDt; }
676 PX_FORCE_INLINE PxReal getDt() const { return mDt; }
677
678 PX_FORCE_INLINE const PxVec3& getGravityFast() const { return mGravity; }
679 PX_FORCE_INLINE bool readFlag(SceneInternalFlag::Enum flag) const { return (mInternalFlags & flag) != 0; }
680 PX_FORCE_INLINE bool readPublicFlag(PxSceneFlag::Enum flag) const { return (mPublicFlags & flag); }
681
682 PX_FORCE_INLINE NPhaseCore* getNPhaseCore() const { return mNPhaseCore; }
683
684 void checkConstraintBreakage();
685
687 getTriggerBufferExtraData() { return *mTriggerBufferExtraData; }
688 PX_FORCE_INLINE PxArray<PxTriggerPair>& getTriggerBufferAPI() { return mTriggerBufferAPI; }
689 void reserveTriggerReportBufferSpace(const PxU32 pairCount, PxTriggerPair*& triggerPairBuffer, TriggerPairExtraData*& triggerPairExtraBuffer);
690
691 PX_FORCE_INLINE ObjectIDTracker& getActorIDTracker() { return *mActorIDTracker; }
692
693 PX_FORCE_INLINE void markReleasedBodyIDForLostTouch(PxU32 id) { mLostTouchPairsDeletedBodyIDs.growAndSet(id); }
694 void resizeReleasedBodyIDMaps(PxU32 maxActors, PxU32 numActors);
695
696 PX_FORCE_INLINE StaticSim& getStaticAnchor() { return *mStaticAnchor; }
697
698 PX_FORCE_INLINE ConstraintProjectionManager& getProjectionManager() { return *mProjectionManager; }
699
700 PX_FORCE_INLINE Bp::BoundsArray& getBoundsArray() const { return *mBoundsArray; }
701 PX_FORCE_INLINE void updateContactDistance(PxU32 idx, PxReal distance) { (*mContactDistance)[idx] = distance; mHasContactDistanceChanged = true; }
702 PX_FORCE_INLINE SqBoundsManager& getSqBoundsManager() const { return *mSqBoundsManager; }
703
704 PX_FORCE_INLINE BodyCore* const* getSleepBodiesArray(PxU32& count) { count = mSleepBodies.size(); return mSleepBodies.getEntries(); }
705
706 PX_FORCE_INLINE SoftBodyCore* const* getSleepSoftBodiesArray(PxU32& count) { count = mSleepSoftBodies.size(); return mSleepSoftBodies.getEntries(); }
707
708 PX_FORCE_INLINE PxTaskManager& getTaskManager() const { PX_ASSERT(mTaskManager); return *mTaskManager; }
709
710 Cm::FlushPool* getFlushPool();
711
712 PX_FORCE_INLINE bool getStabilizationEnabled() const { return mEnableStabilization; }
713
714 PX_FORCE_INLINE void setPostSolverVelocityNeeded() { mContactReportsNeedPostSolverVelocity = true; }
715
716 PX_FORCE_INLINE ObjectIDTracker& getConstraintIDTracker() { return *mConstraintIDTracker; }
717 PX_FORCE_INLINE ObjectIDTracker& getElementIDPool() { return *mElementIDPool; }
718 PX_FORCE_INLINE PxBitMap& getVelocityModifyMap() { return mVelocityModifyMap; }
719
720 void* allocateConstraintBlock(PxU32 size);
721 void deallocateConstraintBlock(void* addr, PxU32 size);
722
723 void stepSetupCollide(PxBaseTask* continuation);//This is very important to guarantee thread safty in the collide
724 PX_FORCE_INLINE void addToPosePreviewList(BodySim& b) { PX_ASSERT(!mPosePreviewBodies.contains(&b)); mPosePreviewBodies.insert(&b); }
725 PX_FORCE_INLINE void removeFromPosePreviewList(BodySim& b) { PX_ASSERT(mPosePreviewBodies.contains(&b)); mPosePreviewBodies.erase(&b); }
726#if PX_DEBUG
727 PX_FORCE_INLINE bool isInPosePreviewList(BodySim& b) const { return mPosePreviewBodies.contains(&b); }
728#endif
729
730 PX_FORCE_INLINE void setSpeculativeCCDRigidBody(const PxU32 index) { mSpeculativeCCDRigidBodyBitMap.growAndSet(index); }
731 PX_FORCE_INLINE void resetSpeculativeCCDRigidBody(const PxU32 index) { if(index < mSpeculativeCCDRigidBodyBitMap.size()) mSpeculativeCCDRigidBodyBitMap.reset(index); }
732
733 PX_FORCE_INLINE void setSpeculativeCCDArticulationLink(const PxU32 index) { mSpeculativeCDDArticulationBitMap.growAndSet(index); }
734 PX_FORCE_INLINE void resetSpeculativeCCDArticulationLink(const PxU32 index) { if(index < mSpeculativeCDDArticulationBitMap.size()) mSpeculativeCDDArticulationBitMap.reset(index); }
735
736 PX_FORCE_INLINE PxU64 getContextId() const { return mContextId; }
737 PX_FORCE_INLINE bool isUsingGpuDynamicsOrBp() const { return mUseGpuBp || mUseGpuDynamics; }
738 PX_FORCE_INLINE bool isUsingGpuDynamicsAndBp() const { return mUseGpuBp && mUseGpuDynamics; }
739 PX_FORCE_INLINE bool isUsingGpuDynamics() const { return mUseGpuDynamics; }
740 PX_FORCE_INLINE bool isUsingGpuBp() const { return mUseGpuBp; }
741
742 // statistics counters increase/decrease
743 PX_FORCE_INLINE void increaseNumKinematicsCounter() { mNbRigidKinematic++; }
744 PX_FORCE_INLINE void decreaseNumKinematicsCounter() { mNbRigidKinematic--; }
745 PX_FORCE_INLINE void increaseNumDynamicsCounter() { mNbRigidDynamics++; }
746 PX_FORCE_INLINE void decreaseNumDynamicsCounter() { mNbRigidDynamics--; }
747
748 void addParticleFilter(Sc::ParticleSystemCore* core, SoftBodySim& sim, PxU32 particleId, PxU32 userBufferId, PxU32 tetId);
749 void removeParticleFilter(Sc::ParticleSystemCore* core, SoftBodySim& sim, PxU32 particleId, PxU32 userBufferId, PxU32 tetId);
750
751 PxU32 addParticleAttachment(Sc::ParticleSystemCore* core, SoftBodySim& sim, PxU32 particleId, PxU32 userBufferId, PxU32 tetId, const PxVec4& barycentric);
752 void removeParticleAttachment(Sc::ParticleSystemCore* core, SoftBodySim& sim, PxU32 handle);
753
754 void addRigidFilter(BodyCore* core, SoftBodySim& sim, PxU32 vertId);
755 void removeRigidFilter(BodyCore* core, SoftBodySim& sim, PxU32 vertId);
756
757 PxU32 addRigidAttachment(BodyCore* core, SoftBodySim& sim, PxU32 vertId, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint);
758 void removeRigidAttachment(BodyCore* core, SoftBodySim& sim, PxU32 handle);
759
760 void addTetRigidFilter(BodyCore* core, SoftBodySim& sim, PxU32 tetIdx);
761 void removeTetRigidFilter(BodyCore* core, SoftBodySim& sim, PxU32 tetIdx);
762
763 PxU32 addTetRigidAttachment(BodyCore* core, SoftBodySim& sim, PxU32 tetIdx, const PxVec4& barycentric, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint);
764
765 void addSoftBodyFilter(SoftBodyCore& core, PxU32 tetIdx0, SoftBodySim& sim, PxU32 tetIdx1);
766 void removeSoftBodyFilter(SoftBodyCore& core, PxU32 tetIdx0, SoftBodySim& sim, PxU32 tetIdx1);
767 void addSoftBodyFilters(SoftBodyCore& core, SoftBodySim& sim, PxU32* tetIndices0, PxU32* tetIndices1, PxU32 tetIndicesSize);
768 void removeSoftBodyFilters(SoftBodyCore& core, SoftBodySim& sim, PxU32* tetIndices0, PxU32* tetIndices1, PxU32 tetIndicesSize);
769
770 PxU32 addSoftBodyAttachment(SoftBodyCore& core, PxU32 tetIdx0, const PxVec4& triBarycentric0, SoftBodySim& sim, PxU32 tetIdx1, const PxVec4& tetBarycentric1,
771 PxConeLimitedConstraint* constraint);
772 void removeSoftBodyAttachment(SoftBodyCore& core, SoftBodySim& sim, PxU32 handle);
773
774 void addClothFilter(Sc::FEMClothCore& core, PxU32 triIdx, Sc::SoftBodySim& sim, PxU32 tetIdx);
775 void removeClothFilter(Sc::FEMClothCore& core, PxU32 triIdx, Sc::SoftBodySim& sim, PxU32 tetIdx);
776
777 PxU32 addClothAttachment(FEMClothCore& core, PxU32 triIdx, const PxVec4& triBarycentric, SoftBodySim& sim, PxU32 tetIdx, const PxVec4& tetBarycentric,
778 PxConeLimitedConstraint* constraint);
779 void removeClothAttachment(FEMClothCore& core, SoftBodySim& sim, PxU32 handle);
780
781 void addRigidFilter(BodyCore* core, FEMClothSim& sim, PxU32 vertId);
782 void removeRigidFilter(BodyCore* core, FEMClothSim& sim, PxU32 vertId);
783
784 PxU32 addRigidAttachment(BodyCore* core, FEMClothSim& sim, PxU32 vertId, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint);
785 void removeRigidAttachment(BodyCore* core, FEMClothSim& sim, PxU32 handle);
786
787 void addClothFilter(FEMClothCore& core0, PxU32 triIdx0, Sc::FEMClothSim& sim1, PxU32 triIdx1);
788 void removeClothFilter(FEMClothCore& core, PxU32 triIdx0, FEMClothSim& sim1, PxU32 triIdx1);
789
790 PxU32 addTriClothAttachment(FEMClothCore& core0, PxU32 triIdx0, const PxVec4& barycentric0, Sc::FEMClothSim& sim1, PxU32 triIdx1, const PxVec4& barycentric1);
791 void removeTriClothAttachment(FEMClothCore& core, FEMClothSim& sim1, PxU32 handle);
792
793 void addTriRigidFilter(BodyCore* core, FEMClothSim& sim, PxU32 triIdx);
794 void removeTriRigidFilter(BodyCore* core, FEMClothSim& sim, PxU32 triIdx);
795
796 PxU32 addTriRigidAttachment(BodyCore* core, FEMClothSim& sim, PxU32 triIdx, const PxVec4& barycentric, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint);
797 void removeTriRigidAttachment(BodyCore* core, FEMClothSim& sim, PxU32 handle);
798
799 void addRigidAttachment(BodyCore* core, ParticleSystemSim& sim);
800 void removeRigidAttachment(BodyCore* core, ParticleSystemSim& sim);
801
802 void addRigidAttachment(const BodyCore* core, const HairSystemSim& sim);
803 void removeRigidAttachment(const BodyCore* core, const HairSystemSim& sim);
804
805 ConstraintCore* findConstraintCore(const ActorSim* sim0, const ActorSim* sim1);
806
807 //internal private methods:
808 private:
809 void activateEdgesInternal(const IG::EdgeIndex* activatingEdges, const PxU32 nbActivatingEdges);
810 void releaseConstraints(bool endOfScene);
811 PX_INLINE void clearBrokenConstraintBuffer();
812
814
815 void prepareCollide();
816
817 void collideStep(PxBaseTask* continuation);
818 void advanceStep(PxBaseTask* continuation);
819
820 // subroutines of collideStep/solveStep:
821 void kinematicsSetup(PxBaseTask* continuation);
822 void stepSetupSolve(PxBaseTask* continuation);
823 //void stepSetupSimulate();
824
825 void fetchPatchEvents(PxBaseTask*);
826 void processNarrowPhaseTouchEvents();
827 void processNarrowPhaseTouchEventsStage2(PxBaseTask*);
828 void setEdgesConnected(PxBaseTask*);
829 void processNarrowPhaseLostTouchEvents(PxBaseTask*);
830 void processNarrowPhaseLostTouchEventsIslands(PxBaseTask*);
831 void processLostTouchPairs();
832 void integrateKinematicPose();
833 void updateKinematicCached(PxBaseTask* task);
834
835 void beforeSolver(PxBaseTask* continuation);
836 void checkForceThresholdContactEvents(const PxU32 ccdPass);
837 void endStep();
838 private:
839 void putObjectsToSleep(PxU32 infoFlag);
840 void wakeObjectsUp(PxU32 infoFlag);
841
842 void collectPostSolverVelocitiesBeforeCCD();
843
844 void clearSleepWakeBodies(void);
845 PX_INLINE void cleanUpSleepBodies();
846 PX_INLINE void cleanUpWokenBodies();
847 PX_INLINE void cleanUpSleepOrWokenBodies(PxCoalescedHashSet<BodyCore*>& bodyList, PxU32 removeFlag, bool& validMarker);
848
849#if PX_SUPPORT_GPU_PHYSX
850 // PT: TODO: why inline these ones?
851 PX_INLINE void cleanUpSleepSoftBodies();
852 PX_INLINE void cleanUpWokenSoftBodies();
853 PX_INLINE void cleanUpSleepOrWokenSoftBodies(PxCoalescedHashSet<SoftBodyCore*>& bodyList, PxU32 removeFlag, bool& validMarker);
854
855 PX_INLINE void cleanUpSleepHairSystems();
856 PX_INLINE void cleanUpWokenHairSystems();
857 PX_INLINE void cleanUpSleepOrWokenHairSystems(PxCoalescedHashSet<HairSystemCore*>& bodyList, PxU32 removeFlag, bool& validMarker);
858#endif
859
860 //internal variables:
861 private:
862 // Material manager
863 PX_ALIGN(16, PxsMaterialManager mMaterialManager);
864#if PX_SUPPORT_GPU_PHYSX
865 PX_ALIGN(16, PxsFEMMaterialManager mFEMMaterialManager);
866
867 PX_ALIGN(16, PxsFEMClothMaterialManager mFEMClothMaterialManager);
868
869 PX_ALIGN(16, PxsPBDMaterialManager mPBDMaterialManager);
870
871 PX_ALIGN(16, PxsFLIPMaterialManager mFLIPMaterialManager);
872
873 PX_ALIGN(16, PxsMPMMaterialManager mMPMMaterialManager);
874
875 PX_ALIGN(16, PxsCustomMaterialManager mCustomMaterialManager);
876#endif
877 PxU64 mContextId;
878
879 PxArray<BodyCore*> mActiveBodies; // Sorted: kinematic before dynamic
880 PxU32 mActiveKinematicBodyCount; // Number of active kinematics. This is also the index in mActiveBodies where the active dynamic bodies start.
881 PxU32 mActiveDynamicBodyCount; // Number of active dynamics. This is also the index in mActiveBodies where the active soft bodies start.
882 PxArray<BodyCore*> mActiveCompoundBodies;
883
884 BodyCore** mActiveKinematicsCopy;
885 PxU32 mActiveKinematicsCopyCapacity;
886
887#if PX_SUPPORT_GPU_PHYSX
888 PxArray<SoftBodyCore*> mActiveSoftBodies;
889 PxArray<FEMClothCore*> mActiveFEMCloths;
890 PxArray<ParticleSystemCore*> mActiveParticleSystems;
891 PxArray<HairSystemCore*> mActiveHairSystems;
892#endif
893 PxArray<Interaction*> mInteractions[InteractionType::eTRACKED_IN_SCENE_COUNT];
894 PxU32 mActiveInteractionCount[InteractionType::eTRACKED_IN_SCENE_COUNT]; // Interactions with id < activeInteractionCount are active
895
896 template <typename T, PxU32 size>
897 struct Block
898 {
899 PxU8 mem[sizeof(T)*size];
900 Block() {} // get around VS warning C4345, otherwise useless
901 };
902
903 typedef Block<void*, 8> PointerBlock8;
904 typedef Block<void*, 16> PointerBlock16;
905 typedef Block<void*, 32> PointerBlock32;
906
907 PxPool<PointerBlock8> mPointerBlock8Pool;
908 PxPool<PointerBlock16> mPointerBlock16Pool;
909 PxPool<PointerBlock32> mPointerBlock32Pool;
910
911 PxsContext* mLLContext;
912
913 Bp::AABBManagerBase* mAABBManager;
914 PxsCCDContext* mCCDContext;
915 PxI32 mNumFastMovingShapes;
916 PxU32 mCCDPass;
917
918 //PxsIslandManager* mIslandManager;
919
920 IG::SimpleIslandManager* mSimpleIslandManager;
921
922 Dy::Context* mDynamicsContext;
923
924
925 PxsMemoryManager* mMemoryManager;
926
927#if PX_SUPPORT_GPU_PHYSX
928 PxsKernelWranglerManager* mGpuWranglerManagers;
929 PxsHeapMemoryAllocatorManager* mHeapMemoryAllocationManager;
930#endif
931
932 PxsSimulationController* mSimulationController;
933
934 PxsSimulationControllerCallback* mSimulationControllerCallback;
935
936 PxSceneLimits mLimits;
937
938 PxVec3 mGravity;
939 PxU32 mBodyGravityDirty; // Set to true before body->updateForces() when the mGravity has changed
940
942 mQueuedContactPairHeaders;
943 //time:
944 //constants set with setTiming():
945 PxReal mDt; //delta time for current step.
946 PxReal mOneOverDt; //inverse of dt.
947 //stepping / counters:
948 PxU32 mTimeStamp; //Counts number of steps.
949 PxU32 mReportShapePairTimeStamp; //Timestamp for refreshing the shape pair report structure. Updated before delayed shape/actor deletion and before CCD passes.
950 //containers:
951 // Those ones contain shape ptrs from Actor, i.e. compound level, not subparts
952
954
955 ConstraintProjectionManager* mProjectionManager;
956 Bp::BoundsArray* mBoundsArray;
957 PxFloatArrayPinned* mContactDistance;
958 bool mHasContactDistanceChanged;
959 SqBoundsManager* mSqBoundsManager;
960
961 PxArray<BodySim*> mCcdBodies;
962 PxArray<BodySim*> mProjectedBodies;
963 PxArray<PxTriggerPair> mTriggerBufferAPI;
964 PxArray<TriggerPairExtraData>* mTriggerBufferExtraData;
965
967 PxCoalescedHashSet<ArticulationSim*> mDirtyArticulationSims;
968
969#if PX_SUPPORT_GPU_PHYSX
974#endif
975 PxArray<ConstraintCore*> mBrokenConstraints;
976 PxCoalescedHashSet<ConstraintSim*> mActiveBreakableConstraints;
977
978 // pools for joint buffers
979 // Fixed joint is 92 bytes, D6 is 364 bytes right now. So these three pools cover all the internal cases
980 typedef Block<PxU8, 128> MemBlock128;
981 typedef Block<PxU8, 256> MemBlock256;
982 typedef Block<PxU8, 384> MemBlock384;
983
984 PxPool2<MemBlock128, 8192> mMemBlock128Pool;
985 PxPool2<MemBlock256, 8192> mMemBlock256Pool;
986 PxPool2<MemBlock384, 8192> mMemBlock384Pool;
987
988 // broad phase data:
989 NPhaseCore* mNPhaseCore;
990
991 // Collision filtering
992 void* mFilterShaderData;
993 PxU32 mFilterShaderDataSize;
994 PxU32 mFilterShaderDataCapacity;
995 PxSimulationFilterShader mFilterShader;
996 PxSimulationFilterCallback* mFilterCallback;
997
998 const PxPairFilteringMode::Enum mKineKineFilteringMode;
999 const PxPairFilteringMode::Enum mStaticKineFilteringMode;
1000
1001 PxCoalescedHashSet<BodyCore*> mSleepBodies;
1003
1004 PxCoalescedHashSet<SoftBodyCore*> mSleepSoftBodies;
1005 PxCoalescedHashSet<SoftBodyCore*> mWokeSoftBodies;
1006 PxCoalescedHashSet<HairSystemCore*> mSleepHairSystems;
1007 PxCoalescedHashSet<HairSystemCore*> mWokeHairSystems;
1008 bool mWokeBodyListValid;
1009 bool mSleepBodyListValid;
1010 bool mWokeSoftBodyListValid;
1011 bool mSleepSoftBodyListValid;
1012 bool mWokeHairSystemListValid;
1013 bool mSleepHairSystemListValid;
1014 const bool mEnableStabilization;
1015
1016 PxArray<PxActor*> mActiveActors;
1017 PxArray<PxActor*> mFrozenActors;
1018
1019#if PX_SUPPORT_GPU_PHYSX
1020 PxArray<PxActor*> mActiveSoftBodyActors;
1021 PxArray<PxActor*> mActiveFEMClothActors;
1022 PxArray<PxActor*> mActiveHairSystemActors;
1023#endif
1024 PxArray<const PxRigidBody*> mClientPosePreviewBodies; // buffer for bodies that requested early report of the integrated pose (eENABLE_POSE_INTEGRATION_PREVIEW).
1025 // This buffer gets exposed to users. Is officially accessible from PxSimulationEventCallback::onAdvance()
1026 // until the next simulate()/advance().
1027 PxArray<PxTransform> mClientPosePreviewBuffer; // buffer of newly integrated poses for the bodies that requested a preview. This buffer gets exposed
1028 // to users.
1029
1030 PxSimulationEventCallback* mSimulationEventCallback;
1031 PxBroadPhaseCallback* mBroadPhaseCallback;
1032
1033 SimStats* mStats;
1034 PxU32 mInternalFlags;
1035 PxSceneFlags mPublicFlags; //copy of PxSceneDesc::flags, of type PxSceneFlag
1036
1037 ObjectIDTracker* mConstraintIDTracker;
1038 ObjectIDTracker* mActorIDTracker;
1039 ObjectIDTracker* mElementIDPool;
1040
1041 StaticSim* mStaticAnchor;
1042
1043 Cm::PreallocatingPool<ShapeSim>* mShapeSimPool;
1044 Cm::PreallocatingPool<StaticSim>* mStaticSimPool;
1045 Cm::PreallocatingPool<BodySim>* mBodySimPool;
1046 PxPool<ConstraintSim>* mConstraintSimPool;
1047 LLArticulationRCPool* mLLArticulationRCPool;
1048#if PX_SUPPORT_GPU_PHYSX
1049 LLSoftBodyPool* mLLSoftBodyPool;
1050 LLFEMClothPool* mLLFEMClothPool;
1051 LLParticleSystemPool* mLLParticleSystemPool;
1052 LLHairSystemPool* mLLHairSystemPool;
1053#endif
1054 PxHashMap<PxPair<PxU32, PxU32>, ParticleOrSoftBodyRigidInteraction> mParticleOrSoftBodyRigidInteractionMap;
1055
1057
1058 PxPool<ConstraintInteraction>* mConstraintInteractionPool;
1059
1060 PxPool<SimStateData>* mSimStateDataPool;
1061
1062 BatchRemoveState* mBatchRemoveState;
1063
1064 PxArray<SimpleBodyPair> mLostTouchPairs;
1065 PxBitMap mLostTouchPairsDeletedBodyIDs; // Need to know which bodies have been deleted when processing the lost touch pair list.
1066 // Can't use the existing rigid object ID tracker class since this map needs to be cleared at
1067 // another point in time.
1068 PxBitMap mVelocityModifyMap;
1069
1070 PxArray<PxvContactManagerTouchEvent> mTouchFoundEvents;
1071 PxArray<PxvContactManagerTouchEvent> mTouchLostEvents;
1072
1073 PxArray<PxU32> mOutOfBoundsIDs;
1074
1075 PxBitMap mDirtyShapeSimMap;
1076
1077 PxU32 mDominanceBitMatrix[PX_MAX_DOMINANCE_GROUP];
1078
1079 bool mVisualizationParameterChanged;
1080
1081 PxU32 mMaxNbArticulationLinks;
1082
1083 // statics:
1084 PxU32 mNbRigidStatics;
1085 PxU32 mNbRigidDynamics;
1086 PxU32 mNbRigidKinematic;
1087 PxU32 mNbGeometries[PxGeometryType::eGEOMETRY_COUNT];
1088
1089 //IG::Node::eTYPE_COUNT
1090 PxU32 mNumDeactivatingNodes[IG::Node::eTYPE_COUNT];
1091
1092 // task decomposition
1093 void broadPhase(PxBaseTask* continuation);
1094 void broadPhaseFirstPass(PxBaseTask* continuation);
1095 void broadPhaseSecondPass(PxBaseTask* continuation);
1096 void updateBroadPhase(PxBaseTask* continuation);
1097 void preIntegrate(PxBaseTask* continuation);
1098 void postBroadPhase(PxBaseTask* continuation);
1099 void postBroadPhaseContinuation(PxBaseTask* continuation);
1100 void preRigidBodyNarrowPhase(PxBaseTask* continuation);
1101 void postBroadPhaseStage2(PxBaseTask* continuation);
1102 void postBroadPhaseStage3(PxBaseTask* continuation);
1103 void updateBoundsAndShapes(PxBaseTask* continuation);
1104 void rigidBodyNarrowPhase(PxBaseTask* continuation);
1105 void unblockNarrowPhase(PxBaseTask* continuation);
1106 void islandGen(PxBaseTask* continuation);
1107 void processLostSolverPatches(PxBaseTask* continuation);
1108 void processFoundSolverPatches(PxBaseTask* continuation);
1109 void postIslandGen(PxBaseTask* continuation);
1110 //void processTriggerInteractions(PxBaseTask* continuation);
1111 void solver(PxBaseTask* continuation);
1112 void updateBodies(PxBaseTask* continuation);
1113 void updateShapes(PxBaseTask* continuation);
1114 void updateSimulationController(PxBaseTask* continuation);
1115 void updateDynamics(PxBaseTask* continuation);
1116 void processLostContacts(PxBaseTask*);
1117 void processLostContacts2(PxBaseTask*);
1118 void processLostContacts3(PxBaseTask*);
1119 void destroyManagers(PxBaseTask*);
1120 void lostTouchReports(PxBaseTask*);
1121 void unregisterInteractions(PxBaseTask*);
1122 void postThirdPassIslandGen(PxBaseTask*);
1123 void postSolver(PxBaseTask* continuation);
1124 void constraintProjection(PxBaseTask* continuation);
1125 void afterIntegration(PxBaseTask* continuation); // performs sleep check, for instance
1126 void postCCDPass(PxBaseTask* continuation);
1127 void ccdBroadPhaseAABB(PxBaseTask* continuation);
1128 void ccdBroadPhase(PxBaseTask* continuation);
1129 void updateCCDMultiPass(PxBaseTask* continuation);
1130 void updateCCDSinglePass(PxBaseTask* continuation);
1131 void updateCCDSinglePassStage2(PxBaseTask* continuation);
1132 void updateCCDSinglePassStage3(PxBaseTask* continuation);
1133 void finalizationPhase(PxBaseTask* continuation);
1134
1135 void postNarrowPhase(PxBaseTask* continuation);
1136
1137 void addShapes(NpShape*const* shapes, PxU32 nbShapes, size_t ptrOffset, RigidSim& sim, PxBounds3* outBounds);
1138 void removeShapes(RigidSim& , PxInlineArray<ShapeSim*, 64>& , PxInlineArray<const ShapeCore*, 64>&, bool wakeOnLostTouch);
1139
1140 private:
1141 void addShapes(NpShape*const* shapes, PxU32 nbShapes, size_t ptrOffset, RigidSim& sim, ShapeSim*& prefetchedShapeSim, PxBounds3* outBounds);
1142 void updateContactDistances(PxBaseTask* continuation);
1143
1148
1149 //multi-pass ccd stuff
1156
1172 &Scene::processNarrowPhaseLostTouchEventsIslands> mProcessNarrowPhaseLostTouchTasks;
1174 &Scene::processNarrowPhaseLostTouchEvents> mProcessNPLostTouchEvents;
1202
1203 Cm::FlushPool mTaskPool;
1204 PxTaskManager* mTaskManager;
1205 PxCudaContextManager* mCudaContextManager;
1206
1207 bool mContactReportsNeedPostSolverVelocity;
1208 bool mUseGpuDynamics;
1209 bool mUseGpuBp;
1210 bool mCCDBp;
1211
1212 SimulationStage::Enum mSimulationStage;
1213
1214 ConstraintGroupNode** mTmpConstraintGroupRootBuffer; // temporary list of constraint group roots, used for constraint projection
1215
1216 PxCoalescedHashSet<const BodySim*> mPosePreviewBodies; // list of bodies that requested early report of the integrated pose (eENABLE_POSE_INTEGRATION_PREVIEW).
1217
1218 PxArray<PxsContactManager*> mPreallocatedContactManagers;
1219 PxArray<ShapeInteraction*> mPreallocatedShapeInteractions;
1220 PxArray<ElementInteractionMarker*> mPreallocatedInteractionMarkers;
1221
1222 OverlapFilterTask* mOverlapFilterTaskHead;
1223 PxArray<PxFilterInfo> mFilterInfo;
1224 PxBitMap mSpeculativeCCDRigidBodyBitMap;
1225 PxBitMap mSpeculativeCDDArticulationBitMap;
1226
1227 bool mIsCollisionPhaseActive;
1228 // Set to true as long as collision phase is active (used as an indicator that it is OK to read object pose,
1229 // velocity etc. compared to the solver phase where these properties might get written to).
1230
1231 public:
1232 // For OmniPVD. To notify NpScene that actor's sleeping state has changed.
1233 typedef void(*SleepingStateChangedCallback)(PxActor*, bool);
1234 SleepingStateChangedCallback mOnSleepingStateChanged;
1235 };
1236
1237 bool activateInteraction(Interaction* interaction, void* data);
1238 void activateInteractions(Sc::ActorSim& actorSim);
1239 void deactivateInteractions(Sc::ActorSim& actorSim);
1240
1241} // namespace Sc
1242
1243}
1244
1245#endif
Definition ScScene.cpp:7380
Definition SnippetSoftBody.h:36
A structure responsible for: storing an aabb representation for each active shape in the related scen...
Definition BpAABBManagerBase.h:165
Definition BpAABBManagerBase.h:101
Specialization of FanoutTask class in order to provide the delegation mechanism.
Definition CmTask.h:253
Definition CmTask.h:90
Definition CmFlushPool.h:49
Definition CmPreallocatingPool.h:261
Definition DyContext.h:76
Definition DyFEMCloth.h:50
Definition DyFeatherstoneArticulation.h:590
Definition DyHairSystem.h:81
Definition DyParticleSystem.h:66
Definition DySoftBody.h:52
Definition PxsSimpleIslandManager.h:87
Definition NpShape.h:44
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Definition PxArray.h:53
Base class of all task types.
Definition PxTask.h:45
Definition PxBitMap.h:52
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Broad-phase callback to receive broad-phase related events.
Definition PxScene.h:144
An interface class that the user can implement in order to modify CCD contact constraints.
Definition PxContactModifyCallback.h:500
Definition PxHashSet.h:100
An interface class that the user can implement in order to modify contact constraints.
Definition PxContactModifyCallback.h:459
Definition PxHashMap.h:78
Definition PxInlineArray.h:43
Definition PxPool.h:259
Definition PxPool.h:248
Interface for points, lines, triangles, and text buffer.
Definition PxRenderBuffer.h:136
Descriptor class for scenes. See #PxScene.
Definition PxSceneDesc.h:426
Class used to retrieve limits(e.g. maximum number of bodies) for a scene. The limits are used as a hi...
Definition PxSceneDesc.h:318
An interface class that the user can implement in order to receive simulation events.
Definition PxSimulationEventCallback.h:792
Filter callback to specify handling of collision pairs.
Definition PxFiltering.h:633
Class used to retrieve statistics for a simulation step.
Definition PxSimulationStatistics.h:50
The PxTaskManager interface.
Definition PxTaskManager.h:81
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition PxVec4.h:50
CCD context object.
Definition PxsCCD.h:423
Definition PxvNphaseImplementationContext.h:81
Definition PxsContext.h:92
Definition PxsMaterialManager.h:150
Definition PxsMaterialManager.h:134
Definition PxsMaterialManager.h:130
Definition PxsMaterialManager.h:142
Definition PxsHeapMemoryAllocator.h:83
Definition PxsKernelWrangler.h:41
Definition PxsMaterialManager.h:146
Definition PxsMaterialManager.h:126
Definition PxsMemoryManager.h:40
Definition PxsMaterialManager.h:138
Definition PxsSimulationController.h:114
Definition PxsSimulationController.h:124
Class shared by all shape interactions for a pair of actors if contact reports are requested.
Definition ScActorPair.h:110
Definition ScActorSim.h:83
Definition ScArticulationCore.h:52
Definition ScArticulationTendonCore.h:101
Definition ScArticulationJointCore.h:55
Definition ScArticulationSensor.h:44
Definition ScArticulationSim.h:68
Definition ScArticulationTendonCore.h:63
Definition ScBodyCore.h:49
Definition ScBodySim.h:60
Definition ScConstraintCore.h:43
Definition ScConstraintInteraction.h:42
Definition ScConstraintProjectionManager.h:47
Definition ScConstraintSim.h:48
Definition ScIterators.h:66
Contact report logic and data management.
Definition ScContactStream.h:125
Definition ScFEMClothCore.h:54
Definition ScFEMClothSim.h:42
Definition ScHairSystemCore.h:45
Definition ScHairSystemSim.h:42
Definition ScInteraction.h:50
Definition ScScene.cpp:118
Definition ScNPhaseCore.h:193
Definition ScObjectIDTracker.h:42
Definition ScParticleSystemCore.h:51
Definition ScParticleSystemSim.h:42
Definition ScRigidCore.h:61
Definition ScRigidSim.h:42
Definition ScScene.h:240
void flush(bool sendPendingReports)
Definition ScScene.cpp:1781
void visualizeStartStep()
Definition ScScene.cpp:5521
void release()
Definition ScScene.cpp:1112
Definition ScShapeCore.h:46
Definition ScShapeSim.h:55
Definition ScSimStats.h:49
Definition ScSoftBodyCore.h:53
Definition ScSoftBodySim.h:42
Definition ScSqBoundsManager.h:100
Definition ScStaticCore.h:43
Definition ScStaticSim.h:40
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_ALIGN(alignment, decl)
Definition PxPreprocessor.h:402
#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
PxFilterFlags(* PxSimulationFilterShader)(PxFilterObjectAttributes attributes0, PxFilterData filterData0, PxFilterObjectAttributes attributes1, PxFilterData filterData1, PxPairFlags &pairFlags, const void *constantBlock, PxU32 constantBlockSize)
Filter method to specify how a pair of potentially colliding objects should be processed.
Definition PxFiltering.h:604
PxU8 PxDominanceGroup
Group index which allows to specify 1- or 2-way interaction.
Definition PxActor.h:56
A constraint descriptor for limiting movement to a conical region.
Definition PxConeLimitedConstraint.h:48
An Instance of this class is passed to PxSimulationEventCallback.onContact().
Definition PxSimulationEventCallback.h:346
Expresses the dominance relationship of a contact. For the time being only three settings are permitt...
Definition PxScene.h:83
Definition ScScene.h:62
Enum
Definition PxSceneDesc.h:71
@ eGEOMETRY_COUNT
internal use only!
Definition PxGeometry.h:65
Enum
Definition PxFiltering.h:717
Enum
Definition PxSceneDesc.h:103
Enum
Definition PxSceneDesc.h:89
Descriptor for a trigger pair.
Definition PxSimulationEventCallback.h:745
Enum
Definition PxVisualizationParameter.h:63
Definition ScScene.h:174
Definition ScScene.h:186
Definition ScConstraintGroupNode.h:45
Definition ScScene.h:192
Definition ScScene.h:207
Definition ScScene.h:217
Definition ScSqBoundsSync.h:57
Definition ScSqBoundsSync.h:49
Definition ScTriggerPairs.h:62