RavEngine
Loading...
Searching...
No Matches
ScSoftBodyCore.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 SC_SOFT_BODY_CORE_H
30#define SC_SOFT_BODY_CORE_H
31
32#include "PxSoftBody.h"
33#include "DySoftBodyCore.h"
34#include "foundation/PxAssert.h"
35#include "ScActorCore.h"
36#include "ScShapeCore.h"
37#include "PxFiltering.h"
38#include "ScRigidCore.h" //KS - needed for ShapeChangeNotifyFlags. Move to a shared header
39
40
41namespace physx
42{
43
44
45 namespace Sc
46 {
47 class SoftBodySim;
48 class BodyCore;
49 class FEMClothCore;
50 class ParticleSystemCore;
51
52 class SoftBodyCore : public ActorCore
53 {
54 //= ATTENTION! =====================================================================================
55 // Changing the data layout of this class breaks the binary serialization format. See comments for
56 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
57 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
58 // accordingly.
59 //==================================================================================================
60
61 //---------------------------------------------------------------------------------
62 // Construction, destruction & initialization
63 //---------------------------------------------------------------------------------
64
65 // PX_SERIALIZATION
66 public:
67 SoftBodyCore(const PxEMPTY) : ActorCore(PxEmpty){}
68 static void getBinaryMetaData(PxOutputStream& stream);
69 //~PX_SERIALIZATION
72
73 //---------------------------------------------------------------------------------
74 // External API
75 //---------------------------------------------------------------------------------
76
77 void setMaterial(const PxU16 handle);
78 void clearMaterials();
79
80
81 PxFEMParameters getParameter() const;
82 void setParameter(const PxFEMParameters paramters);
83
84
85 PxReal getSleepThreshold() const;
86 void setSleepThreshold(const PxReal v);
87
88 PxReal getFreezeThreshold() const;
89 void setFreezeThreshold(const PxReal v);
90
91 PxU16 getSolverIterationCounts() const { return mCore.solverIterationCounts; }
92 void setSolverIterationCounts(PxU16 c);
93
94 PxReal getWakeCounter() const;
95 void setWakeCounter(const PxReal v);
96 void setWakeCounterInternal(const PxReal v);
97
98 bool isSleeping() const;
99 void wakeUp(PxReal wakeCounter);
100 void putToSleep();
101
102 PxActor* getPxActor() const;
103
104 void attachShapeCore(ShapeCore* shapeCore);
105 void attachSimulationMesh(PxTetrahedronMesh* simulationMesh, PxSoftBodyAuxData* simulationState);
106
107 void addParticleFilter(Sc::ParticleSystemCore* core, PxU32 particleId, PxU32 userBufferId, PxU32 tetId);
108 void removeParticleFilter(Sc::ParticleSystemCore* core, PxU32 particleId, PxU32 userBufferId, PxU32 tetId);
109
110 PxU32 addParticleAttachment(Sc::ParticleSystemCore* core, PxU32 particleId, PxU32 userBufferId, PxU32 tetId, const PxVec4& barycentric);
111 void removeParticleAttachment(Sc::ParticleSystemCore* core, PxU32 handle);
112
113 void addRigidFilter(Sc::BodyCore* core, PxU32 vertId);
114 void removeRigidFilter(Sc::BodyCore* core, PxU32 vertId);
115
116 PxU32 addRigidAttachment(Sc::BodyCore* core, PxU32 vertId, const PxVec3& actorSpacePose, PxConeLimitedConstraint* constraint);
117 void removeRigidAttachment(Sc::BodyCore* core, PxU32 handle);
118
119
120 void addTetRigidFilter(Sc::BodyCore* core, PxU32 tetIdx);
121 void removeTetRigidFilter(Sc::BodyCore* core, PxU32 tetIdx);
122
123 PxU32 addTetRigidAttachment(Sc::BodyCore* core, PxU32 tetIdx, const PxVec4& barycentric, const PxVec3& actorSpacePose,
124 PxConeLimitedConstraint* constraint);
125
126 void addSoftBodyFilter(Sc::SoftBodyCore& core, PxU32 tetIdx0, PxU32 tetIdx1);
127 void removeSoftBodyFilter(Sc::SoftBodyCore& core, PxU32 tetIdx0, PxU32 tetIdx1);
128 void addSoftBodyFilters(Sc::SoftBodyCore& core, PxU32* tetIndices0, PxU32* tetIndices1, PxU32 tetIndicesSize);
129 void removeSoftBodyFilters(Sc::SoftBodyCore& core, PxU32* tetIndices0, PxU32* tetIndices1, PxU32 tetIndicesSize);
130
131 PxU32 addSoftBodyAttachment(Sc::SoftBodyCore& core, PxU32 tetIdx0, const PxVec4& triBarycentric0, PxU32 tetIdx1, const PxVec4& tetBarycentric1,
132 PxConeLimitedConstraint* constraint);
133 void removeSoftBodyAttachment(Sc::SoftBodyCore& core, PxU32 handle);
134
135 void addClothFilter(Sc::FEMClothCore& core, PxU32 triIdx, PxU32 tetIdx);
136 void removeClothFilter(Sc::FEMClothCore& core, PxU32 triIdx, PxU32 tetIdx);
137
138 PxU32 addClothAttachment(Sc::FEMClothCore& core, PxU32 triIdx, const PxVec4& triBarycentric, PxU32 tetIdx, const PxVec4& tetBarycentric, PxConeLimitedConstraint* constraint);
139 void removeClothAttachment(Sc::FEMClothCore& core, PxU32 handle);
140
141 PxU32 getGpuSoftBodyIndex();
142 //---------------------------------------------------------------------------------
143 // Internal API
144 //---------------------------------------------------------------------------------
145 public:
146
147 SoftBodySim* getSim() const;
148
149 PX_FORCE_INLINE const Dy::SoftBodyCore& getCore() const { return mCore; }
150
151 PX_FORCE_INLINE Dy::SoftBodyCore& getCore() { return mCore; }
152
153 static PX_FORCE_INLINE SoftBodyCore& getSoftBodyCore(SoftBodyCore& core)
154 {
155 size_t offset = PX_OFFSET_OF_RT(SoftBodyCore, mCore);
156 return *reinterpret_cast<SoftBodyCore*>(reinterpret_cast<PxU8*>(&core) - offset);
157 }
158
159 void setSimulationFilterData(const PxFilterData& data);
160
161 PxFilterData getSimulationFilterData() const;
162
163 PxSoftBodyFlags getFlags() const { return mCore.mFlags; }
164
165 void setFlags(PxSoftBodyFlags flags);
166
167 PX_FORCE_INLINE PxReal getMaxPenetrationBias() const { return mCore.maxPenBias; }
168 PX_FORCE_INLINE void setMaxPenetrationBias(PxReal p) { mCore.maxPenBias = p; }
169
170 PX_FORCE_INLINE PxU64& getGpuMemStat() { return mGpuMemStat; }
171
172 void onShapeChange(ShapeCore& shape, ShapeChangeNotifyFlags notifyFlags);
173
174 private:
175 Dy::SoftBodyCore mCore;
176 PxFilterData mFilterData;
177 PxU64 mGpuMemStat;
178
179
180 };
181
182
183
184 } // namespace Sc
185
186}
187
188#endif
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Output stream class for I/O.
Definition PxIO.h:114
A data container providing mass, rest pose and other information required for softbody simulation.
Definition PxTetrahedronMesh.h:70
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 ScActorCore.h:48
Definition ScBodyCore.h:49
Definition ScFEMClothCore.h:54
Definition ScParticleSystemCore.h:51
Definition ScShapeCore.h:46
Definition ScSoftBodyCore.h:53
Definition ScSoftBodySim.h:42
#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
PxEMPTY
Definition Px.h:87
Definition DySoftBodyCore.h:41
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
PxFilterData is user-definable data which gets passed into the collision filtering shader and/or call...
Definition PxFiltering.h:365