RavEngine
Loading...
Searching...
No Matches
NpFactory.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 NP_FACTORY_H
30#define NP_FACTORY_H
31
32#include "foundation/PxPool.h"
33#include "foundation/PxMutex.h"
34#include "foundation/PxHashSet.h"
35
36#include "GuMeshFactory.h"
37#include "PxPhysXConfig.h"
38#include "PxShape.h"
39#include "PxAggregate.h"
40
41
42#include "NpFEMCloth.h" // to be deleted
43
44namespace physx
45{
46class PxCudaContextManager;
47
48class PxActor;
49
50class PxRigidActor;
51
52class PxRigidStatic;
53class NpRigidStatic;
54
55class PxRigidDynamic;
56class NpRigidDynamic;
57
58class NpConnectorArray;
59
60struct PxConstraintShaderTable;
61class PxConstraintConnector;
62class PxConstraint;
63class NpConstraint;
64
65class PxArticulationReducedCoordinate;
66class NpArticulationReducedCoordinate;
67class PxArticulationLink;
68class NpArticulationLink;
69class NpArticulationJointReducedCoordinate;
70
71class PxSoftBody;
72class PxFEMCloth;
73class PxParticleSystem;
74class PxHairSystem;
75
76#if PX_SUPPORT_GPU_PHYSX
77class NpSoftBody;
78class NpFEMCloth;
79class NpPBDParticleSystem;
80class NpFLIPParticleSystem;
81class NpMPMParticleSystem;
82class NpCustomParticSystem;
83class NpHairSystem;
84
85class NpFEMSoftBodyMaterial;
86class NpFEMClothMaterial;
87class NpPBDMaterial;
88class NpFLIPMaterial;
89class NpMPMMaterial;
90class NpCustomMaterial;
91#endif
92
93class PxMaterial;
94class NpMaterial;
95
96class PxFEMSoftBodyMaterial;
97class PxFEMClothMaterial;
98class PxPBDMaterial;
99class PxFLIPMaterial;
100class PxMPMMaterial;
101
102class PxGeometry;
103
104class NpShape;
105
106class NpAggregate;
107
108class NpPtrTableStorageManager;
109
110namespace Cm
111{
112 class Collection;
113}
114
116{
117protected:
118 virtual ~NpFactoryListener(){}
119};
120
122{
123 PX_NOCOPY(NpFactory)
124public:
125 NpFactory();
126private:
127 ~NpFactory();
128
129 template <typename PxMaterialType, typename NpMaterialType>
130 NpShape* createShapeInternal(const PxGeometry& geometry, PxShapeFlags shapeFlags, PxMaterialType*const* materials, PxU16 materialCount, bool isExclusive, PxShapeCoreFlag::Enum flag);
131public:
132 static void createInstance();
133 static void destroyInstance();
134 static void registerArticulations();
135 static void registerArticulationRCs();
136 static void onParticleBufferRelease(PxParticleBuffer* buffer);
137
138 void release();
139
140 void addCollection(const Cm::Collection& collection);
141
142 PX_INLINE static NpFactory& getInstance() { return *mInstance; }
143
144 // Rigid dynamic
145 PxRigidDynamic* createRigidDynamic(const PxTransform& pose);
146 void addRigidDynamic(PxRigidDynamic*, bool lock=true);
147 void releaseRigidDynamicToPool(NpRigidDynamic&);
148// PT: TODO: add missing functions
149// PxU32 getNbRigidDynamics() const;
150// PxU32 getRigidDynamics(PxRigidDynamic** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
151
152 // Rigid static
153 PxRigidStatic* createRigidStatic(const PxTransform& pose);
154 void addRigidStatic(PxRigidStatic*, bool lock=true);
155 void releaseRigidStaticToPool(NpRigidStatic&);
156// PT: TODO: add missing functions
157// PxU32 getNbRigidStatics() const;
158// PxU32 getRigidStatics(PxRigidStatic** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
159
160 // Shapes
161 NpShape* createShape(const PxGeometry& geometry, PxShapeFlags shapeFlags, PxMaterial*const* materials, PxU16 materialCount, bool isExclusive);
162 NpShape* createShape(const PxGeometry& geometry, PxShapeFlags shapeFlags, PxFEMSoftBodyMaterial*const* materials, PxU16 materialCount, bool isExclusive);
163#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
164 NpShape* createShape(const PxGeometry& geometry, PxShapeFlags shapeFlags, PxFEMClothMaterial*const* materials, PxU16 materialCount, bool isExclusive);
165#endif
166 void addShape(PxShape*, bool lock=true);
167 void releaseShapeToPool(NpShape&);
168 PxU32 getNbShapes() const;
169 PxU32 getShapes(PxShape** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
170
171 // Constraints
172 PxConstraint* createConstraint(PxRigidActor* actor0, PxRigidActor* actor1, PxConstraintConnector& connector, const PxConstraintShaderTable& shaders, PxU32 dataSize);
173 void addConstraint(PxConstraint*, bool lock=true);
174 void releaseConstraintToPool(NpConstraint&);
175// PT: TODO: add missing functions
176// PxU32 getNbConstraints() const;
177// PxU32 getConstraints(PxConstraint** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
178
179 // Articulations
180 void addArticulation(PxArticulationReducedCoordinate*, bool lock=true);
181 void releaseArticulationToPool(PxArticulationReducedCoordinate& articulation);
182 PxArticulationReducedCoordinate* createArticulationRC();
183 NpArticulationReducedCoordinate* createNpArticulationRC();
184
185 // Articulation links
186 NpArticulationLink* createNpArticulationLink(NpArticulationReducedCoordinate& root, NpArticulationLink* parent, const PxTransform& pose);
187 void releaseArticulationLinkToPool(NpArticulationLink& articulation);
188 PxArticulationLink* createArticulationLink(NpArticulationReducedCoordinate& root, NpArticulationLink* parent, const PxTransform& pose);
189
190 NpArticulationJointReducedCoordinate* createNpArticulationJointRC(NpArticulationLink& parent, const PxTransform& parentFrame, NpArticulationLink& child, const PxTransform& childFrame);
191 void releaseArticulationJointRCToPool(NpArticulationJointReducedCoordinate& articulationJoint);
192
193 //Soft bodys
194 PxSoftBody* createSoftBody(PxCudaContextManager& cudaContextManager);
195 void releaseSoftBodyToPool(PxSoftBody& softBody);
196
197#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
198 // FEMCloth
199 PxFEMCloth* createFEMCloth(PxCudaContextManager& cudaContextManager);
200 void releaseFEMClothToPool(PxFEMCloth& femCloth);
201#endif
202
203 //Particle systems
204 PxPBDParticleSystem* createPBDParticleSystem(PxU32 maxNeighborhood, PxCudaContextManager& cudaContexManager);
205 void releasePBDParticleSystemToPool(PxPBDParticleSystem& particleSystem);
206
207#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
208 //Particle systems
209 PxFLIPParticleSystem* createFLIPParticleSystem(PxCudaContextManager& cudaContexManager);
210 void releaseFLIPParticleSystemToPool(PxFLIPParticleSystem& particleSystem);
211
212 //Particle systems
213 PxMPMParticleSystem* createMPMParticleSystem(PxCudaContextManager& cudaContexManager);
214 void releaseMPMParticleSystemToPool(PxMPMParticleSystem& particleSystem);
215
216 //Particle systems
217 PxCustomParticleSystem* createCustomParticleSystem(PxCudaContextManager& cudaContexManager, PxU32 maxNeighborhood);
218 void releaseCustomParticleSystemToPool(PxCustomParticleSystem& particleSystem);
219#endif
220
221 //Particle buffers
222 PxParticleBuffer* createParticleBuffer(PxU32 maxParticles, PxU32 maxVolumes, PxCudaContextManager* cudaContextManager);
223
224 //Diffuse Particle buffers
225 PxParticleAndDiffuseBuffer* createParticleAndDiffuseBuffer(PxU32 maxParticles, PxU32 maxVolumes, PxU32 maxDiffuseParticles, PxCudaContextManager* cudaContextManager);
226
227 //Particle cloth buffers
228 PxParticleClothBuffer* createParticleClothBuffer(PxU32 maxParticles, PxU32 maxNumVolumes, PxU32 maxNumCloths, PxU32 maxNumTriangles, PxU32 maxNumSprings, PxCudaContextManager* cudaContextManager);
229
230 //Particle rigid buffers
231 PxParticleRigidBuffer* createParticleRigidBuffer(PxU32 maxParticles, PxU32 maxNumVolumes, PxU32 maxNumRigids, PxCudaContextManager* cudaContextManager);
232
233#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
234 // HairSystem
235 PxHairSystem* createHairSystem(PxCudaContextManager& cudaContextManager);
236 void releaseHairSystemToPool(PxHairSystem& hairSystem);
237#endif
238
239 // Aggregates
240 PxAggregate* createAggregate(PxU32 maxActors, PxU32 maxShapes, PxAggregateFilterHint filterHint);
241 void addAggregate(PxAggregate*, bool lock=true);
242 void releaseAggregateToPool(NpAggregate&);
243// PT: TODO: add missing functions
244// PxU32 getNbAggregates() const;
245// PxU32 getAggregates(PxAggregate** userBuffer, PxU32 bufferSize, PxU32 startIndex) const;
246
247 // Materials
248 PxMaterial* createMaterial(PxReal staticFriction, PxReal dynamicFriction, PxReal restitution);
249 void releaseMaterialToPool(NpMaterial& material);
250
251 PxFEMSoftBodyMaterial* createFEMSoftBodyMaterial(PxReal youngs, PxReal poissons, PxReal dynamicFriction);
252 void releaseFEMMaterialToPool(PxFEMSoftBodyMaterial& material);
253
254 PxFEMClothMaterial* createFEMClothMaterial(PxReal youngs, PxReal poissons, PxReal dynamicFriction);
255 void releaseFEMClothMaterialToPool(PxFEMClothMaterial& material);
256
257 PxPBDMaterial* createPBDMaterial(PxReal friction, PxReal damping, PxReal adhesion, PxReal viscosity, PxReal vorticityConfinement, PxReal surfaceTension, PxReal cohesion, PxReal lift, PxReal drag, PxReal cflCoefficient, PxReal gravityScale);
258 void releasePBDMaterialToPool(PxPBDMaterial& material);
259
260#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
261 PxFLIPMaterial* createFLIPMaterial(PxReal friction, PxReal damping, PxReal adhesion, PxReal viscosity, PxReal gravityScale);
262 void releaseFLIPMaterialToPool(PxFLIPMaterial& material);
263#endif
264
265 PxMPMMaterial* createMPMMaterial(PxReal friction, PxReal damping, PxReal adhesion, bool isPlastic, PxReal youngsModulus, PxReal poissons, PxReal hardening, PxReal criticalCompression, PxReal criticalStretch, PxReal tensileDamageSensitivity, PxReal compressiveDamageSensitivity, PxReal attractiveForceResidual, PxReal gravityScale);
266 void releaseMPMMaterialToPool(PxMPMMaterial& material);
267
268 PxCustomMaterial* createCustomMaterial(void* gpuBuffer);
269 void releaseCustomMaterialToPool(PxCustomMaterial& material);
270
271 // It's easiest to track these uninvasively, so it's OK to use the Px pointers
272 void onActorRelease(PxActor*);
273 void onConstraintRelease(PxConstraint*);
274 void onAggregateRelease(PxAggregate*);
275 void onArticulationRelease(PxArticulationReducedCoordinate*);
276 void onShapeRelease(PxShape*);
277
278 void addParticleBuffer(PxParticleBuffer* buffer, bool lock = true);
279 void onParticleBufferReleaseInternal(PxParticleBuffer* buffer);
280
281 NpConnectorArray* acquireConnectorArray();
282 void releaseConnectorArray(NpConnectorArray*);
283
284 PX_FORCE_INLINE NpPtrTableStorageManager& getPtrTableStorageManager() { return *mPtrTableStorageManager; }
285
286#if PX_SUPPORT_PVD
287 void setNpFactoryListener( NpFactoryListener& );
288#endif
289
290private:
291 void releaseExclusiveShapeUserReferences();
292
293 PxPool<NpConnectorArray> mConnectorArrayPool;
294 PxMutex mConnectorArrayPoolLock;
295
296 NpPtrTableStorageManager* mPtrTableStorageManager;
297
298 PxHashSet<PxAggregate*> mAggregateTracking;
300 PxHashSet<PxConstraint*> mConstraintTracking;
301 PxHashSet<PxActor*> mActorTracking;
302 PxCoalescedHashSet<PxShape*> mShapeTracking;
303 PxHashSet<PxParticleBuffer*> mParticleBufferTracking;
304
305 PxPool2<NpRigidDynamic, 4096> mRigidDynamicPool;
306 PxMutex mRigidDynamicPoolLock;
307
308 PxPool2<NpRigidStatic, 4096> mRigidStaticPool;
309 PxMutex mRigidStaticPoolLock;
310
311 PxPool2<NpShape, 4096> mShapePool;
312 PxMutex mShapePoolLock;
313
314 PxPool2<NpAggregate, 4096> mAggregatePool;
315 PxMutex mAggregatePoolLock;
316
317 PxPool2<NpConstraint, 4096> mConstraintPool;
318 PxMutex mConstraintPoolLock;
319
320 PxPool2<NpMaterial, 4096> mMaterialPool;
321 PxMutex mMaterialPoolLock;
322
324 PxMutex mArticulationRCPoolLock;
325
326 PxPool2<NpArticulationLink, 4096> mArticulationLinkPool;
327 PxMutex mArticulationLinkPoolLock;
328
329
331 PxMutex mArticulationJointRCPoolLock;
332
333#if PX_SUPPORT_GPU_PHYSX
334 PxPool2<NpSoftBody, 4096> mSoftBodyPool;
335 PxMutex mSoftBodyPoolLock;
336
337#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
338 PxPool2<NpFEMCloth, 4096> mFEMClothPool;
339 PxMutex mFEMClothPoolLock;
340#endif
341
342 PxPool2<NpPBDParticleSystem, 4096> mPBDParticleSystemPool;
343 PxMutex mPBDParticleSystemPoolLock;
344#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
345 PxPool2<NpFLIPParticleSystem, 4096> mFLIPParticleSystemPool;
346 PxMutex mFLIPParticleSystemPoolLock;
347
348 PxPool2<NpMPMParticleSystem, 4096> mMPMParticleSystemPool;
349 PxMutex mMPMParticleSystemPoolLock;
350
351 PxPool2<NpCustomParticleSystem, 4096> mCustomParticleSystemPool;
352 PxMutex mCustomParticleSystemPoolLock;
353#endif
354
356 PxMutex mFEMMaterialPoolLock;
357
358#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
359 PxPool2<NpFEMClothMaterial, 4096> mFEMClothMaterialPool;
360 PxMutex mFEMClothMaterialPoolLock;
361#endif
362 PxPool2<NpPBDMaterial, 4096> mPBDMaterialPool;
363 PxMutex mPBDMaterialPoolLock;
364#if PX_ENABLE_FEATURES_UNDER_CONSTRUCTION
365 PxPool2<NpFLIPMaterial, 4096> mFLIPMaterialPool;
366 PxMutex mFLIPMaterialPoolLock;
367
368 PxPool2<NpMPMMaterial, 4096> mMPMMaterialPool;
369 PxMutex mMPMMaterialPoolLock;
370
371 PxPool2<NpCustomMaterial, 4096> mCustomMaterialPool;
372 PxMutex mCustomMaterialPoolLock;
373 /*PxPool2<NpFEMSoftBodyMaterial, 4096> mFEMMaterialPool;
374 PxMutex mFEMMaterialPoolLock;*/
375
376 PxPool2<NpHairSystem, 4096> mHairSystemPool;
377 PxMutex mHairSystemPoolLock;
378#endif
379#endif
380
381 static NpFactory* mInstance;
382 PxU64 mGpuMemStat;
383
384#if PX_SUPPORT_PVD
385 NpFactoryListener* mNpFactoryListener;
386#endif
387};
388
389 void NpDestroyRigidActor(NpRigidStatic* np);
390 void NpDestroyRigidDynamic(NpRigidDynamic* np);
391 void NpDestroyArticulationLink(NpArticulationLink* np);
392 void NpDestroyArticulationJoint(PxArticulationJointReducedCoordinate* np);
393 void NpDestroyArticulation(PxArticulationReducedCoordinate* artic);
394 void NpDestroyAggregate(NpAggregate* np);
395 void NpDestroyShape(NpShape* np);
396 void NpDestroyConstraint(NpConstraint* np);
397
398#if PX_SUPPORT_GPU_PHYSX
399 void NpDestroySoftBody(NpSoftBody* softBody);
400 void NpDestroyFEMCloth(NpFEMCloth* femCloth);
401 void NpDestroyParticleSystem(NpPBDParticleSystem* particleSystem);
402 void NpDestroyParticleSystem(NpFLIPParticleSystem* particleSystem);
403 void NpDestroyParticleSystem(NpMPMParticleSystem* particleSystem);
404 void NpDestroyParticleSystem(NpCustomParticleSystem* particleSystem);
405 void NpDestroyHairSystem(NpHairSystem* hairSystem);
406#endif
407}
408
409#endif
Definition CmCollection.h:61
Definition GuMeshFactory.h:66
Definition GuMeshFactory.h:83
Definition NpAggregate.h:40
Definition NpArticulationJointReducedCoordinate.h:49
Definition NpArticulationReducedCoordinate.h:56
Definition NpConnector.h:112
Definition NpConstraint.h:43
Definition NpFactory.h:116
Definition NpFactory.h:122
Definition NpMaterial.h:46
Definition NpParticleSystem.h:444
Definition NpPtrTableStorageManager.h:40
Definition NpRigidDynamic.h:41
Definition NpRigidStatic.h:42
Definition NpShape.h:44
Definition NpSoftBody.h:43
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Class to aggregate actors into a single broad-phase entry.
Definition PxAggregate.h:98
A joint between two links in an articulation.
Definition PxArticulationJointReducedCoordinate.h:49
A tree structure of bodies connected by joints that is treated as a unit by the dynamics solver....
Definition PxArticulationReducedCoordinate.h:448
Definition PxHashSet.h:100
This class connects a custom constraint to the SDK.
Definition PxConstraintDesc.h:354
A plugin class for implementing constraints.
Definition PxConstraint.h:100
Definition PxPBDMaterial.h:215
Material class to represent a set of FEM material properties.
Definition PxFEMClothMaterial.h:48
Material class to represent a set of softbody FEM material properties.
Definition PxFEMSoftBodyMaterial.h:49
Material class to represent a set of FLIP particle material properties.
Definition PxFLIPMaterial.h:49
A geometry object.
Definition PxGeometry.h:79
Definition PxHashSet.h:77
Material class to represent a set of MPM particle material properties.
Definition PxMPMMaterial.h:94
Material class to represent a set of surface properties.
Definition PxMaterial.h:149
Definition PxMutex.h:89
Material class to represent a set of PBD particle material properties.
Definition PxPBDMaterial.h:49
A particle system that uses the position based dynamics(PBD) solver.
Definition PxPBDParticleSystem.h:57
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
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
Definition PxPool.h:259
Definition PxPool.h:248
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
PxRigidDynamic represents a dynamic rigid simulation object in the physics SDK.
Definition PxRigidDynamic.h:82
PxRigidStatic represents a static rigid body simulation object in the physics SDK.
Definition PxRigidStatic.h:58
Abstract class for collision shapes.
Definition PxShape.h:146
Represents a FEM softbody including everything to calculate its definition like geometry and material...
Definition PxSoftBody.h:104
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#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
a table of function pointers for a constraint
Definition PxConstraint.h:87