29#ifndef NP_PARTICLE_SYSTEM_H
30#define NP_PARTICLE_SYSTEM_H
32#include "foundation/PxBounds3.h"
33#include "foundation/PxErrors.h"
34#include "foundation/PxSimpleTypes.h"
35#include "foundation/PxUserAllocated.h"
36#include "foundation/PxVec3.h"
38#include "common/PxBase.h"
39#include "common/PxRenderOutput.h"
42#include "PxFiltering.h"
43#include "PxParticleBuffer.h"
45#include "PxParticleSolverType.h"
46#include "PxParticleSystem.h"
47#include "PxPBDParticleSystem.h"
48#include "PxPBDMaterial.h"
49#include "PxSceneDesc.h"
50#include "PxSparseGridParams.h"
52#include "DyParticleSystem.h"
55#include "NpActorTemplate.h"
58#include "ScParticleSystemSim.h"
60#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
61#include "PxCustomParticleSystem.h"
62#include "PxFLIPParticleSystem.h"
63#include "PxFLIPMaterial.h"
64#include "PxMPMParticleSystem.h"
65#include "PxMPMMaterial.h"
72 class PxCudaContextManager;
73 class PxParticleMaterial;
75 class PxSerializationContext;
79 class ParticleSystemSim;
82 template<
class APIClass>
89 mCudaContextManager(&contextManager),
105 virtual PxBounds3 getWorldBounds(
float inflation = 1.01f)
const
107 NP_READ_CHECK(NpBase::getNpScene());
109 if (!NpBase::getNpScene())
129 virtual void setSolverIterationCounts(PxU32 minPositionIters, PxU32 minVelocityIters = 1)
131 NpScene* npScene = NpBase::getNpScene();
132 NP_WRITE_CHECK(npScene);
133 PX_CHECK_AND_RETURN(minPositionIters > 0,
"NpParticleSystem::setSolverIterationCounts: positionIters must be more than zero!");
134 PX_CHECK_AND_RETURN(minPositionIters <= 255,
"NpParticleSystem::setSolverIterationCounts: positionIters must be no greater than 255!");
135 PX_CHECK_AND_RETURN(minVelocityIters <= 255,
"NpParticleSystem::setSolverIterationCounts: velocityIters must be no greater than 255!");
137 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene,
"PxParticleSystem::setSolverIterationCounts() not allowed while simulation is running. Call will be ignored.")
139 mCore.setSolverIterationCounts((minVelocityIters & 0xff) << 8 | (minPositionIters & 0xff));
144 virtual void getSolverIterationCounts(PxU32& minPositionIters, PxU32& minVelocityIters)
const
146 NP_READ_CHECK(NpBase::getNpScene());
148 PxU16 x = mCore.getSolverIterationCounts();
149 minVelocityIters = PxU32(x >> 8);
150 minPositionIters = PxU32(x & 0xff);
153 virtual PxCudaContextManager* getCudaContextManager()
const {
return mCudaContextManager; }
155 virtual void setRestOffset(PxReal restOffset) { scSetRestOffset(restOffset); }
156 virtual PxReal getRestOffset()
const {
return mCore.getRestOffset(); }
158 virtual void setContactOffset(PxReal contactOffset) { scSetContactOffset(contactOffset); }
159 virtual PxReal getContactOffset()
const {
return mCore.getContactOffset(); }
161 virtual void setParticleContactOffset(PxReal particleContactOffset) { scSetParticleContactOffset(particleContactOffset); }
162 virtual PxReal getParticleContactOffset()
const {
return mCore.getParticleContactOffset(); }
164 virtual void setSolidRestOffset(PxReal solidRestOffset) { scSetSolidRestOffset(solidRestOffset); }
165 virtual PxReal getSolidRestOffset()
const {
return mCore.getSolidRestOffset(); }
167 virtual void setMaxDepenetrationVelocity(PxReal v) {scSetMaxDepenetrationVelocity(v); }
168 virtual PxReal getMaxDepenetrationVelocity(){
return mCore.getMaxDepenetrationVelocity(); }
170 virtual void setMaxVelocity(PxReal v) { scSetMaxVelocity(v); }
171 virtual PxReal getMaxVelocity() {
return mCore.getMaxVelocity(); }
173 virtual void setParticleSystemCallback(
PxParticleSystemCallback* callback) { mCore.setParticleSystemCallback(callback); }
176 virtual void enableCCD(
bool enable) { scSnableCCD(enable); }
182 return mCore.getShapeCore().getSimulationFilterData();
185 virtual void setSimulationFilterData(
const PxFilterData& data)
187 mCore.getShapeCore().setSimulationFilterData(data);
197 mCore.setFlags(flags);
202 mCore.setFlags(flags);
207 return mCore.getFlags();
215 virtual PxU32 getNbParticleMaterials()
const
218 return shapeCore.getNbMaterialIndices();
221 virtual void setPeriodicBoundary(
const PxVec3& boundary)
223 mCore.setPeriodicBoundary(boundary);
228 virtual PxVec3 getPeriodicBoundary()
const
230 return mCore.getPeriodicBoundary();
236 virtual PxU32 getGpuParticleSystemIndex()
238 NP_READ_CHECK(NpBase::getNpScene());
239 PX_CHECK_AND_RETURN_VAL(NpBase::getNpScene(),
"NpParticleSystem::getGpuParticleSystemIndex: particle system must be in a scene.", 0xffffffff);
241 if (NpBase::getNpScene()->getFlags() & PxSceneFlag::eSUPPRESS_READBACK)
242 return mCore.getSim()->getLowLevelParticleSystem()->getGpuRemapId();
252 NP_READ_CHECK(NpBase::getNpScene());
253 NpScene* scene = NpBase::getNpScene();
256 mCore.getSim()->getLowLevelParticleSystem()->mFlag |= Dy::ParticleSystemFlag::eUPDATE_PARAMS;
260 PX_INLINE void scSetSleepThreshold(
const PxReal v)
262 PX_ASSERT(!NpBase::isAPIWriteForbidden());
263 mCore.setSleepThreshold(v);
267 PX_INLINE void scSetRestOffset(
const PxReal v)
269 PX_ASSERT(!NpBase::isAPIWriteForbidden());
270 mCore.setRestOffset(v);
275 PX_INLINE void scSetContactOffset(
const PxReal v)
277 PX_ASSERT(!NpBase::isAPIWriteForbidden());
278 mCore.setContactOffset(v);
283 PX_INLINE void scSetParticleContactOffset(
const PxReal v)
285 PX_ASSERT(!NpBase::isAPIWriteForbidden());
286 mCore.setParticleContactOffset(v);
291 PX_INLINE void scSetSolidRestOffset(
const PxReal v)
293 PX_ASSERT(!NpBase::isAPIWriteForbidden());
294 mCore.setSolidRestOffset(v);
299 PX_INLINE void scSetFluidRestOffset(
const PxReal v)
301 PX_ASSERT(!NpBase::isAPIWriteForbidden());
302 mCore.setFluidRestOffset(v);
307 PX_INLINE void scSetGridSizeX(
const PxU32 v)
309 PX_ASSERT(!NpBase::isAPIWriteForbidden());
310 mCore.setGridSizeX(v);
314 PX_INLINE void scSetGridSizeY(
const PxU32 v)
316 PX_ASSERT(!NpBase::isAPIWriteForbidden());
317 mCore.setGridSizeY(v);
321 PX_INLINE void scSetGridSizeZ(
const PxU32 v)
323 PX_ASSERT(!NpBase::isAPIWriteForbidden());
324 mCore.setGridSizeZ(v);
328 PX_INLINE void scSnableCCD(
const bool enable)
330 PX_ASSERT(!NpBase::isAPIWriteForbidden());
331 mCore.enableCCD(enable);
338 PX_ASSERT(!NpBase::isAPIWriteForbidden());
344 PX_INLINE void scSetMaxDepenetrationVelocity(
const PxReal v)
346 PX_CHECK_AND_RETURN(v > 0.f,
"PxParticleSystem::setMaxDepenetrationVelocity: Max Depenetration Velocity must be > 0!");
347 PX_ASSERT(!NpBase::isAPIWriteForbidden());
348 mCore.setMaxDepenetrationVelocity(v);
353 PX_INLINE void scSetMaxVelocity(
const PxReal v)
355 PX_CHECK_AND_RETURN(v > 0.f,
"PxParticleSystem::setMaxVelocity: Max Velocity must be > 0!");
356 PX_ASSERT(!NpBase::isAPIWriteForbidden());
357 mCore.setMaxVelocity(v);
364 PX_ASSERT(!NpBase::isAPIWriteForbidden());
365 mCore.setSolverType(solverType);
369#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
372 PX_CHECK_AND_RETURN(params.
subgridSizeX > 1 && params.
subgridSizeX % 2 == 0,
"PxParticleSystem::setSparseGridParams: Sparse grid subgridSizeX must be > 1 and even number!");
373 PX_CHECK_AND_RETURN(params.
subgridSizeY > 1 && params.
subgridSizeY % 2 == 0,
"PxParticleSystem::setSparseGridParams: Sparse grid subgridSizeY must be > 1 and even number!");
374 PX_CHECK_AND_RETURN(params.
subgridSizeZ > 1 && params.
subgridSizeZ % 2 == 0,
"PxParticleSystem::setSparseGridParams: Sparse grid subgridSizeZ must be > 1 and even number!");
375 PX_ASSERT(!NpBase::isAPIWriteForbidden());
376 mCore.setSparseGridParams(params);
381#if PX_ENABLE_DEBUG_VISUALIZATION
384 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
387 void setName(
const char* debugName)
389 NP_WRITE_CHECK(NpBase::getNpScene());
390 NpActor::mName = debugName;
393 const char* getName()
const
395 NP_READ_CHECK(NpBase::getNpScene());
396 return NpActor::mName;
399 virtual void setGridSizeX(PxU32 gridSizeX) { scSetGridSizeX(gridSizeX); }
400 virtual void setGridSizeY(PxU32 gridSizeY) { scSetGridSizeY(gridSizeY); }
401 virtual void setGridSizeZ(PxU32 gridSizeZ) { scSetGridSizeZ(gridSizeZ); }
405 PxCudaContextManager* mCudaContextManager;
406 PxU32 mNextPhaseGroupID;
413 NpParticleClothPreProcessor(PxCudaContextManager* cudaContextManager) : mCudaContextManager(cudaContextManager), mNbPartitions(0){}
421 PxU32 computeSpringPartition(
const PxParticleSpring& springs,
const PxU32 partitionStartIndex, PxU32* partitionProgresses);
423 PxU32* partitions(
const PxParticleSpring* springs, PxU32* orderedSpringIndices);
425 PxU32 combinePartitions(
const PxParticleSpring* springs,
const PxU32* orderedSpringIndices,
const PxU32* accumulatedSpringsPerPartition,
426 PxU32* accumulatedSpringsPerCombinedPartitions, PxParticleSpring* orderedSprings, PxU32* accumulatedCopiesPerParticles, PxU32* remapOutput);
428 void classifySprings(
const PxParticleSpring* springs, PxU32* partitionProgresses, PxU32* tempSprings,
physx::PxArray<PxU32>& springsPerPartition);
430 void writeSprings(
const PxParticleSpring* springs, PxU32* partitionProgresses, PxU32* tempSprings, PxU32* orderedSprings,
431 PxU32* accumulatedSpringsPerPartition);
434 PxCudaContextManager* mCudaContextManager;
439 PxU32 mMaxSpringsPerPartition;
453 virtual void release();
456 virtual void setWind(
const PxVec3& wind) { scSetWind(wind); }
457 virtual PxVec3 getWind()
const {
return mCore.getWind(); }
459 virtual void setFluidBoundaryDensityScale(PxReal fluidBoundaryDensityScale) { scSetFluidBoundaryDensityScale(fluidBoundaryDensityScale); }
460 virtual PxReal getFluidBoundaryDensityScale()
const {
return mCore.getFluidBoundaryDensityScale(); }
462 virtual void setFluidRestOffset(PxReal fluidRestOffset) { scSetFluidRestOffset(fluidRestOffset); }
463 virtual PxReal getFluidRestOffset()
const {
return mCore.getFluidRestOffset(); }
466#if PX_ENABLE_DEBUG_VISUALIZATION
469 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
479 virtual void removeRigidAttachment(
PxRigidActor* actor);
485 PX_ASSERT(!NpBase::isAPIWriteForbidden());
486 mCore.setFluidBoundaryDensityScale(v);
492#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
497 NpFLIPParticleSystem(PxCudaContextManager& contextManager);
499 virtual ~NpFLIPParticleSystem() {}
501 virtual PxU32 createPhase(PxParticleMaterial* material, PxParticlePhaseFlags flags)
PX_OVERRIDE;
502 virtual void release();
504 virtual void setSparseGridParams(
const PxSparseGridParams& params) { scSetSparseGridParams(params); }
505 virtual PxSparseGridParams getSparseGridParams()
const {
return mCore.getSparseGridParams(); }
507 virtual void* getSparseGridDataPointer(PxSparseGridDataFlag::Enum flags);
509 virtual void getSparseGridCoord(PxI32& x, PxI32& y, PxI32& z, PxU32
id);
511 virtual void setFLIPParams(
const PxFLIPParams& params) { scSetFLIPParams(params); }
512 virtual PxFLIPParams getFLIPParams()
const {
return mCore.getFLIPParams(); }
514#if PX_ENABLE_DEBUG_VISUALIZATION
515 virtual void visualize(PxRenderOutput& out, NpScene& npScene)
const;
517 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
520 virtual void addParticleBuffer(PxParticleBuffer* particleBuffer);
521 virtual void removeParticleBuffer(PxParticleBuffer* particleBuffer);
523 virtual void addRigidAttachment(PxRigidActor* ) {}
524 virtual void removeRigidAttachment(PxRigidActor* ) {}
527 virtual PxActorType::Enum getType()
const {
return PxActorType::eFLIP_PARTICLESYSTEM; }
535 PX_CHECK_AND_RETURN(params.blendingFactor >= 0.f && params.blendingFactor <= 1.f,
"PxParticleSystem::setFLIPParams: FLIP blending factor must be >= 0 and <= 1!");
536 PX_ASSERT(!isAPIWriteForbidden());
537 mCore.setFLIPParams(params);
543 class NpMPMParticleSystem :
public NpParticleSystem<PxMPMParticleSystem>
547 NpMPMParticleSystem(PxCudaContextManager& contextManager);
549 virtual ~NpMPMParticleSystem() {}
551 virtual PxU32 createPhase(PxParticleMaterial* material, PxParticlePhaseFlags flags)
PX_OVERRIDE;
552 virtual void release();
554 virtual void setSparseGridParams(
const PxSparseGridParams& params) { scSetSparseGridParams(params); }
555 virtual PxSparseGridParams getSparseGridParams()
const {
return mCore.getSparseGridParams(); }
557 virtual void* getSparseGridDataPointer(PxSparseGridDataFlag::Enum flags);
559 virtual void getSparseGridCoord(PxI32& x, PxI32& y, PxI32& z, PxU32
id);
561 virtual void setMPMParams(
const PxMPMParams& params) { scSetMPMParams(params); }
562 virtual PxMPMParams getMPMParams()
const {
return mCore.getMPMParams(); }
564 virtual void* getMPMDataPointer(PxMPMParticleDataFlag::Enum flags);
565#if PX_ENABLE_DEBUG_VISUALIZATION
566 virtual void visualize(PxRenderOutput& out, NpScene& npScene)
const;
568 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
571 virtual void addParticleBuffer(PxParticleBuffer* particleBuffer);
572 virtual void removeParticleBuffer(PxParticleBuffer* particleBuffer);
574 virtual void addRigidAttachment(PxRigidActor* actor);
575 virtual void removeRigidAttachment(PxRigidActor* actor);
578 virtual PxActorType::Enum getType()
const {
return PxActorType::eMPM_PARTICLESYSTEM; }
581 PX_INLINE void scSetMPMParams(
const PxMPMParams& params)
583 mCore.setMPMParams(params);
588 class NpCustomParticleSystem :
public NpParticleSystem<PxCustomParticleSystem>
592 NpCustomParticleSystem(PxCudaContextManager& contextManager, PxU32 maxNeighborhood);
594 virtual ~NpCustomParticleSystem() {}
596 virtual void release();
600 virtual void setSparseGridParams(
const PxSparseGridParams& params) { scSetSparseGridParams(params); }
601 virtual PxSparseGridParams getSparseGridParams()
const {
return mCore.getSparseGridParams(); }
603 virtual void* getSparseGridDataPointer(PxSparseGridDataFlag::Enum flags);
605 virtual void getSparseGridCoord(PxI32& x, PxI32& y, PxI32& z, PxU32
id);
607 virtual PxU32 createPhase(PxParticleMaterial* material, PxParticlePhaseFlags flags)
PX_OVERRIDE;
609#if PX_ENABLE_DEBUG_VISUALIZATION
610 virtual void visualize(PxRenderOutput& out, NpScene& npScene)
const;
612 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
615 virtual void addParticleBuffer(PxParticleBuffer* particleBuffer);
616 virtual void removeParticleBuffer(PxParticleBuffer* particleBuffer);
618 virtual void addRigidAttachment(PxRigidActor* ) {}
619 virtual void removeRigidAttachment(PxRigidActor* ) {}
622 virtual PxActorType::Enum getType()
const {
return PxActorType::eCUSTOM_PARTICLESYSTEM; }
624 virtual void setCustomParticleCallback(PxCustomParticleSystemSolverCallback* callback);
625 virtual PxCustomParticleSystemSolverCallback* getCustomParticleCallback()
const;
Definition NpActorTemplate.h:54
Definition NpParticleSystem.h:444
Definition NpParticleSystem.h:411
virtual void release()
Release this object and deallocate all the memory.
virtual void partitionSprings(const PxParticleClothDesc &clothDesc, PxPartitionedParticleCloth &output) PX_OVERRIDE
Partition the spring constraints for particle cloth simulation.
Definition NpParticleSystem.h:84
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isValid() const
Definition PxBounds3.h:482
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 empty()
Return empty bounds.
Definition PxBounds3.h:284
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getCenter() const
returns the center of this axis aligned box.
Definition PxBounds3.h:396
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3 ¢er, const PxVec3 &extent)
returns the AABB from center and extents vectors.
Definition PxBounds3.h:299
PX_CUDA_CALLABLE PX_FORCE_INLINE float getExtents(uint32_t axis) const
get component of the box's extents along a given axis
Definition PxBounds3.h:408
The shared base class for all particle buffers, can be instantiated directly to simulate granular and...
Definition PxParticleBuffer.h:81
Preprocessor to prepare particle cloths for simulation.
Definition PxParticleBuffer.h:569
Material class to represent a set of particle material properties.
Definition PxParticleMaterial.h:50
Particle system callback base class to schedule work that should be done before, while or after the p...
Definition PxParticleSystem.h:77
Definition PxRenderOutput.h:50
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
Binary serialization context class.
Definition PxSerialFramework.h:99
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition ScParticleSystemCore.h:51
Definition ScParticleSystemShapeCore.h:48
Definition ScParticleSystemSim.h:42
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
PX_C_EXPORT PX_FOUNDATION_API physx::PxFoundation &PX_CALL_CONV PxGetFoundation()
Retrieves the Foundation SDK after it has been created.
Definition FdFoundation.cpp:279
#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
Enum
Definition PxActor.h:121
@ ePBD_PARTICLESYSTEM
A PBD ParticleSystem.
Definition PxActor.h:157
@ eINVALID_OPERATION
method was called at a time when an operation is not possible
Definition PxErrors.h:65
PxFilterData is user-definable data which gets passed into the collision filtering shader and/or call...
Definition PxFiltering.h:365
Structure to describe the set of particle cloths in the same #PxParticleClothBuffer....
Definition PxParticleBuffer.h:372
Enum
Definition PxParticleSystem.h:120
Enum
Definition PxParticleSolverType.h:53
Structure to describe the output of the particle cloth preprocessing. Used as an input to specify clo...
Definition PxParticleBuffer.h:395
Parameters to define the sparse grid settings like grid spacing, maximal number of subgrids etc.
Definition PxSparseGridParams.h:46
PxU16 subgridSizeZ
Subgrid resolution in z dimension (must be an even number)
Definition PxSparseGridParams.h:109
PxU16 subgridSizeY
Subgrid resolution in y dimension (must be an even number)
Definition PxSparseGridParams.h:108
PxU16 subgridSizeX
Subgrid resolution in x dimension (must be an even number)
Definition PxSparseGridParams.h:107