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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_IMMEDIATE_MODE
#define PX_PHYSICS_IMMEDIATE_MODE
/** \addtogroup immediatemode
@{ */
#include "PxPhysXConfig.h"
#include "solver/PxSolverDefs.h"
#include "collision/PxCollisionDefs.h"
#include "PxArticulationReducedCoordinate.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
#if !PX_DOXYGEN
namespace immediate
{
#endif
/**
\brief Structure to store rigid body properties
*/
struct PxRigidBodyData
{
PX_ALIGN(16, PxVec3 linearVelocity); //!< 12 Linear velocity
PxReal invMass; //!< 16 Inverse mass
PxVec3 angularVelocity; //!< 28 Angular velocity
PxReal maxDepenetrationVelocity; //!< 32 Maximum de-penetration velocity
PxVec3 invInertia; //!< 44 Mass-space inverse interia diagonal vector
PxReal maxContactImpulse; //!< 48 Maximum permissable contact impulse
PxTransform body2World; //!< 76 World space transform
PxReal linearDamping; //!< 80 Linear damping coefficient
PxReal angularDamping; //!< 84 Angular damping coefficient
PxReal maxLinearVelocitySq; //!< 88 Squared maximum linear velocity
PxReal maxAngularVelocitySq; //!< 92 Squared maximum angular velocity
PxU32 pad; //!< 96 Padding for 16-byte alignment
};
/**
\brief Callback class to record contact points produced by immediate::PxGenerateContacts
*/
class PxContactRecorder
{
public:
/**
\brief Method to record new contacts
\param [in] contactPoints The contact points produced
\param [in] nbContacts The number of contact points produced
\param [in] index The index of this pair. This is an index from 0-N-1 identifying which pair this relates to from within the array of pairs passed to PxGenerateContacts
\return a boolean to indicate if this callback successfully stored the contacts or not.
*/
virtual bool recordContacts(const Gu::ContactPoint* contactPoints, const PxU32 nbContacts, const PxU32 index) = 0;
virtual ~PxContactRecorder(){}
};
/**
\brief Constructs a PxSolverBodyData structure based on rigid body properties. Applies gravity, damping and clamps maximum velocity.
\param [in] inRigidData The array rigid body properties
\param [out] outSolverBodyData The array of solverBodyData produced to repreent these bodies
\param [in] nbBodies The total number of solver bodies to create
\param [in] gravity The gravity vector
\param [in] dt The timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructSolverBodies(const PxRigidBodyData* inRigidData, PxSolverBodyData* outSolverBodyData, const PxU32 nbBodies, const PxVec3& gravity, const PxReal dt);
/**
\brief Constructs a PxSolverBodyData structure for a static body at a given pose.
\param [in] globalPose The pose of this static actor
\param [out] solverBodyData The solver body representation of this static actor
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructStaticSolverBody(const PxTransform& globalPose, PxSolverBodyData& solverBodyData);
/**
\brief Groups together sets of independent PxSolverConstraintDesc objects to be solved using SIMD SOA approach.
\param [in] solverConstraintDescs The set of solver constraint descs to batch
\param [in] nbConstraints The number of constraints to batch
\param [in,out] solverBodies The array of solver bodies that the constraints reference. Some fields in these structures are written to as scratch memory for the batching.
\param [in] nbBodies The number of bodies
\param [out] outBatchHeaders The batch headers produced by this batching process. This array must have at least 1 entry per input constraint
\param [out] outOrderedConstraintDescs A reordered copy of the constraint descs. This array is referenced by the constraint batches. This array must have at least 1 entry per input constraint.
\param [in,out] articulations The array of articulations that the constraints reference. Some fields in these structures are written to as scratch memory for the batching.
\param [in] nbArticulations The number of articulations
\return The total number of batches produced. This should be less than or equal to nbConstraints.
\note This method considers all bodies within the range [0, nbBodies-1] to be valid dynamic bodies. A given dynamic body can only be referenced in a batch once. Static or kinematic bodies can be
referenced multiple times within a batch safely because constraints do not affect their velocities. The batching will implicitly consider any bodies outside of the range [0, nbBodies-1] to be
infinite mass (static or kinematic). This means that either appending static/kinematic to the end of the array of bodies or placing static/kinematic bodies at before the start body pointer
will ensure that the minimum number of batches are produced.
*/
PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxBatchConstraints( const PxSolverConstraintDesc* solverConstraintDescs, const PxU32 nbConstraints, PxSolverBody* solverBodies, const PxU32 nbBodies,
PxConstraintBatchHeader* outBatchHeaders, PxSolverConstraintDesc* outOrderedConstraintDescs,
Dy::ArticulationV** articulations=NULL, const PxU32 nbArticulations=0);
/**
\brief Creates a set of contact constraint blocks. Note that, depending the results of PxBatchConstraints, each batchHeader may refer to up to 4 solverConstraintDescs.
This function will allocate both constraint and friction patch data via the PxConstraintAllocator provided. Constraint data is only valid until PxSolveConstraints has completed.
Friction data is to be retained and provided by the application for friction correlation.
\param [in] batchHeaders Array of batch headers to process
\param [in] nbHeaders The total number of headers
\param [in] contactDescs An array of contact descs defining the pair and contact properties of each respective contacting pair
\param [in] allocator An allocator callback to allocate constraint and friction memory
\param [in] invDt The inverse timestep
\param [in] bounceThreshold The bounce threshold. Relative velocities below this will be solved by bias only. Relative velocities above this will be solved by restitution. If restitution is zero
then these pairs will always be solved by bias.
\param [in] frictionOffsetThreshold The friction offset threshold. Contacts whose separations are below this threshold can generate friction constraints.
\param [in] correlationDistance The correlation distance used by friction correlation to identify whether a friction patch is broken on the grounds of relation separation.
\return a boolean to define if this method was successful or not.
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateContactConstraints(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxSolverContactDesc* contactDescs,
PxConstraintAllocator& allocator, const PxReal invDt, const PxReal bounceThreshold, const PxReal frictionOffsetThreshold, const PxReal correlationDistance);
/**
\brief Creates a set of joint constraint blocks. Note that, depending the results of PxBatchConstraints, the batchHeader may refer to up to 4 solverConstraintDescs
\param [in] batchHeaders The array of batch headers to be processed
\param [in] nbHeaders The total number of batch headers to process
\param [in] jointDescs An array of constraint prep descs defining the properties of the constraints being created
\param [in] allocator An allocator callback to allocate constraint data
\param [in] dt The timestep
\param [in] invDt The inverse timestep
\return a boolean indicating if this method was successful or not.
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraints(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal invDt);
/**
\brief Creates a set of joint constraint blocks. This function runs joint shaders defined inside PxConstraint** param, fills in joint row information in jointDescs and then calls PxCreateJointConstraints.
\param [in] batchHeaders The set of batchHeaders to be processed
\param [in] nbBatchHeaders The number of batch headers to process.
\param [in] constraints The set of constraints to be used to produce constraint rows
\param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
\param [in] allocator An allocator callback to allocate constraint data
\param [in] dt The timestep
\param [in] invDt The inverse timestep
\return a boolean indicating if this method was successful or not.
@see PxCreateJointConstraints
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithShaders(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxConstraint** constraints, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal invDt);
struct PxImmediateConstraint
{
PxConstraintSolverPrep prep;
const void* constantBlock;
};
/**
\brief Creates a set of joint constraint blocks. This function runs joint shaders defined inside PxImmediateConstraint* param, fills in joint row information in jointDescs and then calls PxCreateJointConstraints.
\param [in] batchHeaders The set of batchHeaders to be processed
\param [in] nbBatchHeaders The number of batch headers to process.
\param [in] constraints The set of constraints to be used to produce constraint rows
\param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
\param [in] allocator An allocator callback to allocate constraint data
\param [in] dt The timestep
\param [in] invDt The inverse timestep
\return a boolean indicating if this method was successful or not.
@see PxCreateJointConstraints
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithImmediateShaders(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxImmediateConstraint* constraints, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal invDt);
/**
\brief Iteratively solves the set of constraints defined by the provided PxConstraintBatchHeader and PxSolverConstraintDesc structures. Updates deltaVelocities inside the PxSolverBody structures. Produces resulting linear and angular motion velocities.
\param [in] batchHeaders The set of batch headers to be solved
\param [in] nbBatchHeaders The total number of batch headers to be solved
\param [in] solverConstraintDescs The reordererd set of solver constraint descs referenced by the batch headers
\param [in,out] solverBodies The set of solver bodies the bodies reference
\param [out] linearMotionVelocity The resulting linear motion velocity
\param [out] angularMotionVelocity The resulting angular motion velocity.
\param [in] nbSolverBodies The total number of solver bodies
\param [in] nbPositionIterations The number of position iterations to run
\param [in] nbVelocityIterations The number of velocity iterations to run
\param [in] dt Timestep. Only needed if articulations are sent to the function.
\param [in] invDt Inverse timestep. Only needed if articulations are sent to the function.
\param [in] nbSolverArticulations Number of articulations to solve constraints for.
\param [in] solverArticulations Array of articulations to solve constraints for.
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxSolveConstraints(const PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, const PxSolverConstraintDesc* solverConstraintDescs,
const PxSolverBody* solverBodies, PxVec3* linearMotionVelocity, PxVec3* angularMotionVelocity, const PxU32 nbSolverBodies, const PxU32 nbPositionIterations, const PxU32 nbVelocityIterations,
const float dt=0.0f, const float invDt=0.0f, const PxU32 nbSolverArticulations=0, Dy::ArticulationV** solverArticulations=NULL);
/**
\brief Integrates a rigid body, returning the new velocities and transforms. After this function has been called, solverBodyData stores all the body's velocity data.
\param [in,out] solverBodyData The array of solver body data to be integrated
\param [in] solverBody The bodies' linear and angular velocities
\param [in] linearMotionVelocity The bodies' linear motion velocity array
\param [in] angularMotionState The bodies' angular motion velocity array
\param [in] nbBodiesToIntegrate The total number of bodies to integrate
\param [in] dt The timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxIntegrateSolverBodies(PxSolverBodyData* solverBodyData, PxSolverBody* solverBody, const PxVec3* linearMotionVelocity, const PxVec3* angularMotionState, const PxU32 nbBodiesToIntegrate, const PxReal dt);
/**
\brief Performs contact generation for a given pair of geometries at the specified poses. Produced contacts are stored in the provided Gu::ContactBuffer. Information is cached in PxCache structure
to accelerate future contact generation between pairs. This cache data is valid only as long as the memory provided by PxCacheAllocator has not been released/re-used. Recommendation is to
retain that data for a single simulation frame, discarding cached data after 2 frames. If the cached memory has been released/re-used prior to the corresponding pair having contact generation
performed again, it is the application's responsibility to reset the PxCache.
\param [in] geom0 Array of geometries to perform collision detection on.
\param [in] geom1 Array of geometries to perform collision detection on
\param [in] pose0 Array of poses associated with the corresponding entry in the geom0 array
\param [in] pose1 Array of poses associated with the corresponding entry in the geom1 array
\param [in,out] contactCache Array of contact caches associated with each pair geom0[i] + geom1[i]
\param [in] nbPairs The total number of pairs to process
\param [in] contactRecorder A callback that is called to record contacts for each pair that detects contacts
\param [in] contactDistance The distance at which contacts begin to be generated between the pairs
\param [in] meshContactMargin The mesh contact margin.
\param [in] toleranceLength The toleranceLength. Used for scaling distance-based thresholds internally to produce appropriate results given simulations in different units
\param [in] allocator A callback to allocate memory for the contact cache
\return a boolean indicating if the function was successful or not.
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxGenerateContacts(const PxGeometry* const * geom0, const PxGeometry* const * geom1, const PxTransform* pose0, const PxTransform* pose1, PxCache* contactCache, const PxU32 nbPairs, PxContactRecorder& contactRecorder,
const PxReal contactDistance, const PxReal meshContactMargin, const PxReal toleranceLength, PxCacheAllocator& allocator);
/**
\brief Register articulation-related solver functions. This is equivalent to PxRegisterArticulationsReducedCoordinate() for PxScene-level articulations.
Call this first to enable reduced coordinates articulations in immediate mode.
@see PxRegisterArticulationsReducedCoordinate
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxRegisterImmediateArticulations();
struct PxArticulationJointData
{
PxTransform parentPose;
PxTransform childPose;
};
struct PxFeatherstoneArticulationJointData : PxArticulationJointData
{
PxArticulationJointType::Enum type;
PxArticulationMotion::Enum motion[PxArticulationAxis::eCOUNT];
PxArticulationLimit limits[PxArticulationAxis::eCOUNT];
PxArticulationDrive drives[PxArticulationAxis::eCOUNT];
PxReal targetPos[PxArticulationAxis::eCOUNT];
PxReal targetVel[PxArticulationAxis::eCOUNT];
PxReal frictionCoefficient;
PxReal maxJointVelocity;
};
struct PxFeatherstoneArticulationData
{
PxArticulationFlags flags;
};
struct PxMutableLinkData
{
PxVec3 inverseInertia;
float inverseMass;
float linearDamping;
float angularDamping;
float maxLinearVelocitySq;
float maxAngularVelocitySq;
bool disableGravity;
};
struct PxLinkData
{
PxTransform pose;
PxVec3 linearVelocity;
PxVec3 angularVelocity;
};
struct PxFeatherstoneArticulationLinkData : PxMutableLinkData
{
PxFeatherstoneArticulationLinkData() { initData(); }
void initData()
{
inboundJoint.type = PxArticulationJointType::eUNDEFINED; // For root
inboundJoint.parentPose = PxTransform(PxIdentity);
inboundJoint.childPose = PxTransform(PxIdentity);
inboundJoint.frictionCoefficient = 0.05f;
inboundJoint.maxJointVelocity = 100.0f;
pose = PxTransform(PxIdentity);
parent = 0;
inverseInertia = PxVec3(1.0f);
inverseMass = 1.0f;
linearDamping = 0.05f;
angularDamping = 0.05f;
maxLinearVelocitySq = 100.0f * 100.0f;
maxAngularVelocitySq = 50.0f * 50.0f;
disableGravity = false;
for(PxU32 i=0;i<PxArticulationAxis::eCOUNT;i++)
{
inboundJoint.motion[i] = PxArticulationMotion::eLOCKED;
inboundJoint.limits[i].low = inboundJoint.limits[i].high = 0.0f;
inboundJoint.drives[i].stiffness = 0.0f;
inboundJoint.drives[i].damping = 0.0f;
inboundJoint.drives[i].maxForce = 0.0f;
inboundJoint.drives[i].driveType = PxArticulationDriveType::eFORCE;
}
memset(inboundJoint.targetPos, 0xff, sizeof(PxReal)*PxArticulationAxis::eCOUNT);
memset(inboundJoint.targetVel, 0xff, sizeof(PxReal)*PxArticulationAxis::eCOUNT);
}
PxFeatherstoneArticulationJointData inboundJoint;
// Non-mutable link data
PxTransform pose;
Dy::ArticulationLinkHandle parent;
};
/**
\brief Creates an immediate-mode reduced-coordinate articulation.
\param [in] data Articulation data
\return Articulation handle
@see PxReleaseArticulation
*/
// PT: Design note: I use Dy::ArticulationV* to be consistent with PxSolverDefs.h
PX_C_EXPORT PX_PHYSX_CORE_API Dy::ArticulationV* PxCreateFeatherstoneArticulation(const PxFeatherstoneArticulationData& data);
/**
\brief Releases an immediate-mode reduced-coordinate articulation.
\param [in] articulation Articulation handle
@see PxCreateFeatherstoneArticulation
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxReleaseArticulation(Dy::ArticulationV* articulation);
/**
\brief Creates an articulation cache.
\param [in] articulation Articulation handle
\return Articulation cache
@see PxReleaseArticulationCache
*/
PX_C_EXPORT PX_PHYSX_CORE_API PxArticulationCache* PxCreateArticulationCache(Dy::ArticulationV* articulation);
/**
\brief Copy the internal data of the articulation to the cache
\param[in] articulation articulation handle.
\param[in] cache Articulation data
\param[in] flag Indicates which values of the articulation system are copied to the cache
@see createCache PxApplyArticulationCache
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxCopyInternalStateToArticulationCache(Dy::ArticulationV* articulation, PxArticulationCache& cache, PxArticulationCacheFlags flag);
/**
\brief Apply the user defined data in the cache to the articulation system
\param[in] articulation articulation handle.
\param[in] cache Articulation data.
\param[in] flag Defines which values in the cache will be applied to the articulation
@see createCache PxCopyInternalStateToArticulationCache
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxApplyArticulationCache(Dy::ArticulationV* articulation, PxArticulationCache& cache, PxArticulationCacheFlags flag);
/**
\brief Release an articulation cache
\param[in] cache The cache to release
@see PxCreateArticulationCache PxCopyInternalStateToArticulationCache PxCopyInternalStateToArticulationCache
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxReleaseArticulationCache(PxArticulationCache& cache);
/**
\brief Adds a link to an immediate-mode reduced-coordinate articulation. The articulation becomes the link's owner/parent.
\param [in] articulation Articulation handle
\param [in] data Link data
\param [in] isLastLink Hint to tell the system whether the added link is the last one or not.
This is a minor optimization, it is also ok to always use either true or false here.
\return Articulation link handle
*/
PX_C_EXPORT PX_PHYSX_CORE_API Dy::ArticulationLinkHandle PxAddArticulationLink(Dy::ArticulationV* articulation, const PxFeatherstoneArticulationLinkData& data, bool isLastLink=false);
/**
\brief Retrieves owner/parent articulation handle from a link handle.
\param [in] link Link handle
\return Articulation handle
*/
PX_C_EXPORT PX_PHYSX_CORE_API Dy::ArticulationV* PxGetLinkArticulation(const Dy::ArticulationLinkHandle link);
/**
\brief Retrieves link index from a link handle.
\param [in] link Link handle
\return Link index
*/
PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxGetLinkIndex(const Dy::ArticulationLinkHandle link);
/**
\brief Retrieves non-mutable link data from a link handle.
The data here is computed by the articulation code but cannot be directly changed by users.
\param [in] link Link handle
\param [out] data Link data
\return True if success
@see PxGetAllLinkData
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetLinkData(const Dy::ArticulationLinkHandle link, PxLinkData& data);
/**
\brief Retrieves non-mutable link data from an articulation handle (all links).
The data here is computed by the articulation code but cannot be directly changed by users.
\param [in] articulation Articulation handle
\param [out] data Link data for N links, or NULL to just retrieve the number of links.
\return Number of links in the articulation = number of link data structure written to the data array.
@see PxGetLinkData
*/
PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxGetAllLinkData(const Dy::ArticulationV* articulation, PxLinkData* data);
/**
\brief Retrieves mutable link data from a link handle.
\param [in] link Link handle
\param [out] data Data for this link
\return True if success
@see PxSetMutableLinkData
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetMutableLinkData(const Dy::ArticulationLinkHandle link, PxMutableLinkData& data);
/**
\brief Sets mutable link data for given link.
\param [in] link Link handle
\param [in] data Data for this link
\return True if success
@see PxGetMutableLinkData
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxSetMutableLinkData(Dy::ArticulationLinkHandle link, const PxMutableLinkData& data);
/**
\brief Retrieves joint data from a link handle.
\param [in] link Link handle
\param [out] data Joint data for this link
\return True if success
@see PxSetJointData
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetJointData(const Dy::ArticulationLinkHandle link, PxFeatherstoneArticulationJointData& data);
/**
\brief Sets joint data for given link.
\param [in] link Link handle
\param [in] data Joint data for this link
\return True if success
@see PxGetJointData
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxSetJointData(Dy::ArticulationLinkHandle link, const PxFeatherstoneArticulationJointData& data);
/**
\brief Computes unconstrained velocities for a given articulation.
\param [in] articulation Articulation handle
\param [in] gravity Gravity vector
\param [in] dt Timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxComputeUnconstrainedVelocities(Dy::ArticulationV* articulation, const PxVec3& gravity, const PxReal dt);
/**
\brief Updates bodies for a given articulation.
\param [in] articulation Articulation handle
\param [in] dt Timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxUpdateArticulationBodies(Dy::ArticulationV* articulation, const PxReal dt);
/**
\brief Computes unconstrained velocities for a given articulation.
\param [in] articulation Articulation handle
\param [in] gravity Gravity vector
\param [in] dt Timestep/numPosIterations
\param [in] totalDt Timestep
\param [in] invDt 1/(Timestep/numPosIterations)
\param [in] invTotalDt 1/Timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxComputeUnconstrainedVelocitiesTGS(Dy::ArticulationV* articulation, const PxVec3& gravity, const PxReal dt, const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt);
/**
\brief Updates bodies for a given articulation.
\param [in] articulation Articulation handle
\param [in] dt Timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxUpdateArticulationBodiesTGS(Dy::ArticulationV* articulation, const PxReal dt);
/**
\brief Constructs a PxSolverBodyData structure based on rigid body properties. Applies gravity, damping and clamps maximum velocity.
\param [in] inRigidData The array rigid body properties
\param [out] outSolverBodyVel The array of PxTGSSolverBodyVel structures produced to represent these bodies
\param [out] outSolverBodyTxInertia The array of PxTGSSolverBodyTxInertia produced to represent these bodies
\param [out] outSolverBodyData The array of PxTGSolverBodyData produced to repreent these bodies
\param [in] nbBodies The total number of solver bodies to create
\param [in] gravity The gravity vector
\param [in] dt The timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructSolverBodiesTGS(const PxRigidBodyData* inRigidData, PxTGSSolverBodyVel* outSolverBodyVel, PxTGSSolverBodyTxInertia* outSolverBodyTxInertia, PxTGSSolverBodyData* outSolverBodyData, const PxU32 nbBodies, const PxVec3& gravity, const PxReal dt);
/**
\brief Constructs a PxSolverBodyData structure for a static body at a given pose.
\param [in] globalPose The pose of this static actor
\param [out] solverBodyVel The velocity component of this body (will be zero)
\param [out] solverBodyTxInertia The intertia and transform delta component of this body (will be zero)
\param [out] solverBodyData The solver body representation of this static actor
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructStaticSolverBodyTGS(const PxTransform& globalPose, PxTGSSolverBodyVel& solverBodyVel, PxTGSSolverBodyTxInertia& solverBodyTxInertia, PxTGSSolverBodyData& solverBodyData);
/**
\brief Groups together sets of independent PxSolverConstraintDesc objects to be solved using SIMD SOA approach.
\param [in] solverConstraintDescs The set of solver constraint descs to batch
\param [in] nbConstraints The number of constraints to batch
\param [in,out] solverBodies The array of solver bodies that the constraints reference. Some fields in these structures are written to as scratch memory for the batching.
\param [in] nbBodies The number of bodies
\param [out] outBatchHeaders The batch headers produced by this batching process. This array must have at least 1 entry per input constraint
\param [out] outOrderedConstraintDescs A reordered copy of the constraint descs. This array is referenced by the constraint batches. This array must have at least 1 entry per input constraint.
\param [in,out] articulations The array of articulations that the constraints reference. Some fields in these structures are written to as scratch memory for the batching.
\param [in] nbArticulations The number of articulations
\return The total number of batches produced. This should be less than or equal to nbConstraints.
\note This method considers all bodies within the range [0, nbBodies-1] to be valid dynamic bodies. A given dynamic body can only be referenced in a batch once. Static or kinematic bodies can be
referenced multiple times within a batch safely because constraints do not affect their velocities. The batching will implicitly consider any bodies outside of the range [0, nbBodies-1] to be
infinite mass (static or kinematic). This means that either appending static/kinematic to the end of the array of bodies or placing static/kinematic bodies at before the start body pointer
will ensure that the minimum number of batches are produced.
*/
PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxBatchConstraintsTGS(const PxSolverConstraintDesc* solverConstraintDescs, const PxU32 nbConstraints, PxTGSSolverBodyVel* solverBodies, const PxU32 nbBodies,
PxConstraintBatchHeader* outBatchHeaders, PxSolverConstraintDesc* outOrderedConstraintDescs,
Dy::ArticulationV** articulations = NULL, const PxU32 nbArticulations = 0);
/**
\brief Creates a set of contact constraint blocks. Note that, depending the results of PxBatchConstraints, each batchHeader may refer to up to 4 solverConstraintDescs.
This function will allocate both constraint and friction patch data via the PxConstraintAllocator provided. Constraint data is only valid until PxSolveConstraints has completed.
Friction data is to be retained and provided by the application for friction correlation.
\param [in] batchHeaders Array of batch headers to process
\param [in] nbHeaders The total number of headers
\param [in] contactDescs An array of contact descs defining the pair and contact properties of each respective contacting pair
\param [in] allocator An allocator callback to allocate constraint and friction memory
\param [in] invDt The inverse timestep/nbPositionIterations
\param [in] invTotalDt The inverse time-step
\param [in] bounceThreshold The bounce threshold. Relative velocities below this will be solved by bias only. Relative velocities above this will be solved by restitution. If restitution is zero
then these pairs will always be solved by bias.
\param [in] frictionOffsetThreshold The friction offset threshold. Contacts whose separations are below this threshold can generate friction constraints.
\param [in] correlationDistance The correlation distance used by friction correlation to identify whether a friction patch is broken on the grounds of relation separation.
\return a boolean to define if this method was successful or not.
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateContactConstraintsTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxTGSSolverContactDesc* contactDescs,
PxConstraintAllocator& allocator, const PxReal invDt, const PxReal invTotalDt, const PxReal bounceThreshold, const PxReal frictionOffsetThreshold, const PxReal correlationDistance);
/**
\brief Creates a set of joint constraint blocks. Note that, depending the results of PxBatchConstraints, the batchHeader may refer to up to 4 solverConstraintDescs
\param [in] batchHeaders The array of batch headers to be processed
\param [in] nbHeaders The total number of batch headers to process
\param [in] jointDescs An array of constraint prep descs defining the properties of the constraints being created
\param [in] allocator An allocator callback to allocate constraint data
\param [in] dt The total time-step/nbPositionIterations
\param [in] totalDt The total time-step
\param [in] invDt The inverse (timestep/nbPositionIterations)
\param [in] invTotalDt The inverse total time-step
\param [in] lengthScale PxToleranceScale::length, i.e. a meter in simulation units
\return a boolean indicating if this method was successful or not.
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders,
PxTGSSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal totalDt, const PxReal invDt,
const PxReal invTotalDt, const PxReal lengthScale);
/**
\brief Creates a set of joint constraint blocks. This function runs joint shaders defined inside PxConstraint** param, fills in joint row information in jointDescs and then calls PxCreateJointConstraints.
\param [in] batchHeaders The set of batchHeaders to be processed
\param [in] nbBatchHeaders The number of batch headers to process.
\param [in] constraints The set of constraints to be used to produce constraint rows
\param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
\param [in] allocator An allocator callback to allocate constraint data
\param [in] dt The total time-step/nbPositionIterations
\param [in] totalDt The total time-step
\param [in] invDt The inverse (timestep/nbPositionIterations)
\param [in] invTotalDt The inverse total time-step
\param [in] lengthScale PxToleranceScale::length, i.e. a meter in simulation units
\return a boolean indicating if this method was successful or not.
@see PxCreateJointConstraints
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithShadersTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxConstraint** constraints, PxTGSSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt,
const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal lengthScale);
/**
\brief Creates a set of joint constraint blocks. This function runs joint shaders defined inside PxImmediateConstraint* param, fills in joint row information in jointDescs and then calls PxCreateJointConstraints.
\param [in] batchHeaders The set of batchHeaders to be processed
\param [in] nbBatchHeaders The number of batch headers to process.
\param [in] constraints The set of constraints to be used to produce constraint rows
\param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
\param [in] allocator An allocator callback to allocate constraint data
\param [in] dt The total time-step/nbPositionIterations
\param [in] totalDt The total time-step
\param [in] invDt The inverse (timestep/nbPositionIterations)
\param [in] invTotalDt The inverse total time-step
\param [in] lengthScale PxToleranceScale::length, i.e. a meter in simulation units
\return a boolean indicating if this method was successful or not.
@see PxCreateJointConstraints
*/
PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithImmediateShadersTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxImmediateConstraint* constraints, PxTGSSolverConstraintPrepDesc* jointDescs,
PxConstraintAllocator& allocator, const PxReal dt, const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal lengthScale);
/**
\brief Iteratively solves the set of constraints defined by the provided PxConstraintBatchHeader and PxSolverConstraintDesc structures. Updates deltaVelocities inside the PxSolverBody structures. Produces resulting linear and angular motion velocities.
\param [in] batchHeaders The set of batch headers to be solved
\param [in] nbBatchHeaders The total number of batch headers to be solved
\param [in] solverConstraintDescs The reordererd set of solver constraint descs referenced by the batch headers
\param [in,out] solverBodies The set of solver bodies the bodies reference
\param [in,out] txInertias The set of solver body TxInertias the bodies reference
\param [in] nbSolverBodies The total number of solver bodies
\param [in] nbPositionIterations The number of position iterations to run
\param [in] nbVelocityIterations The number of velocity iterations to run
\param [in] dt time-step/nbPositionIterations
\param [in] invDt 1/(time-step/nbPositionIterations)
\param [in] nbSolverArticulations Number of articulations to solve constraints for.
\param [in] solverArticulations Array of articulations to solve constraints for.
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxSolveConstraintsTGS(const PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, const PxSolverConstraintDesc* solverConstraintDescs,
PxTGSSolverBodyVel* solverBodies, PxTGSSolverBodyTxInertia* txInertias, const PxU32 nbSolverBodies, const PxU32 nbPositionIterations, const PxU32 nbVelocityIterations,
const float dt, const float invDt, const PxU32 nbSolverArticulations, Dy::ArticulationV** solverArticulations);
/**
\brief Integrates a rigid body, returning the new velocities and transforms. After this function has been called, solverBody stores all the body's velocity data.
\param [in,out] solverBody The array of solver bodies to be integrated
\param [in] txInertia The delta pose and inertia terms
\param [in,out] poses The original poses of the bodies. Updated to be the new poses of the bodies
\param [in] nbBodiesToIntegrate The total number of bodies to integrate
\param [in] dt The timestep
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PxIntegrateSolverBodiesTGS(PxTGSSolverBodyVel* solverBody, PxTGSSolverBodyTxInertia* txInertia, PxTransform* poses, const PxU32 nbBodiesToIntegrate, const PxReal dt);
#if !PX_DOXYGEN
}
#endif
#if !PX_DOXYGEN
}
#endif
/** @} */
#endif
|