RavEngine
Loading...
Searching...
No Matches
PxParticleBuffer.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 PX_PARTICLE_BUFFER_H
30#define PX_PARTICLE_BUFFER_H
34#include "common/PxBase.h"
35#include "common/PxPhysXCommonConfig.h"
36#include "common/PxTypeInfo.h"
37
38#include "PxParticleSystemFlag.h"
39
40#include "foundation/PxBounds3.h"
41#include "foundation/PxSimpleTypes.h"
42#include "foundation/PxVec4.h"
43
44#if !PX_DOXYGEN
45namespace physx
46{
47#endif
48
49#if PX_VC
50#pragma warning(push)
51#pragma warning(disable : 4435)
52#endif
53
54class PxCudaContextManager;
55struct PxParticleRigidFilterPair;
56struct PxParticleRigidAttachment;
57
62PX_ALIGN_PREFIX(16)
64{
68} PX_ALIGN_SUFFIX(16);
69
70
81{
82public:
83
88 virtual PxVec4* getPositionInvMasses() const = 0;
89
94 virtual PxVec4* getVelocities() const = 0;
95
103 virtual PxU32* getPhases() const = 0;
104
113
121 virtual void setNbActiveParticles(PxU32 nbActiveParticles) = 0;
122
127 virtual PxU32 getNbActiveParticles() const = 0;
128
136 virtual PxU32 getMaxParticles() const = 0;
137
142 virtual PxU32 getNbParticleVolumes() const = 0;
143
148 virtual void setNbParticleVolumes(PxU32 nbParticleVolumes) = 0;
149
157 virtual PxU32 getMaxParticleVolumes() const = 0;
158
167 virtual void setRigidFilters(PxParticleRigidFilterPair* filters, PxU32 nbFilters) = 0;
168
177 virtual void setRigidAttachments(PxParticleRigidAttachment* attachments, PxU32 nbAttachments) = 0;
178
188 virtual PxU32 getFlatListStartIndex() const = 0;
189
197 virtual void raiseFlags(PxParticleBufferFlag::Enum flags) = 0;
198
202 virtual void release() = 0;
203
207 virtual void onParticleSystemDestroy() = 0;
208
212 virtual void setInternalData(void* data) = 0;
213
218
222 const PxU32 bufferUniqueId;
223
224protected:
225
226 virtual ~PxParticleBuffer() { }
227 PX_INLINE PxParticleBuffer(PxU32 uniqueId) : PxBase(PxConcreteType::ePARTICLE_BUFFER, PxBaseFlag::eOWNS_MEMORY | PxBaseFlag::eIS_RELEASABLE), bufferIndex(0xffffffff), bufferUniqueId(uniqueId){}
228 PX_INLINE PxParticleBuffer(PxU32 uniqueId, PxType type) : PxBase(type, PxBaseFlag::eOWNS_MEMORY | PxBaseFlag::eIS_RELEASABLE), bufferIndex(0xffffffff), bufferUniqueId(uniqueId){}
229
230private:
231 PX_NOCOPY(PxParticleBuffer)
232};
233
238{
239public:
244 {
245 threshold = 100.0f;
246 lifetime = 5.0f;
247 airDrag = 0.0f;
248 bubbleDrag = 0.5f;
249 buoyancy = 0.8f;
250 kineticEnergyWeight = 0.01f;
251 pressureWeight = 1.0f;
252 divergenceWeight = 5.0f;
253 collisionDecay = 0.5f;
254 useAccurateVelocity = false;
255 }
256
261 {
262 *this = PxDiffuseParticleParams();
263 }
264
265 PxReal threshold;
266 PxReal lifetime;
267 PxReal airDrag;
268 PxReal bubbleDrag;
269 PxReal buoyancy;
275};
276
283{
284public:
285
290 virtual PxVec4* getDiffusePositionLifeTime() const = 0;
291
296 virtual PxU32 getNbActiveDiffuseParticles() const = 0;
297
304 virtual void setMaxActiveDiffuseParticles(PxU32 maxActiveDiffuseParticles) = 0;
305
310 virtual PxU32 getMaxDiffuseParticles() const = 0;
311
318 virtual void setDiffuseParticleParams(const PxDiffuseParticleParams& params) = 0;
319
325
326protected:
327
328 virtual ~PxParticleAndDiffuseBuffer() {}
329 PX_INLINE PxParticleAndDiffuseBuffer(PxU32 uniqueId) : PxParticleBuffer(uniqueId, PxConcreteType::ePARTICLE_DIFFUSE_BUFFER){}
330
331private:
332 PX_NOCOPY(PxParticleAndDiffuseBuffer)
333};
334
338struct PX_ALIGN_PREFIX(8) PxParticleSpring
339{
340 PxU32 ind0;
341 PxU32 ind1;
342 PxReal length;
343 PxReal stiffness;
344 PxReal damping;
345 PxReal pad;
346} PX_ALIGN_SUFFIX(8);
347
352{
356 PxReal restVolume;
357 PxReal pressure;
360
361 bool operator <= (const PxParticleCloth& other) const { return startVertexIndex <= other.startVertexIndex; }
362 bool operator >= (const PxParticleCloth& other) const { return startVertexIndex >= other.startVertexIndex; }
363 bool operator < (const PxParticleCloth& other) const { return startVertexIndex < other.startVertexIndex; }
364 bool operator > (const PxParticleCloth& other) const { return startVertexIndex > other.startVertexIndex; }
365 bool operator == (const PxParticleCloth& other) const { return startVertexIndex == other.startVertexIndex; }
366};
367
372{
373 PxParticleClothDesc() : cloths(NULL), triangles(NULL), springs(NULL), restPositions(NULL),
375 {
376 }
377
379 PxU32* triangles;
380 PxParticleSpring* springs;
382 PxU32 nbCloths;
383 PxU32 nbSprings;
386};
387
394struct PX_PHYSX_CORE_API PxPartitionedParticleCloth
395{
398 PxU32* remapOutput;
399 PxParticleSpring* orderedSprings;
402
405 PxU32 nbSprings;
406 PxU32 nbCloths;
408
409 PxCudaContextManager* mCudaManager;
410
413
420 void allocateBuffers(PxU32 nbParticles, PxCudaContextManager* cudaManager);
421};
422
429{
430public:
431
436 virtual PxVec4* getRestPositions() = 0;
437
442 virtual PxU32* getTriangles() const = 0;
443
448 virtual void setNbTriangles(PxU32 nbTriangles) = 0;
449
454 virtual PxU32 getNbTriangles() const = 0;
455
460 virtual PxU32 getNbSprings() const = 0;
461
466 virtual PxParticleSpring* getSprings() = 0;
467
474 virtual void setCloths(PxPartitionedParticleCloth& cloths) = 0;
475
476protected:
477
478 virtual ~PxParticleClothBuffer() {}
479 PX_INLINE PxParticleClothBuffer(PxU32 uniqueId) : PxParticleBuffer(uniqueId, PxConcreteType::ePARTICLE_CLOTH_BUFFER) {}
480
481private:
482 PX_NOCOPY(PxParticleClothBuffer)
483};
484
491{
492public:
497 virtual PxU32* getRigidOffsets() const = 0;
498
506 virtual PxReal* getRigidCoefficients() const = 0;
507
512 virtual PxVec4* getRigidLocalPositions() const = 0;
513
518 virtual PxVec4* getRigidTranslations() const = 0;
519
527 virtual PxVec4* getRigidRotations() const = 0;
528
536 virtual PxVec4* getRigidLocalNormals() const = 0;
537
542 virtual void setNbRigids(PxU32 nbRigids) = 0;
543
548 virtual PxU32 getNbRigids() const = 0;
549
550protected:
551
552 virtual ~PxParticleRigidBuffer() {}
553 PX_INLINE PxParticleRigidBuffer(PxU32 uniqueId) : PxParticleBuffer(uniqueId, PxConcreteType::ePARTICLE_RIGID_BUFFER) {}
554
555private:
556 PX_NOCOPY(PxParticleRigidBuffer)
557};
558
569{
570public:
571
575 virtual void release() = 0;
576
582 virtual void partitionSprings(const PxParticleClothDesc& clothDesc, PxPartitionedParticleCloth& output) = 0;
583
584protected:
586};
587
588
589#if PX_VC
590#pragma warning(pop)
591#endif
592
593
594#if !PX_DOXYGEN
595} // namespace physx
596#endif
597
604PX_C_EXPORT PX_PHYSX_CORE_API physx::PxParticleClothPreProcessor* PX_CALL_CONV PxCreateParticleClothPreProcessor(physx::PxCudaContextManager* cudaContextManager);
605
606
608#endif
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Parameters to configure the behavior of diffuse particles.
Definition PxParticleBuffer.h:238
PX_INLINE PxDiffuseParticleParams()
Construct parameters with default values.
Definition PxParticleBuffer.h:243
PxReal lifetime
Diffuse particle will be removed after the specified lifetime.
Definition PxParticleBuffer.h:266
PX_INLINE void setToDefault()
(re)sets the structure to the default.
Definition PxParticleBuffer.h:260
PxReal collisionDecay
Decay factor of diffuse particles' lifetime after they collide with shapes.
Definition PxParticleBuffer.h:273
PxReal airDrag
Air drag force factor for spray particles.
Definition PxParticleBuffer.h:267
PxReal divergenceWeight
Contribution from divergence when deciding diffuse particle creation.
Definition PxParticleBuffer.h:272
PxReal threshold
Particles with potential value greater than the threshold will spawn diffuse particles.
Definition PxParticleBuffer.h:265
PxReal buoyancy
Buoyancy force factor for bubble particles.
Definition PxParticleBuffer.h:269
PxReal pressureWeight
Contribution from pressure when deciding diffuse particle creation.
Definition PxParticleBuffer.h:271
PxReal bubbleDrag
Fluid drag force factor for bubble particles.
Definition PxParticleBuffer.h:268
bool useAccurateVelocity
If true, enables accurate velocity estimation when using PBD solver.
Definition PxParticleBuffer.h:274
PxReal kineticEnergyWeight
Contribution from kinetic energy when deciding diffuse particle creation.
Definition PxParticleBuffer.h:270
A particle buffer used to simulate diffuse particles.
Definition PxParticleBuffer.h:283
virtual PxDiffuseParticleParams getDiffuseParticleParams() const =0
Get the parameters currently used for diffuse particle simulation.
virtual void setMaxActiveDiffuseParticles(PxU32 maxActiveDiffuseParticles)=0
Set the maximum possible number of diffuse particles for this buffer.
virtual PxU32 getNbActiveDiffuseParticles() const =0
Get number of currently active diffuse particles.
virtual PxU32 getMaxDiffuseParticles() const =0
Get maximum possible number of diffuse particles.
virtual void setDiffuseParticleParams(const PxDiffuseParticleParams &params)=0
Set the parameters for diffuse particle simulation.
virtual PxVec4 * getDiffusePositionLifeTime() const =0
Get a device buffer of positions and remaining lifetimes for the diffuse particles.
The shared base class for all particle buffers, can be instantiated directly to simulate granular and...
Definition PxParticleBuffer.h:81
virtual PxParticleVolume * getParticleVolumes() const =0
Get particle volumes for this particle buffer.
virtual void setRigidFilters(PxParticleRigidFilterPair *filters, PxU32 nbFilters)=0
Set the #PxParticleRigidFilterPair s for collision filtering of particles in this buffer with rigid b...
virtual void raiseFlags(PxParticleBufferFlag::Enum flags)=0
Raise dirty flags on this particle buffer to communicate that the corresponding data has been updated...
virtual PxVec4 * getVelocities() const =0
Get velocities for this particle buffer.
virtual void release()=0
Release this buffer and deallocate all the memory.
virtual PxU32 getMaxParticles() const =0
Get the maximum number particles this particle buffer can hold.
const PxU32 bufferUniqueId
Unique index that does not change over the lifetime of a PxParticleBuffer.
Definition PxParticleBuffer.h:222
virtual void setNbActiveParticles(PxU32 nbActiveParticles)=0
Set the number of active particles for this particle buffer.
virtual void setNbParticleVolumes(PxU32 nbParticleVolumes)=0
Set the number of #PxParticleVolume s for this particle buffer.
virtual PxVec4 * getPositionInvMasses() const =0
Get positions and inverse masses for this particle buffer.
virtual PxU32 getNbParticleVolumes() const =0
Get the number of particle volumes in this particle buffer.
virtual PxU32 getFlatListStartIndex() const =0
Get the start index for the first particle of this particle buffer in the complete list of particles ...
virtual PxU32 getMaxParticleVolumes() const =0
Get the maximum number of particle volumes this particle buffer can hold.
virtual void setInternalData(void *data)=0
Reserved for internal use.
virtual PxU32 * getPhases() const =0
Get phases for this particle buffer.
virtual PxU32 getNbActiveParticles() const =0
Get the number of active particles for this particle buffer.
virtual void setRigidAttachments(PxParticleRigidAttachment *attachments, PxU32 nbAttachments)=0
Set the particle-rigid body attachments for particles in this particle buffer.
PxU32 bufferIndex
Index of this buffer in the particle system it is assigned to.
Definition PxParticleBuffer.h:217
virtual void onParticleSystemDestroy()=0
Cleanup helper used in case a particle system is released before the particle buffers have been remov...
A particle buffer used to simulate particle cloth.
Definition PxParticleBuffer.h:429
virtual void setNbTriangles(PxU32 nbTriangles)=0
Set the number of triangles for this particle buffer.
virtual PxVec4 * getRestPositions()=0
Get rest positions for this particle buffer.
virtual PxParticleSpring * getSprings()=0
Get the springs for this particle buffer.
virtual PxU32 getNbTriangles() const =0
Get the number of triangles for this particle buffer.
virtual PxU32 * getTriangles() const =0
Get the triangle indices for this particle buffer.
virtual PxU32 getNbSprings() const =0
Get the number of springs in this particle buffer.
virtual void setCloths(PxPartitionedParticleCloth &cloths)=0
Set cloths for this particle buffer.
Preprocessor to prepare particle cloths for simulation.
Definition PxParticleBuffer.h:569
virtual void partitionSprings(const PxParticleClothDesc &clothDesc, PxPartitionedParticleCloth &output)=0
Partition the spring constraints for particle cloth simulation.
virtual void release()=0
Release this object and deallocate all the memory.
A particle buffer used to simulate rigid bodies using shape matching with particles.
Definition PxParticleBuffer.h:491
virtual PxVec4 * getRigidLocalPositions() const =0
Get the local position of each particle relative to the rigid body's center of mass.
virtual PxVec4 * getRigidLocalNormals() const =0
Get the local space normals for each particle relative to the shape of the corresponding rigid body.
virtual PxU32 getNbRigids() const =0
Get the number of shape matched rigid bodies in this buffer.
virtual PxReal * getRigidCoefficients() const =0
Get the stiffness coefficients for all shape matched rigid bodies in this buffer.
virtual void setNbRigids(PxU32 nbRigids)=0
Set the number of shape matched rigid bodies in this buffer.
virtual PxVec4 * getRigidRotations() const =0
Get the world-space rotation of every shape-matched rigid body in this buffer.
virtual PxU32 * getRigidOffsets() const =0
Get the particle indices of the first particle for each shape matched rigid body.
virtual PxVec4 * getRigidTranslations() const =0
Get the world-space translations for all rigid bodies in this buffer.
Definition PxVec4.h:50
#define PX_CALL_CONV
Definition PxPreprocessor.h:299
#define PX_INLINE
Definition PxPreprocessor.h:320
PX_C_EXPORT PX_PHYSX_CORE_API physx::PxParticleClothPreProcessor *PX_CALL_CONV PxCreateParticleClothPreProcessor(physx::PxCudaContextManager *cudaContextManager)
Create a particle cloth preprocessor.
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Flags for PxBase.
Definition PxBase.h:54
an enumeration of concrete classes inheriting from PxBase
Definition PxTypeInfo.h:53
Enum
Definition PxParticleSystemFlag.h:47
Structure to describe the set of particle cloths in the same #PxParticleClothBuffer....
Definition PxParticleBuffer.h:372
PxParticleCloth * cloths
List of PxParticleCloth s, describes the individual cloths.
Definition PxParticleBuffer.h:378
PxVec4 * restPositions
List of rest positions for all particles.
Definition PxParticleBuffer.h:381
PxU32 nbTriangles
The number of triangles in this cloth descriptor.
Definition PxParticleBuffer.h:384
PxU32 nbCloths
The number of cloths in described using this cloth descriptor.
Definition PxParticleBuffer.h:382
PxU32 nbParticles
The number of particles in this cloth descriptor.
Definition PxParticleBuffer.h:385
PxParticleSpring * springs
List of PxParticleSpring s.
Definition PxParticleBuffer.h:380
PxU32 * triangles
List of triangle indices, 3 consecutive PxU32 that map triangle vertices to particles.
Definition PxParticleBuffer.h:379
PxU32 nbSprings
The number of springs in this cloth descriptor.
Definition PxParticleBuffer.h:383
Particle cloth structure. Holds information about a single piece of cloth that is part of a #PxPartic...
Definition PxParticleBuffer.h:352
PxU32 numTriangles
The number of triangles of this piece of cloth.
Definition PxParticleBuffer.h:359
PxU32 startVertexIndex
Index of the first particle of this cloth in the position/velocity buffers of the parent #PxParticleC...
Definition PxParticleBuffer.h:353
PxReal clothBlendScale
Used internally.
Definition PxParticleBuffer.h:355
PxU32 numVertices
The number of particles of this piece of cloth.
Definition PxParticleBuffer.h:354
PxReal restVolume
The rest volume of this piece of cloth, used for inflatable simulation.
Definition PxParticleBuffer.h:356
PxU32 startTriangleIndex
The index of the first triangle of this piece of cloth in the triangle list.
Definition PxParticleBuffer.h:358
PxReal pressure
The factor of the rest volume to specify the target volume for this piece of cloth,...
Definition PxParticleBuffer.h:357
Struct to specify attachment between a particle/vertex and a rigid.
Definition PxAttachment.h:49
Struct for storing a particle/vertex - rigid filter pair with comparison operators.
Definition PxFiltering.h:751
Particle volume structure. Used to track the bounding volume of a user-specified set of particles....
Definition PxParticleBuffer.h:64
PxU32 numParticles
The number of particles contained in this #PxParticleVolume.
Definition PxParticleBuffer.h:67
PxU32 particleIndicesOffset
The index into the particle list of the #PxParticleBuffer for the first particle of this volume.
Definition PxParticleBuffer.h:66
PxBounds3 bound
The current bounds of the particles contained in this #PxParticleVolume.
Definition PxParticleBuffer.h:65
Structure to describe the output of the particle cloth preprocessing. Used as an input to specify clo...
Definition PxParticleBuffer.h:395
void allocateBuffers(PxU32 nbParticles, PxCudaContextManager *cudaManager)
allocate all the buffers for this PxPartitionedParticleCloth.
PxU32 * sortedClothStartIndices
The first particle index into the position buffer of the #PxParticleClothBuffer for each cloth....
Definition PxParticleBuffer.h:400
PxU32 nbCloths
The number of cloths.
Definition PxParticleBuffer.h:406
PxU32 * remapOutput
Index of the next copy of this particle in the next partition, or in the accumulation buffer....
Definition PxParticleBuffer.h:398
PxU32 * accumulatedCopiesPerParticles
Start index for each particle in the accumulation buffer. Size: numParticles.
Definition PxParticleBuffer.h:397
PxU32 nbSprings
The number of springs.
Definition PxParticleBuffer.h:405
PxParticleCloth * cloths
The #PxParticleCloth s sorted by start particle index.
Definition PxParticleBuffer.h:401
PxCudaContextManager * mCudaManager
A cuda context manager.
Definition PxParticleBuffer.h:409
PxU32 * accumulatedSpringsPerPartitions
The number of springs in each partition. Size: numPartitions.
Definition PxParticleBuffer.h:396
PxParticleSpring * orderedSprings
Springs ordered by partition. Size: numSprings.
Definition PxParticleBuffer.h:399
PxU32 maxSpringsPerPartition
The maximum number of springs in a partition.
Definition PxParticleBuffer.h:407
PxU32 nbPartitions
The number of partitions.
Definition PxParticleBuffer.h:404
PxU32 remapOutputSize
Size of remapOutput.
Definition PxParticleBuffer.h:403