RavEngine
Loading...
Searching...
No Matches
NpSoftBody.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_SOFTBODY_H
30#define NP_SOFTBODY_H
31
32#include "PxSoftBody.h"
33#include "ScSoftBodyCore.h"
34#include "NpActorTemplate.h"
35#include "GuTetrahedronMesh.h"
36
37namespace physx
38{
39 class NpScene;
40 class NpShape;
41
42 class NpSoftBody : public NpActorTemplate<PxSoftBody>
43 {
44 public:
45 NpSoftBody(PxCudaContextManager& cudaContextManager);
46 NpSoftBody(PxBaseFlags baseFlags, PxCudaContextManager& cudaContextManager);
47
48 virtual ~NpSoftBody() {}
49
50 void exportData(PxSerializationContext& /*context*/) const{}
51
52 //external API
54
55 virtual PxBounds3 getWorldBounds(float inflation = 1.01f) const;
56 virtual PxU32 getGpuSoftBodyIndex();
57
58 virtual void setSoftBodyFlag(PxSoftBodyFlag::Enum flag, bool val);
59 virtual void setSoftBodyFlags(PxSoftBodyFlags flags);
61
62 virtual void setParameter(const PxFEMParameters paramters);
64
65 virtual void readData(PxSoftBodyData::Enum flags, PxBuffer& buffer, bool flush);
66 virtual void readData(PxSoftBodyData::Enum flags, bool flush);
67
68 virtual void writeData(PxSoftBodyData::Enum flags, PxBuffer& buffer, bool flush);
69 virtual void writeData(PxSoftBodyData::Enum flags, bool flush);
70
71 virtual PxCudaContextManager* getCudaContextManager() const;
72
73 virtual void setWakeCounter(PxReal wakeCounterValue);
74 virtual PxReal getWakeCounter() const;
75
76 virtual bool isSleeping() const;
77
78 virtual void setSolverIterationCounts(PxU32 minPositionIters, PxU32 minVelocityIters);
79
80 virtual void getSolverIterationCounts(PxU32& minPositionIters, PxU32& minVelocityIters) const;
81
82 virtual PxShape* getShape();
86
87 virtual bool attachShape(PxShape& shape);
88 virtual bool attachSimulationMesh(PxTetrahedronMesh& simulationMesh, PxSoftBodyAuxData& softBodyAuxData);
89
90 virtual void detachShape();
91 virtual void detachSimulationMesh();
92
93 virtual void release();
94
95 PX_FORCE_INLINE const Sc::SoftBodyCore& getCore() const { return mCore; }
96 PX_FORCE_INLINE Sc::SoftBodyCore& getCore() { return mCore; }
97 static PX_FORCE_INLINE size_t getCoreOffset() { return PX_OFFSET_OF_RT(NpSoftBody, mCore); }
98
99 virtual void addParticleFilter(PxPBDParticleSystem* particlesystem, const PxParticleBuffer* buffer, PxU32 particleId, PxU32 tetId);
100 virtual void removeParticleFilter(PxPBDParticleSystem* particlesystem, const PxParticleBuffer* buffer, PxU32 particleId, PxU32 tetId);
101
102 virtual PxU32 addParticleAttachment(PxPBDParticleSystem* particlesystem, const PxParticleBuffer* buffer, PxU32 particleId, PxU32 tetId, const PxVec4& barycentric);
103 virtual void removeParticleAttachment(PxPBDParticleSystem* particlesystem, PxU32 handle);
104
105 virtual void addRigidFilter(PxRigidActor* actor, PxU32 vertId);
106 virtual void removeRigidFilter(PxRigidActor* actor, PxU32 vertId);
107
108 virtual PxU32 addRigidAttachment(PxRigidActor* actor, PxU32 vertId, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint);
109 virtual void removeRigidAttachment(PxRigidActor* actor, PxU32 handle);
110
111 virtual void addTetRigidFilter(PxRigidActor* actor, PxU32 tetIdx);
112 virtual void removeTetRigidFilter(PxRigidActor* actor, PxU32 tetIdx);
113
114 virtual PxU32 addTetRigidAttachment(PxRigidActor* actor, PxU32 tetIdx, const PxVec4& barycentric, const PxVec3& actorSpacePose,
115 PxConeLimitedConstraint* constraint);
116
117 virtual void addSoftBodyFilter(PxSoftBody* softbody0, PxU32 tetIdx0, PxU32 tetIdx1);
118 virtual void removeSoftBodyFilter(PxSoftBody* softbody0, PxU32 tetIdx0, PxU32 tetIdx1);
119 virtual void addSoftBodyFilters(PxSoftBody* softbody0, PxU32* tetIndices0, PxU32* tetIndices1, PxU32 tetIndicesSize);
120 virtual void removeSoftBodyFilters(PxSoftBody* softbody0, PxU32* tetIndices0, PxU32* tetIndices1, PxU32 tetIndicesSize);
121
122 virtual PxU32 addSoftBodyAttachment(PxSoftBody* softbody0, PxU32 tetIdx0, const PxVec4& tetBarycentric0, PxU32 tetIdx1, const PxVec4& tetBarycentric1,
123 PxConeLimitedConstraint* constraint);
124 virtual void removeSoftBodyAttachment(PxSoftBody* softbody0, PxU32 handle);
125
126 virtual void addClothFilter(PxFEMCloth* cloth, PxU32 triIdx, PxU32 tetIdx);
127 virtual void removeClothFilter(PxFEMCloth* cloth, PxU32 triIdx, PxU32 tetIdx);
128
129 virtual PxU32 addClothAttachment(PxFEMCloth* cloth, PxU32 triIdx, const PxVec4& triBarycentric, PxU32 tetIdx, const PxVec4& tetBarycentric,
130 PxConeLimitedConstraint* constraint);
131 virtual void removeClothAttachment(PxFEMCloth* cloth, PxU32 handle);
132
133 // Debug name
134 void setName(const char*);
135 const char* getName() const;
136
137 virtual PxBuffer* getSimPositionInvMassCPU() { return mCore.getCore().mSimPositionInvMassCPU; }
138 virtual PxBuffer* getSimVelocityInvMassCPU() { return mCore.getCore().mSimVelocityInvMassCPU; }
139 virtual PxBuffer* getKinematicTargetCPU() { return mCore.getCore().mKinematicTargetCPU; }
140
141 virtual PxBuffer* getPositionInvMassCPU() { return mCore.getCore().mPositionInvMassCPU; }
142 virtual PxBuffer* getRestPositionInvMassCPU() { return mCore.getCore().mRestPositionInvMassCPU; }
143
144 void updateMaterials();
145
146 private:
147
148 PxBuffer* getBufferFromFlag(PxSoftBodyData::Enum flags);
149 PxBuffer* getBufferHostFromFlag(PxSoftBodyData::Enum flags);
150
151 NpShape* mShape; //soft body should just have one shape. The geometry type should be tetrahedron mesh
152 Gu::TetrahedronMesh* mSimulationMesh;
153 Gu::SoftBodyAuxData* mSoftBodyAuxData;
154 Sc::SoftBodyCore mCore;
155 PxCudaContextManager* mCudaContextManager;
156 };
157}
158#endif
Definition GuTetrahedronMesh.h:54
Definition GuTetrahedronMesh.h:120
Definition NpActorTemplate.h:54
Definition NpShape.h:44
Definition NpSoftBody.h:43
virtual PxU32 addParticleAttachment(PxPBDParticleSystem *particlesystem, const PxParticleBuffer *buffer, PxU32 particleId, PxU32 tetId, const PxVec4 &barycentric)
Creates an attachment between a particle and a soft body. Be aware that destroying the particle syste...
virtual PxTetrahedronMesh * getCollisionMesh()
Retrieve the collision mesh pointer.
virtual PxBuffer * getSimPositionInvMassCPU()
Access to the vertices of the simulation mesh on the host.
Definition NpSoftBody.h:137
virtual void readData(PxSoftBodyData::Enum flags, bool flush)
Issues a read command to the PxSoftBody.
virtual void detachSimulationMesh()
Detaches the simulation mesh.
virtual void removeParticleAttachment(PxPBDParticleSystem *particlesystem, PxU32 handle)
Removes an attachment between a particle and a soft body. Be aware that destroying the particle syste...
virtual PxU32 addSoftBodyAttachment(PxSoftBody *softbody0, PxU32 tetIdx0, const PxVec4 &tetBarycentric0, PxU32 tetIdx1, const PxVec4 &tetBarycentric1, PxConeLimitedConstraint *constraint)
Creates an attachment between two soft bodies.
virtual void getSolverIterationCounts(PxU32 &minPositionIters, PxU32 &minVelocityIters) const
Retrieves the solver iteration counts.
virtual PxFEMParameters getParameter() const
Get parameter for FEM internal solve.
virtual void removeClothFilter(PxFEMCloth *cloth, PxU32 triIdx, PxU32 tetIdx)
Removes collision filter between a tetrahedron in a soft body and a triangle in a cloth.
virtual void removeRigidAttachment(PxRigidActor *actor, PxU32 handle)
Releases a rigid attachment between a soft body and a rigid body. Be aware that destroying the rigid ...
virtual PxBuffer * getSimVelocityInvMassCPU()
Access to the velocities of the simulation mesh on the host.
Definition NpSoftBody.h:138
virtual void addRigidFilter(PxRigidActor *actor, PxU32 vertId)
Creates a collision filter between a vertex in a soft body and a rigid body.
virtual void addTetRigidFilter(PxRigidActor *actor, PxU32 tetIdx)
Creates collision filter between a tetrahedron in a soft body and a rigid body.
virtual void removeParticleFilter(PxPBDParticleSystem *particlesystem, const PxParticleBuffer *buffer, PxU32 particleId, PxU32 tetId)
Removes a collision filter between a particle and a tetrahedron in the soft body's collision mesh.
const char * getName() const
Retrieves the name string set with setName().
virtual PxBuffer * getKinematicTargetCPU()
Access to the vertices of the simulation mesh on the host.
Definition NpSoftBody.h:139
virtual void setParameter(const PxFEMParameters paramters)
Set parameter for FEM internal solve.
virtual void removeRigidFilter(PxRigidActor *actor, PxU32 vertId)
Removes a collision filter between a vertex in a soft body and a rigid body.
virtual bool isSleeping() const
Returns true if this soft body is sleeping.
virtual PxSoftBodyFlags getSoftBodyFlag() const
Get the softbody flags.
virtual void removeSoftBodyAttachment(PxSoftBody *softbody0, PxU32 handle)
Releases an attachment between a soft body and the other soft body. Be aware that destroying the soft...
virtual PxU32 addTetRigidAttachment(PxRigidActor *actor, PxU32 tetIdx, const PxVec4 &barycentric, const PxVec3 &actorSpacePose, PxConeLimitedConstraint *constraint)
Creates a rigid attachment between a soft body and a rigid body. Be aware that destroying the rigid b...
virtual PxU32 addClothAttachment(PxFEMCloth *cloth, PxU32 triIdx, const PxVec4 &triBarycentric, PxU32 tetIdx, const PxVec4 &tetBarycentric, PxConeLimitedConstraint *constraint)
Creates an attachment between a soft body and a cloth. Be aware that destroying the rigid body before...
virtual void removeClothAttachment(PxFEMCloth *cloth, PxU32 handle)
Releases an attachment between a cloth and a soft body. Be aware that destroying the cloth before des...
virtual void release()
Releases the softbody.
virtual void readData(PxSoftBodyData::Enum flags, PxBuffer &buffer, bool flush)
Issues a read command to the PxSoftBody.
virtual PxShape * getShape()
Retrieves the shape pointer belonging to the actor.
virtual PxReal getWakeCounter() const
Returns the wake counter of the soft body.
virtual void addClothFilter(PxFEMCloth *cloth, PxU32 triIdx, PxU32 tetIdx)
Creates collision filter between a tetrahedron in a soft body and a triangle in a cloth.
virtual PxCudaContextManager * getCudaContextManager() const
Return the cuda context manager.
virtual PxBounds3 getWorldBounds(float inflation=1.01f) const
Retrieves the axis aligned bounding box enclosing the soft body.
virtual void detachShape()
Detaches the shape.
virtual PxSoftBodyAuxData * getSoftBodyAuxData()
Retrieves the simulation state pointer.
virtual void addSoftBodyFilters(PxSoftBody *softbody0, PxU32 *tetIndices0, PxU32 *tetIndices1, PxU32 tetIndicesSize)
Creates collision filters between a tetrahedron in a soft body with another soft body.
virtual void setSoftBodyFlags(PxSoftBodyFlags flags)
Set the softbody flags.
virtual void setWakeCounter(PxReal wakeCounterValue)
Sets the wake counter for the soft body.
void setName(const char *)
Sets a name string for the object that can be retrieved with getName().
virtual PxActorType::Enum getType() const
Retrieves the type of actor.
Definition NpSoftBody.h:53
virtual void writeData(PxSoftBodyData::Enum flags, bool flush)
Issues a write command to the PxSoftBody.
virtual PxU32 getGpuSoftBodyIndex()
Returns the GPU soft body index.
virtual void setSoftBodyFlag(PxSoftBodyFlag::Enum flag, bool val)
Set a single softbody flag.
virtual PxBuffer * getRestPositionInvMassCPU()
Access to the rest vertices of the collision mesh on the host.
Definition NpSoftBody.h:142
virtual PxTetrahedronMesh * getSimulationMesh()
Retrieves the simulation mesh pointer.
virtual void removeSoftBodyFilters(PxSoftBody *softbody0, PxU32 *tetIndices0, PxU32 *tetIndices1, PxU32 tetIndicesSize)
Removes collision filters between a tetrahedron in a soft body with another soft body.
virtual bool attachShape(PxShape &shape)
Attaches a shape.
virtual void addParticleFilter(PxPBDParticleSystem *particlesystem, const PxParticleBuffer *buffer, PxU32 particleId, PxU32 tetId)
Creates a collision filter between a particle and a tetrahedron in the soft body's collision mesh.
virtual void removeSoftBodyFilter(PxSoftBody *softbody0, PxU32 tetIdx0, PxU32 tetIdx1)
Removes collision filter between a tetrahedron in a soft body and a tetrahedron in other soft body.
virtual bool attachSimulationMesh(PxTetrahedronMesh &simulationMesh, PxSoftBodyAuxData &softBodyAuxData)
Attaches a simulation mesh.
virtual void writeData(PxSoftBodyData::Enum flags, PxBuffer &buffer, bool flush)
Issues a write command to the PxSoftBody.
virtual void addSoftBodyFilter(PxSoftBody *softbody0, PxU32 tetIdx0, PxU32 tetIdx1)
Creates collision filter between a tetrahedron in a soft body and a tetrahedron in another soft body.
virtual PxU32 addRigidAttachment(PxRigidActor *actor, PxU32 vertId, const PxVec3 &actorSpacePose, PxConeLimitedConstraint *constraint)
Creates a rigid attachment between a soft body and a rigid body. Be aware that destroying the rigid b...
virtual void setSolverIterationCounts(PxU32 minPositionIters, PxU32 minVelocityIters)
Sets the solver iteration counts for the body.
virtual void removeTetRigidFilter(PxRigidActor *actor, PxU32 tetIdx)
Removes collision filter between a tetrahedron in a soft body and a rigid body.
virtual PxBuffer * getPositionInvMassCPU()
Access to the vertices of the collision mesh on the host.
Definition NpSoftBody.h:141
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Buffer for delayed bulk read and write operations supporting host and GPU device memory spaces.
Definition PxBuffer.h:66
A particle system that uses the position based dynamics(PBD) solver.
Definition PxPBDParticleSystem.h:57
The shared base class for all particle buffers, can be instantiated directly to simulate granular and...
Definition PxParticleBuffer.h:81
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
Abstract class for collision shapes.
Definition PxShape.h:146
A data container providing mass, rest pose and other information required for softbody simulation.
Definition PxTetrahedronMesh.h:70
Represents a FEM softbody including everything to calculate its definition like geometry and material...
Definition PxSoftBody.h:104
A tetramedron mesh, also called a 'tetrahedron soup'.
Definition PxTetrahedronMesh.h:115
3 Element vector class.
Definition PxVec3.h:50
Definition PxVec4.h:50
Definition ScSoftBodyCore.h:53
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Enum
Definition PxActor.h:121
@ eSOFTBODY
A FEM-based soft body.
Definition PxActor.h:144
A constraint descriptor for limiting movement to a conical region.
Definition PxConeLimitedConstraint.h:48
Set of parameters to control the sleeping and collision behavior of FEM based objects.
Definition PxFEMParameter.h:45
Enum
Definition PxSoftBody.h:68
Enum
Definition PxSoftBody.h:88