RavEngine
Loading...
Searching...
No Matches
DySoftBody.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_SOFTBODY_H
28#define DY_SOFTBODY_H
29
30#include "foundation/PxSimpleTypes.h"
31#include "foundation/PxPinnedArray.h"
32#include "DySoftBodyCore.h"
33#include "PxvGeometry.h"
34
35namespace physx
36{
37 namespace Sc
38 {
39 class SoftBodySim;
40 }
41
42 namespace Dy
43 {
44
45 typedef size_t SoftBodyHandle;
46
47 struct SoftBodyCore;
48
49 typedef PxPinnedArray<PxU64> SoftBodyFilterArray;
50
52 {
53 PX_NOCOPY(SoftBody)
54 public:
56 mSoftBodySoftBodyFilterPairs(NULL), mSim(sim), mCore(core), mElementId(0xffffffff), mGpuRemapId(0xffffffff)
57 {
58 mFilterDirty = false;
59 mFilterInDirtyList = false;
60 mDirtySoftBodyForFilterPairs = NULL;
61 mSoftBodySoftBodyFilterPairs = NULL;
62 }
63
64 ~SoftBody()
65 {
66 if (mDirtySoftBodyForFilterPairs)
67 {
68 Dy::SoftBody** dirtySoftBodies = mDirtySoftBodyForFilterPairs->begin();
69
70 const PxU32 size = mDirtySoftBodyForFilterPairs->size();
71
72 for (PxU32 i = 0; i < size; ++i)
73 {
74 if (dirtySoftBodies[i] == this)
75 {
76 dirtySoftBodies[i] = NULL;
77 }
78 }
79
80 if (mSoftBodySoftBodyFilterPairs)
81 PX_FREE(mSoftBodySoftBodyFilterPairs);
82 }
83 }
84
85 PX_FORCE_INLINE PxReal getMaxPenetrationBias() const { return mCore.maxPenBias; }
86
87 PX_FORCE_INLINE Sc::SoftBodySim* getSoftBodySim() const { return mSim; }
88
89 PX_FORCE_INLINE void setGpuRemapId(const PxU32 remapId)
90 {
91 mGpuRemapId = remapId;
92 PxTetrahedronMeshGeometryLL& geom = mShapeCore->mGeometry.get<PxTetrahedronMeshGeometryLL>();
93 geom.materialsLL.gpuRemapId = remapId;
94 }
95
96 PX_FORCE_INLINE PxU32 getGpuRemapId() { return mGpuRemapId; }
97
98 PX_FORCE_INLINE void setElementId(const PxU32 elementId) { mElementId = elementId; }
99 PX_FORCE_INLINE PxU32 getElementId() { return mElementId; }
100
101 PX_FORCE_INLINE PxsShapeCore& getShapeCore() { return *mShapeCore; }
102 PX_FORCE_INLINE void setShapeCore(PxsShapeCore* shapeCore) { mShapeCore = shapeCore; }
103
104 PX_FORCE_INLINE void setSimShapeCore(PxTetrahedronMesh* simulationMesh, PxSoftBodyAuxData* simulationState)
105 {
106 mSimulationMesh = simulationMesh;
107 mSoftBodyAuxData = simulationState;
108 }
109
110 PX_FORCE_INLINE const PxTetrahedronMesh* getCollisionMesh() const { return mShapeCore->mGeometry.get<PxTetrahedronMeshGeometryLL>().tetrahedronMesh; }
111 PX_FORCE_INLINE PxTetrahedronMesh* getCollisionMesh() { return mShapeCore->mGeometry.get<PxTetrahedronMeshGeometryLL>().tetrahedronMesh; }
112
113 PX_FORCE_INLINE const PxTetrahedronMesh* getSimulationMesh() const { return mSimulationMesh; }
114 PX_FORCE_INLINE PxTetrahedronMesh* getSimulationMesh() { return mSimulationMesh; }
115
116 PX_FORCE_INLINE const PxSoftBodyAuxData* getSoftBodyAuxData() const { return mSoftBodyAuxData; }
117 PX_FORCE_INLINE PxSoftBodyAuxData* getSoftBodyAuxData() { return mSoftBodyAuxData; }
118
119
120 PX_FORCE_INLINE const SoftBodyCore& getCore() const { return mCore; }
121 PX_FORCE_INLINE SoftBodyCore& getCore() { return mCore; }
122
123 PX_FORCE_INLINE PxU16 getIterationCounts() { return mCore.solverIterationCounts; }
124
125 PX_FORCE_INLINE PxU32 getGpuSoftBodyIndex() { return mGpuRemapId; }
126
127 //These variables are used in the constraint partition
128 PxU16 maxSolverFrictionProgress;
129 PxU16 maxSolverNormalProgress;
130 PxU32 solverProgress;
131 PxU8 numTotalConstraints;
132
133 PxArray<PxU32> mParticleSoftBodyAttachments;
134 PxArray<PxU32> mRigidSoftBodyAttachments;
135 PxArray<PxU32> mClothSoftBodyAttachments;
136 PxArray<PxU32> mSoftSoftBodyAttachments;
137
138 SoftBodyFilterArray* mSoftBodySoftBodyFilterPairs;
139 PxArray <Dy::SoftBody*>* mDirtySoftBodyForFilterPairs; //pointer to the array of mDirtySoftBodyForFilterPairs in PxgSimulationController.cpp
140
141 PxArray<PxU32> mSoftBodyClothAttachmentIdReferences;
142 bool mFilterDirty;
143 bool mFilterInDirtyList;
144
145
146 private:
147 Sc::SoftBodySim* mSim;
148 SoftBodyCore& mCore;
149 PxsShapeCore* mShapeCore;
150
151 PxTetrahedronMesh* mSimulationMesh;
152 PxSoftBodyAuxData* mSoftBodyAuxData;
153
154 PxU32 mElementId; //this is used for the bound array, contactDist
155 PxU32 mGpuRemapId;
156 };
157
158 PX_FORCE_INLINE SoftBody* getSoftBody(SoftBodyHandle handle)
159 {
160 return reinterpret_cast<SoftBody*>(handle);
161 }
162
163 }
164}
165
166#endif
Definition DySoftBody.h:52
Definition PxArray.h:53
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
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
Definition DySoftBodyCore.h:41
Definition PxvGeometry.h:125
Definition PxvGeometry.h:221