RavEngine
Loading...
Searching...
No Matches
DyParticleSystemCore.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
27#ifndef DY_PARTICLESYSTEM_CORE_H
28#define DY_PARTICLESYSTEM_CORE_H
29
30#include "foundation/PxSimpleTypes.h"
31#include "foundation/PxTransform.h"
32#include "foundation/PxArray.h"
33#include "foundation/PxMemory.h"
34#include "PxParticleSystem.h"
35#include "PxParticleBuffer.h"
36#include "CmIDPool.h"
37#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
38#include "PxFLIPParticleSystem.h"
39#include "PxMPMParticleSystem.h"
40#endif
41#include "PxParticleSolverType.h"
42#include "PxCustomParticleSystemSolverCallback.h"
43#include "PxSparseGridParams.h"
44
45namespace physx
46{
47namespace Dy
48{
49
51{
52public:
53
54 PxReal sleepThreshold;
55 PxReal freezeThreshold;
56 PxReal wakeCounter;
57
58 PxU32 gridSizeX;
59 PxU32 gridSizeY;
60 PxU32 gridSizeZ;
61
63
64 bool enableCCD;
65
66 PxU16 solverIterationCounts;
67
68 PxSparseGridParams sparseGridParams;
69
70#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
71 PxFLIPParams flipParams;
72 PxMPMParams mpmParams;
73#endif
74
75 PxReal restOffset;
76 PxReal particleContactOffset;
77 PxReal particleContactOffset_prev;
78 PxReal solidRestOffset;
79 PxReal fluidRestOffset;
80 PxReal fluidRestOffset_prev;
81
82 PxReal fluidBoundaryDensityScale;
83
84 PxReal maxDepenetrationVelocity;
85 PxReal maxVelocity;
86
87 PxVec3 periodicBoundary;
88
89 PxParticleFlags mFlags;
90
91 PxVec3 mWind;
92
93 PxU32 mMaxNeighborhood;
94
95 PxArray<PxU16> mPhaseGroupToMaterialHandle;
96
97 void addParticleBuffer(PxParticleBuffer* particleBuffer)
98 {
99 if (particleBuffer->bufferIndex == 0xffffffff)
100 {
101 switch (particleBuffer->getConcreteType())
102 {
103 case (PxConcreteType::ePARTICLE_BUFFER):
104 {
105 particleBuffer->bufferIndex = mParticleBuffers.size();
106 mParticleBuffers.pushBack(particleBuffer);
107 mParticleBufferUpdate = true;
108 particleBuffer->setInternalData(this);
109 return;
110 }
111
112 case (PxConcreteType::ePARTICLE_DIFFUSE_BUFFER):
113 {
114 particleBuffer->bufferIndex = mParticleAndDiffuseBuffers.size();
115 mParticleAndDiffuseBuffers.pushBack(reinterpret_cast<PxParticleAndDiffuseBuffer*>(particleBuffer));
116 mParticleAndDiffuseBufferUpdate = true;
117 particleBuffer->setInternalData(this);
118 return;
119 }
120
121 case (PxConcreteType::ePARTICLE_CLOTH_BUFFER):
122 {
123 particleBuffer->bufferIndex = mClothBuffers.size();
124 mClothBuffers.pushBack(reinterpret_cast<PxParticleClothBuffer*>(particleBuffer));
125 mClothBufferUpdate = true;
126 particleBuffer->setInternalData(this);
127 return;
128 }
129
130 case (PxConcreteType::ePARTICLE_RIGID_BUFFER):
131 {
132 particleBuffer->bufferIndex = mRigidBuffers.size();
133 mRigidBuffers.pushBack(reinterpret_cast<PxParticleRigidBuffer*>(particleBuffer));
134 mRigidBufferUpdate = true;
135 particleBuffer->setInternalData(this);
136 return;
137 }
138
139 default:
140 {
141 PxGetFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "addParticleBuffer : Error, this buffer does not have a valid type!");
142 return;
143 }
144
145 }
146 }
147 else
148 {
149 PxGetFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "addParticleBuffer : Error, this buffer cannot be added to multiple particle systems!");
150 }
151 }
152
153 void removeParticleBuffer(PxParticleBuffer* particleBuffer)
154 {
155 const PxU32 index = particleBuffer->bufferIndex;
156
157 switch (particleBuffer->getConcreteType())
158 {
159 case (PxConcreteType::ePARTICLE_BUFFER):
160 {
161 if (index < mParticleBuffers.size())
162 {
163 mParticleBuffers.replaceWithLast(particleBuffer->bufferIndex);
164 if (mParticleBuffers.size() > index)
165 mParticleBuffers[index]->bufferIndex = index;
166 mParticleBufferUpdate = true;
167 particleBuffer->bufferIndex = 0xffffffff;
168 particleBuffer->onParticleSystemDestroy();
169 }
170 return;
171 }
172
173 case (PxConcreteType::ePARTICLE_DIFFUSE_BUFFER):
174 {
175 if (index < mParticleAndDiffuseBuffers.size())
176 {
177 mParticleAndDiffuseBuffers.replaceWithLast(particleBuffer->bufferIndex);
178 if (mParticleAndDiffuseBuffers.size() > index)
179 mParticleAndDiffuseBuffers[index]->bufferIndex = index;
180
181 mParticleAndDiffuseBufferUpdate = true;
182 particleBuffer->bufferIndex = 0xffffffff;
183 particleBuffer->onParticleSystemDestroy();
184 }
185 return;
186 }
187
188 case (PxConcreteType::ePARTICLE_CLOTH_BUFFER):
189 {
190 if (index < mClothBuffers.size())
191 {
192 mClothBuffers.replaceWithLast(particleBuffer->bufferIndex);
193 if (mClothBuffers.size() > index)
194 mClothBuffers[index]->bufferIndex = index;
195 mClothBufferUpdate = true;
196 particleBuffer->bufferIndex = 0xffffffff;
197 particleBuffer->onParticleSystemDestroy();
198 }
199 return;
200 }
201
202 case (PxConcreteType::ePARTICLE_RIGID_BUFFER):
203 {
204 if (index < mParticleBuffers.size())
205 {
206 mRigidBuffers.replaceWithLast(particleBuffer->bufferIndex);
207 if (mRigidBuffers.size() > index)
208 mRigidBuffers[index]->bufferIndex = index;
209
210 mRigidBufferUpdate = true;
211 particleBuffer->bufferIndex = 0xffffffff;
212 particleBuffer->onParticleSystemDestroy();
213 }
214 return;
215 }
216
217 default:
218 {
219 PxGetFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "removeParticleBuffer : Error, this buffer does not have a valid type!");
220 return;
221 }
222
223 }
224 }
225
226 PxU32 getNumUserBuffers() const { return mParticleBuffers.size() + mClothBuffers.size() + mRigidBuffers.size() + mParticleAndDiffuseBuffers.size(); }
227 //device
228 PxArray<PxParticleBuffer*> mParticleBuffers;
231 PxArray<PxParticleAndDiffuseBuffer*> mParticleAndDiffuseBuffers;
232
233 bool mParticleBufferUpdate;
234 bool mClothBufferUpdate;
235 bool mRigidBufferUpdate;
236 bool mParticleAndDiffuseBufferUpdate;
237
238 PxParticleSystemCallback* mCallback;
240
242 {
243 PxMemSet(this, 0, sizeof(*this));
244 mParticleBufferUpdate = false;
245 mClothBufferUpdate = false;
246 mRigidBufferUpdate = false;
247 mParticleAndDiffuseBufferUpdate = false;
248 }
249
251 {
252 for(PxU32 i = 0; i < mParticleBuffers.size(); ++i)
253 {
254 mParticleBuffers[i]->onParticleSystemDestroy();
255 }
256
257 for (PxU32 i = 0; i < mClothBuffers.size(); ++i)
258 {
259 mClothBuffers[i]->onParticleSystemDestroy();
260 }
261
262 for (PxU32 i = 0; i < mRigidBuffers.size(); ++i)
263 {
264 mRigidBuffers[i]->onParticleSystemDestroy();
265 }
266
267 for (PxU32 i = 0; i < mParticleAndDiffuseBuffers.size(); ++i)
268 {
269 mParticleAndDiffuseBuffers[i]->onParticleSystemDestroy();
270 }
271 }
272};
273
274} // namespace Dy
275} // namespace physx
276
277#endif
278
Definition DyParticleSystemCore.h:51
Definition PxArray.h:53
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
PX_FORCE_INLINE PxType getConcreteType() const
Returns concrete type of object.
Definition PxBase.h:118
Definition PxCustomParticleSystemSolverCallback.h:51
A particle buffer used to simulate diffuse particles.
Definition PxParticleBuffer.h:283
The shared base class for all particle buffers, can be instantiated directly to simulate granular and...
Definition PxParticleBuffer.h:81
virtual void setInternalData(void *data)=0
Reserved for internal use.
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
A particle buffer used to simulate rigid bodies using shape matching with particles.
Definition PxParticleBuffer.h:491
Particle system callback base class to schedule work that should be done before, while or after the p...
Definition PxParticleSystem.h:77
3 Element vector class.
Definition PxVec3.h:50
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
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemSet(void *dest, PxI32 c, PxU32 count)
Sets the bytes of the provided buffer to the specified value.
Definition PxMemory.h:67
@ eINVALID_OPERATION
method was called at a time when an operation is not possible
Definition PxErrors.h:65
Enum
Definition PxParticleSolverType.h:53
Parameters to define the sparse grid settings like grid spacing, maximal number of subgrids etc.
Definition PxSparseGridParams.h:46