RavEngine
Loading...
Searching...
No Matches
PxvNphaseImplementationContext.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 PXV_NPHASE_IMPLEMENTATION_CONTEXT_H
30#define PXV_NPHASE_IMPLEMENTATION_CONTEXT_H
31
32#include "PxSceneDesc.h"
33#include "PxsContactManagerState.h"
34#include "foundation/PxArray.h"
35#include "PxsNphaseCommon.h"
36
37// PT: TODO: forward decl don't work easily with templates, to revisit
38#include "PxsMaterialCore.h"
39#include "PxsFEMClothMaterialCore.h"
40#include "PxsFEMSoftBodyMaterialCore.h"
41#include "PxsFLIPMaterialCore.h"
42#include "PxsMPMMaterialCore.h"
43#include "PxsPBDMaterialCore.h"
44
45namespace physx
46{
47
48namespace IG
49{
50 class SimpleIslandManager;
51 class IslandSim;
52 typedef PxU32 EdgeIndex;
53}
54
55namespace Dy
56{
57 class Context;
58}
59
60namespace Cm
61{
62 class FanoutTask;
63}
64
65namespace Sc
66{
67 class ShapeInteraction;
68}
69
70class PxNodeIndex;
71class PxBaseTask;
72class PxsContext;
73struct PxsShapeCore;
74
75class PxsContactManager;
76struct PxsContactManagerOutput;
77struct PxsTorsionalFrictionData;
78
79
81{
82 PxU32 mOffsets[1<<PxsContactManagerBase::MaxBucketBits];
83 PxsContactManagerOutput* mOutputs;
84
85public:
86
87 PxsContactManagerOutputIterator() : mOutputs(NULL)
88 {
89 }
90
91 PxsContactManagerOutputIterator(PxU32* offsets, PxU32 nbOffsets, PxsContactManagerOutput* outputs) : mOutputs(outputs)
92 {
93 PX_ASSERT(nbOffsets <= (1<<PxsContactManagerBase::MaxBucketBits));
94
95 for(PxU32 a = 0; a < nbOffsets; ++a)
96 {
97 mOffsets[a] = offsets[a];
98 }
99 }
100
101 PX_FORCE_INLINE PxsContactManagerOutput& getContactManager(PxU32 id)
102 {
103 PX_ASSERT((id & PxsContactManagerBase::NEW_CONTACT_MANAGER_MASK) == 0);
104 PxU32 bucketId = PxsContactManagerBase::computeBucketIndexFromId(id);
105 PxU32 cmOutId = PxsContactManagerBase::computeIndexFromId(id);
106 return mOutputs[mOffsets[bucketId] + cmOutId];
107 }
108
109 PxU32 getIndex(PxU32 id)
110 {
111 PX_ASSERT((id & PxsContactManagerBase::NEW_CONTACT_MANAGER_MASK) == 0);
112 PxU32 bucketId = PxsContactManagerBase::computeBucketIndexFromId(id);
113 PxU32 cmOutId = PxsContactManagerBase::computeIndexFromId(id);
114 return mOffsets[bucketId] + cmOutId;
115 }
116};
117
118
120{
121 private:
123public:
124
127 virtual void destroy() = 0;
128 virtual void updateContactManager(PxReal dt, bool hasBoundsArrayChanged, bool hasContactDistanceChanged,
129 PxBaseTask* continuation, PxBaseTask* firstPassContinuation, Cm::FanoutTask* updateBoundAndShapeTask) = 0;
130 virtual void postBroadPhaseUpdateContactManager(PxBaseTask* continuation) = 0;
131 virtual void secondPassUpdateContactManager(PxReal dt, PxBaseTask* continuation) = 0;
132 virtual void fetchUpdateContactManager() = 0;
133
134 virtual void registerContactManager(PxsContactManager* cm, Sc::ShapeInteraction* interaction, PxI32 touching, PxU32 patchCount) = 0;
135// virtual void registerContactManagers(PxsContactManager** cm, Sc::ShapeInteraction** shapeInteractions, PxU32 nbContactManagers, PxU32 maxContactManagerId) = 0;
136 virtual void unregisterContactManager(PxsContactManager* cm) = 0;
137 virtual void refreshContactManager(PxsContactManager* cm) = 0;
138
139 virtual void registerShape(const PxNodeIndex& nodeIndex, const PxsShapeCore& shapeCore, const PxU32 transformCacheID, PxActor* actor, const bool isFemCloth = false) = 0;
140 virtual void unregisterShape(const PxsShapeCore& shapeCore, const PxU32 transformCacheID, const bool isFemCloth = false) = 0;
141
142 virtual void registerAggregate(const PxU32 transformCacheID) = 0;
143
144 virtual void registerMaterial(const PxsMaterialCore& materialCore) = 0;
145 virtual void updateMaterial(const PxsMaterialCore& materialCore) = 0;
146 virtual void unregisterMaterial(const PxsMaterialCore& materialCore) = 0;
147
148 virtual void registerMaterial(const PxsFEMSoftBodyMaterialCore& materialCore) = 0;
149 virtual void updateMaterial(const PxsFEMSoftBodyMaterialCore& materialCore) = 0;
150 virtual void unregisterMaterial(const PxsFEMSoftBodyMaterialCore& materialCore) = 0;
151
152 virtual void registerMaterial(const PxsFEMClothMaterialCore& materialCore) = 0;
153 virtual void updateMaterial(const PxsFEMClothMaterialCore& materialCore) = 0;
154 virtual void unregisterMaterial(const PxsFEMClothMaterialCore& materialCore) = 0;
155
156 virtual void registerMaterial(const PxsPBDMaterialCore& materialCore) = 0;
157 virtual void updateMaterial(const PxsPBDMaterialCore& materialCore) = 0;
158 virtual void unregisterMaterial(const PxsPBDMaterialCore& materialCore) = 0;
159
160 virtual void registerMaterial(const PxsFLIPMaterialCore& materialCore) = 0;
161 virtual void updateMaterial(const PxsFLIPMaterialCore& materialCore) = 0;
162 virtual void unregisterMaterial(const PxsFLIPMaterialCore& materialCore) = 0;
163
164 virtual void registerMaterial(const PxsMPMMaterialCore& materialCore) = 0;
165 virtual void updateMaterial(const PxsMPMMaterialCore& materialCore) = 0;
166 virtual void unregisterMaterial(const PxsMPMMaterialCore& materialCore) = 0;
167
168 virtual void registerMaterial(const PxsCustomMaterialCore& materialCore) = 0;
169 virtual void updateMaterial(const PxsCustomMaterialCore& materialCore) = 0;
170 virtual void unregisterMaterial(const PxsCustomMaterialCore& materialCore) = 0;
171
172 virtual void updateShapeMaterial(const PxsShapeCore& shapeCore) = 0;
173
174
175 virtual void startNarrowPhaseTasks() = 0;
176
177 virtual void appendContactManagers() = 0;
178
179 virtual PxsContactManagerOutput& getNewContactManagerOutput(PxU32 index) = 0;
180
181 virtual PxsContactManagerOutputIterator getContactManagerOutputs() = 0;
182
183 virtual void setContactModifyCallback(PxContactModifyCallback* callback) = 0;
184
185 virtual void acquireContext() = 0;
186 virtual void releaseContext() = 0;
187 virtual void preallocateNewBuffers(PxU32 nbNewPairs, PxU32 maxIndex) = 0;
188
189 virtual void lock() = 0;
190 virtual void unlock() = 0;
191
192 virtual PxsContactManagerOutputCounts* getFoundPatchOutputCounts() = 0;
193 virtual PxsContactManager** getFoundPatchManagers() = 0;
194 virtual PxU32 getNbFoundPatchManagers() = 0;
195
196
197 //GPU-specific buffers. Return null for CPU narrow phase
198
199 virtual PxsContactManagerOutput* getGPUContactManagerOutputBase() = 0;
200 virtual PxReal* getGPURestDistances() = 0;
201 virtual Sc::ShapeInteraction** getGPUShapeInteractions() = 0;
202 virtual PxsTorsionalFrictionData* getGPUTorsionalData() = 0;
203
204 virtual void waitForContactsReady() {}
205
206protected:
207
208 PxsContext& mContext;
209};
210
212{
213 private:
215public:
216
219 virtual void processContactManager(PxReal dt, PxsContactManagerOutput* cmOutputs, PxBaseTask* continuation) = 0;
220 virtual void processContactManagerSecondPass(PxReal dt, PxBaseTask* continuation) = 0;
221
222 virtual void registerContactManager(PxsContactManager* cm, Sc::ShapeInteraction* shapeInteraction, PxI32 touching, PxU32 numPatches) = 0;
223 virtual void unregisterContactManagerFallback(PxsContactManager* cm, PxsContactManagerOutput* cmOutputs) = 0;
224
225 virtual void refreshContactManagerFallback(PxsContactManager* cm, PxsContactManagerOutput* cmOutputs) = 0;
226
227 virtual PxsContactManagerOutput& getNewContactManagerOutput(PxU32 npId) = 0;
228
229 virtual void appendContactManagersFallback(PxsContactManagerOutput* outputs) = 0;
230
231 virtual void setContactModifyCallback(PxContactModifyCallback* callback) = 0;
232
233 virtual void removeContactManagersFallback(PxsContactManagerOutput* cmOutputs) = 0;
234
235 virtual void lock() = 0;
236 virtual void unlock() = 0;
237
238 virtual PxsContactManagerOutputCounts* getFoundPatchOutputCounts() = 0;
239 virtual PxsContactManager** getFoundPatchManagers() = 0;
240 virtual PxU32 getNbFoundPatchManagers() = 0;
241
242 virtual Sc::ShapeInteraction** getShapeInteractions() = 0;
243 virtual PxReal* getRestDistances() = 0;
244 virtual PxsTorsionalFrictionData* getTorsionalData() = 0;
245
246};
247
256
257PxvNphaseImplementationContextUsableAsFallback* createNphaseImplementationContext(PxsContext& context, IG::IslandSim* islandSim, PxVirtualAllocatorCallback* allocator);
258
259}
260
261#endif
Definition base.h:1940
A task that maintains a list of dependent tasks.
Definition CmTask.h:132
Definition PxsIslandSim.h:412
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Base class of all task types.
Definition PxTask.h:45
An interface class that the user can implement in order to modify contact constraints.
Definition PxContactModifyCallback.h:459
PxNodeIndex.
Definition PxNodeIndex.h:51
Definition PxAllocator.h:140
Definition PxvNphaseImplementationContext.h:81
Definition PxsContactManager.h:77
Definition PxsContext.h:92
Definition PxvNphaseImplementationContext.h:249
Definition PxvNphaseImplementationContext.h:120
Definition PxvNphaseImplementationContext.h:212
Definition ScShapeInteraction.h:54
#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 PxvGeometry.h:221