1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved.
#ifndef NVBLASTEXTPXMANAGER_H
#define NVBLASTEXTPXMANAGER_H
#include "NvBlastTypes.h"
#include "PxConvexMeshGeometry.h"
#include "PxTransform.h"
#include "NvPreprocessor.h"
// Forward declarations
namespace physx
{
class PxPhysics;
class PxCooking;
class PxRigidDynamic;
class PxJoint;
namespace general_PxIOStream2
{
class PxFileBuf;
}
} // namespace physx
namespace Nv
{
namespace Blast
{
// Forward declarations
class ExtPxActor;
class ExtPxAsset;
class ExtPxFamily;
class ExtPxListener;
class TkFamily;
class TkFramework;
class TkGroup;
class TkJoint;
class ExtPxCollisionBuilder;
/**
Family Desc.
Used to create Physics Family.
*/
struct ExtPxFamilyDesc
{
ExtPxAsset* pxAsset; //!< px asset to create from, pointer will be stored in family.
const NvBlastActorDesc* actorDesc; //!< actor descriptor to be used when creating TkActor. If nullptr, default
//!< NvBlastActorDesc from ExtPxAsset will be used.
TkGroup* group; //!< if not nullptr, created TkActor will be placed in group
};
/**
Function pointer for PxJoint creation.
It will be called when new joints are being created. It should return valid PxJoint pointer or nullptr.
*/
typedef physx::PxJoint* (*ExtPxCreateJointFunction)(ExtPxActor* actor0, const physx::PxTransform& localFrame0,
ExtPxActor* actor1, const physx::PxTransform& localFrame1,
physx::PxPhysics& physics, TkJoint& joint);
/**
Physics Manager.
Used to create and manage Physics Families.
*/
class NV_DLL_EXPORT ExtPxManager
{
public:
//////// manager creation ////////
/**
Create a new ExtPxManager.
\param[in] physics The PxPhysics instance to be used by ExtPxManager.
\param[in] framework The TkFramework instance to be used by ExtPxManager.
\param[in] cooking The optional PxCooking. Required for collision builder.
\param[in] createFn The function to be used when creating joints, can be nullptr.
\param[in] useUserData Flag if ExtPxManager is allowed to override PxActor's userData, it will store pointer to
PxActor there. It is recommended as fastest way. If set to 'false' HashMap will be used.
\return the new ExtPxManager if successful, NULL otherwise.
*/
static ExtPxManager* create(physx::PxPhysics& physics, TkFramework& framework,
ExtPxCreateJointFunction createFn = nullptr, bool useUserData = true);
/**
Create PhysX based convex mesh builder.
*/
static ExtPxCollisionBuilder* createCollisionBuilder(physx::PxPhysics& physics, physx::PxCooking& cooking);
/**
Release this manager.
*/
virtual void release() = 0;
//////// impact ////////
/**
Simulation Filter data to be set on leaf chunk actors
*/
enum FilterDataAttributes
{
LEAF_CHUNK = 1,
};
//////// interface ////////
/**
Create a px family from the given descriptor.
\param[in] desc The family descriptor (see ExtPxFamilyDesc).
\return the created family, if the descriptor was valid and memory was available for the operation. Otherwise,
returns NULL.
*/
virtual ExtPxFamily* createFamily(const ExtPxFamilyDesc& desc) = 0;
/**
Create a px joint associated with TkJoint.
ExtPxCreateJointFunction will be called after this call.
ExtPxCreateJointFunction must be set, nothing will happen otherwise.
\param[in] joint TkJoint to be used to create px joint.
\return true iff Joint was created.
*/
virtual bool createJoint(TkJoint& joint) = 0;
/**
Destroy a px joint associated with TkJoint.
\param[in] joint TkJoint to be used to destroy px joint.
*/
virtual void destroyJoint(TkJoint& joint) = 0;
/**
Set ExtPxCreateJointFunction to be used when new joints are being created.\
\param[in] createFn Create function pointer to set, can be nullptr.
*/
virtual void setCreateJointFunction(ExtPxCreateJointFunction createFn) = 0;
/**
The number of families currently in this manager.
\return the number of ExtPxFamily that currently exist in this manger.
*/
virtual uint32_t getFamilyCount() const = 0;
/**
Retrieve an array of pointers (into the user-supplied buffer) to families.
\param[out] buffer A user-supplied array of ExtPxFamily pointers.
\param[in] bufferSize The number of elements available to write into buffer.
\return the number of ExtPxFamily pointers written to the buffer.
*/
virtual uint32_t getFamilies(ExtPxFamily** buffer, uint32_t bufferSize) const = 0;
/**
Look up an associated ExtPxFamily by TkFamily pointer.
\param[in] family The TkFamily pointer to look up.
\return pointer to the ExtPxFamily object if it exists, NULL otherwise.
*/
virtual ExtPxFamily* getFamilyFromTkFamily(TkFamily& family) const = 0;
/**
Look up an associated ExtPxActor by PxRigidDynamic pointer.
\param[in] pxActor The PxRigidDynamic pointer to look up.
\return pointer to the ExtPxActor object if it exists, NULL otherwise.
*/
virtual ExtPxActor* getActorFromPhysXActor(const physx::PxRigidDynamic& pxActor) const = 0;
/**
Get a PxPhysics object pointer used upon manager creation.
\return a pointer to the (const) PxPhysics object.
*/
virtual physx::PxPhysics& getPhysics() const = 0;
/**
Get a TkFramework object pointer used upon manager creation.
\return a pointer to the TkFramework object.
*/
virtual TkFramework& getFramework() const = 0;
/**
Get if useUserData was set upon manager creation.
\return true iff PxActor userData is used by manager.
*/
virtual bool isPxUserDataUsed() const = 0;
/**
Limits the total number of actors that can exist at a given time. A value of zero disables this (gives no limit).
\param[in] limit If not zero, the maximum number of actors that will be allowed to exist.
*/
virtual void setActorCountLimit(uint32_t limit) = 0;
/**
Retrieve the limit to the total number of actors that can exist at a given time. A value of zero disables this
(gives no limit).
\return the limit to the total number of actors that can exist at a given time (or zero if there is no limit).
*/
virtual uint32_t getActorCountLimit() = 0;
/**
The total number of PxActors generated by Blast.
\return the total number of PxActors generated by Blast.
*/
virtual uint32_t getPxActorCount() const = 0;
/**
Add a user implementation of ExtPxListener to this family's list of listeners.
\param[in] listener The event listener to add.
*/
virtual void subscribe(ExtPxListener& listener) = 0;
/**
Remove a user implementation of ExtPxListener from this family's list of listeners.
\param[in] listener The event listener to remove.
*/
virtual void unsubscribe(ExtPxListener& listener) = 0;
};
} // namespace Blast
} // namespace Nv
#endif // ifndef NVBLASTEXTPXMANAGER_H
|