RavEngine
Loading...
Searching...
No Matches
PxImmediateMode.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 PX_IMMEDIATE_MODE_H
30#define PX_IMMEDIATE_MODE_H
34#include "PxPhysXConfig.h"
35#include "foundation/PxMemory.h"
36#include "solver/PxSolverDefs.h"
37#include "collision/PxCollisionDefs.h"
38#include "PxArticulationReducedCoordinate.h"
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
45 class PxCudaContextManager;
46 class PxBaseTask;
47 class PxGeometry;
48
49#if !PX_DOXYGEN
50namespace immediate
51{
52#endif
53
54 typedef void* PxArticulationHandle;
55
60 {
61 PxVec3 top;
62 PxReal pad0;
63 PxVec3 bottom;
64 PxReal pad1;
65 };
66
85
90 {
91 public:
99 virtual bool recordContacts(const PxContactPoint* contactPoints, const PxU32 nbContacts, const PxU32 index) = 0;
100
101 virtual ~PxContactRecorder(){}
102 };
103
113 PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructSolverBodies(const PxRigidBodyData* inRigidData, PxSolverBodyData* outSolverBodyData, PxU32 nbBodies, const PxVec3& gravity, PxReal dt, bool gyroscopicForces = false);
114
120 PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructStaticSolverBody(const PxTransform& globalPose, PxSolverBodyData& solverBodyData);
121
139 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxBatchConstraints( const PxSolverConstraintDesc* solverConstraintDescs, PxU32 nbConstraints, PxSolverBody* solverBodies, PxU32 nbBodies,
140 PxConstraintBatchHeader* outBatchHeaders, PxSolverConstraintDesc* outOrderedConstraintDescs,
141 PxArticulationHandle* articulations=NULL, PxU32 nbArticulations=0);
142
161 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateContactConstraints(PxConstraintBatchHeader* batchHeaders, PxU32 nbHeaders, PxSolverContactDesc* contactDescs,
162 PxConstraintAllocator& allocator, PxReal invDt, PxReal bounceThreshold, PxReal frictionOffsetThreshold, PxReal correlationDistance,
163 PxSpatialVector* Z = NULL);
164
176 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraints(PxConstraintBatchHeader* batchHeaders, PxU32 nbHeaders, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, PxSpatialVector* Z, PxReal dt, PxReal invDt);
177
191 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithShaders(PxConstraintBatchHeader* batchHeaders, PxU32 nbBatchHeaders, PxConstraint** constraints, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, PxReal dt, PxReal invDt, PxSpatialVector* Z = NULL);
192
194 {
196 const void* constantBlock;
197 };
198
212 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithImmediateShaders(PxConstraintBatchHeader* batchHeaders, PxU32 nbBatchHeaders, PxImmediateConstraint* constraints, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, PxReal dt, PxReal invDt, PxSpatialVector* Z = NULL);
213
232 PX_C_EXPORT PX_PHYSX_CORE_API void PxSolveConstraints(const PxConstraintBatchHeader* batchHeaders, PxU32 nbBatchHeaders, const PxSolverConstraintDesc* solverConstraintDescs,
233 const PxSolverBody* solverBodies, PxVec3* linearMotionVelocity, PxVec3* angularMotionVelocity, PxU32 nbSolverBodies, PxU32 nbPositionIterations, PxU32 nbVelocityIterations,
234 float dt=0.0f, float invDt=0.0f, PxU32 nbSolverArticulations=0, PxArticulationHandle* solverArticulations=NULL, PxSpatialVector* Z = NULL, PxSpatialVector* deltaV = NULL);
235
246 PX_C_EXPORT PX_PHYSX_CORE_API void PxIntegrateSolverBodies(PxSolverBodyData* solverBodyData, PxSolverBody* solverBody, const PxVec3* linearMotionVelocity, const PxVec3* angularMotionState, PxU32 nbBodiesToIntegrate, PxReal dt);
247
268 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGenerateContacts( const PxGeometry* const * geom0, const PxGeometry* const * geom1, const PxTransform* pose0, const PxTransform* pose1,
269 PxCache* contactCache, PxU32 nbPairs, PxContactRecorder& contactRecorder,
270 PxReal contactDistance, PxReal meshContactMargin, PxReal toleranceLength, PxCacheAllocator& allocator);
271
278 PX_C_EXPORT PX_PHYSX_CORE_API void PxRegisterImmediateArticulations();
279
281 {
282 PxTransform parentPose;
283 PxTransform childPose;
284 PxArticulationMotion::Enum motion[PxArticulationAxis::eCOUNT];
285 PxArticulationLimit limits[PxArticulationAxis::eCOUNT];
286 PxArticulationDrive drives[PxArticulationAxis::eCOUNT];
287 PxReal targetPos[PxArticulationAxis::eCOUNT];
288 PxReal targetVel[PxArticulationAxis::eCOUNT];
289 PxReal armature[PxArticulationAxis::eCOUNT];
290 PxReal jointPos[PxArticulationAxis::eCOUNT];
291 PxReal jointVel[PxArticulationAxis::eCOUNT];
292 PxReal frictionCoefficient;
293 PxReal maxJointVelocity;
295
296 void initData()
297 {
298 parentPose = PxTransform(PxIdentity);
299 childPose = PxTransform(PxIdentity);
300 frictionCoefficient = 0.05f;
301 maxJointVelocity = 100.0f;
302 type = PxArticulationJointType::eUNDEFINED; // For root
303
304 for(PxU32 i=0;i<PxArticulationAxis::eCOUNT;i++)
305 {
307 limits[i] = PxArticulationLimit(0.0f, 0.0f);
308 drives[i] = PxArticulationDrive(0.0f, 0.0f, 0.0f);
309 armature[i] = 0.0f;
310 jointPos[i] = 0.0f;
311 jointVel[i] = 0.0f;
312 }
313 PxMemSet(targetPos, 0xff, sizeof(PxReal)*PxArticulationAxis::eCOUNT);
314 PxMemSet(targetVel, 0xff, sizeof(PxReal)*PxArticulationAxis::eCOUNT);
315 }
316 };
317
319 {
321 };
322
324 {
325 PxVec3 inverseInertia;
326 float inverseMass;
327 float linearDamping;
328 float angularDamping;
329 float maxLinearVelocitySq;
330 float maxAngularVelocitySq;
331 float cfmScale;
332 bool disableGravity;
333
334 void initData()
335 {
336 inverseInertia = PxVec3(1.0f);
337 inverseMass = 1.0f;
338 linearDamping = 0.05f;
339 angularDamping = 0.05f;
340 maxLinearVelocitySq = 100.0f * 100.0f;
341 maxAngularVelocitySq = 50.0f * 50.0f;
342 cfmScale = 0.025f;
343 disableGravity = false;
344 }
345 };
346
348 {
349 PxTransform pose;
350 PxVec3 linearVelocity;
351 PxVec3 angularVelocity;
352 };
353
355 {
356 PxArticulationLinkDataRC() { PxArticulationLinkDataRC::initData(); }
357
358 void initData()
359 {
360 pose = PxTransform(PxIdentity);
361
362 PxArticulationLinkMutableDataRC::initData();
363 inboundJoint.initData();
364 }
365
366 PxArticulationJointDataRC inboundJoint;
367 PxTransform pose;
368 };
369
370 typedef void* PxArticulationCookie;
371
373 {
374 PxArticulationCookie articulation;
375 PxU32 linkId;
376 };
377
379 {
380 PX_FORCE_INLINE PxCreateArticulationLinkCookie(PxArticulationCookie art=NULL, PxU32 id=0xffffffff)
381 {
382 articulation = art;
383 linkId = id;
384 }
385 };
386
388 {
389 PX_FORCE_INLINE PxArticulationLinkHandle(PxArticulationHandle art=NULL, const PxU32 id=0xffffffff) : articulation(art), linkId(id) {}
390
391 PxArticulationHandle articulation;
392 PxU32 linkId;
393 };
394
408 PX_C_EXPORT PX_PHYSX_CORE_API PxArticulationCookie PxBeginCreateArticulationRC(const PxArticulationDataRC& data);
409
425 PX_C_EXPORT PX_PHYSX_CORE_API PxArticulationLinkCookie PxAddArticulationLink(PxArticulationCookie articulation, const PxArticulationLinkCookie* parent, const PxArticulationLinkDataRC& data);
426
444 PX_C_EXPORT PX_PHYSX_CORE_API PxArticulationHandle PxEndCreateArticulationRC(PxArticulationCookie articulation, PxArticulationLinkHandle* linkHandles, PxU32 bufferSize);
445
452 PX_C_EXPORT PX_PHYSX_CORE_API void PxReleaseArticulation(PxArticulationHandle articulation);
453
461 PX_C_EXPORT PX_PHYSX_CORE_API PxArticulationCache* PxCreateArticulationCache(PxArticulationHandle articulation);
462
471 PX_C_EXPORT PX_PHYSX_CORE_API void PxCopyInternalStateToArticulationCache(PxArticulationHandle articulation, PxArticulationCache& cache, PxArticulationCacheFlags flag);
472
481 PX_C_EXPORT PX_PHYSX_CORE_API void PxApplyArticulationCache(PxArticulationHandle articulation, PxArticulationCache& cache, PxArticulationCacheFlags flag);
482
490 PX_C_EXPORT PX_PHYSX_CORE_API void PxReleaseArticulationCache(PxArticulationCache& cache);
491
501 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetLinkData(const PxArticulationLinkHandle& link, PxArticulationLinkDerivedDataRC& data);
502
512 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxGetAllLinkData(const PxArticulationHandle articulation, PxArticulationLinkDerivedDataRC* data);
513
522 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetMutableLinkData(const PxArticulationLinkHandle& link, PxArticulationLinkMutableDataRC& data);
523
532 PX_C_EXPORT PX_PHYSX_CORE_API bool PxSetMutableLinkData(const PxArticulationLinkHandle& link, const PxArticulationLinkMutableDataRC& data);
533
542 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetJointData(const PxArticulationLinkHandle& link, PxArticulationJointDataRC& data);
543
552 PX_C_EXPORT PX_PHYSX_CORE_API bool PxSetJointData(const PxArticulationLinkHandle& link, const PxArticulationJointDataRC& data);
553
561 PX_C_EXPORT PX_PHYSX_CORE_API void PxComputeUnconstrainedVelocities(PxArticulationHandle articulation, const PxVec3& gravity, const PxReal dt, const PxReal invLengthScale);
562
568 PX_C_EXPORT PX_PHYSX_CORE_API void PxUpdateArticulationBodies(PxArticulationHandle articulation, const PxReal dt);
569
580 PX_C_EXPORT PX_PHYSX_CORE_API void PxComputeUnconstrainedVelocitiesTGS( PxArticulationHandle articulation, const PxVec3& gravity, const PxReal dt,
581 const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal invLengthScale);
582
588 PX_C_EXPORT PX_PHYSX_CORE_API void PxUpdateArticulationBodiesTGS(PxArticulationHandle articulation, const PxReal dt);
589
601 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, const bool gyroscopicForces = false);
602
610 PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructStaticSolverBodyTGS(const PxTransform& globalPose, PxTGSSolverBodyVel& solverBodyVel, PxTGSSolverBodyTxInertia& solverBodyTxInertia, PxTGSSolverBodyData& solverBodyData);
611
629 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxBatchConstraintsTGS( const PxSolverConstraintDesc* solverConstraintDescs, const PxU32 nbConstraints, PxTGSSolverBodyVel* solverBodies, const PxU32 nbBodies,
630 PxConstraintBatchHeader* outBatchHeaders, PxSolverConstraintDesc* outOrderedConstraintDescs,
631 PxArticulationHandle* articulations = NULL, const PxU32 nbArticulations = 0);
632
651 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateContactConstraintsTGS( PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxTGSSolverContactDesc* contactDescs,
652 PxConstraintAllocator& allocator, const PxReal invDt, const PxReal invTotalDt, const PxReal bounceThreshold,
653 const PxReal frictionOffsetThreshold, const PxReal correlationDistance);
654
668 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsTGS( PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders,
669 PxTGSSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal totalDt, const PxReal invDt,
670 const PxReal invTotalDt, const PxReal lengthScale);
671
687 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithShadersTGS( PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxConstraint** constraints, PxTGSSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator,
688 const PxReal dt, const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal lengthScale);
689
705 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithImmediateShadersTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxImmediateConstraint* constraints, PxTGSSolverConstraintPrepDesc* jointDescs,
706 PxConstraintAllocator& allocator, const PxReal dt, const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal lengthScale);
707
725 PX_C_EXPORT PX_PHYSX_CORE_API void PxSolveConstraintsTGS( const PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, const PxSolverConstraintDesc* solverConstraintDescs,
726 PxTGSSolverBodyVel* solverBodies, PxTGSSolverBodyTxInertia* txInertias, const PxU32 nbSolverBodies, const PxU32 nbPositionIterations, const PxU32 nbVelocityIterations,
727 const float dt, const float invDt, const PxU32 nbSolverArticulations = 0, PxArticulationHandle* solverArticulations = NULL, PxSpatialVector* Z = NULL, PxSpatialVector* deltaV = NULL);
728
738 PX_C_EXPORT PX_PHYSX_CORE_API void PxIntegrateSolverBodiesTGS(PxTGSSolverBodyVel* solverBody, PxTGSSolverBodyTxInertia* txInertia, PxTransform* poses, const PxU32 nbBodiesToIntegrate, const PxReal dt);
739
743 typedef PX_DEPRECATED PxArticulationJointDataRC PxFeatherstoneArticulationJointData;
747 typedef PX_DEPRECATED PxArticulationLinkDataRC PxFeatherstoneArticulationLinkData;
751 typedef PX_DEPRECATED PxArticulationDataRC PxFeatherstoneArticulationData;
755 typedef PX_DEPRECATED PxArticulationLinkMutableDataRC PxMutableLinkData;
760
761#if !PX_DOXYGEN
762}
763#endif
764
765#if !PX_DOXYGEN
766}
767#endif
768
770#endif
771
Data structure used to read and write internal articulation data.
Definition PxArticulationReducedCoordinate.h:99
A callback class to allocate memory to cache information used in contact generation.
Definition PxCollisionDefs.h:44
Definition PxSolverDefs.h:227
A plugin class for implementing constraints.
Definition PxConstraint.h:100
A geometry object.
Definition PxGeometry.h:79
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
Callback class to record contact points produced by immediate::PxGenerateContacts.
Definition PxImmediateMode.h:90
virtual bool recordContacts(const PxContactPoint *contactPoints, const PxU32 nbContacts, const PxU32 index)=0
Method to record new contacts.
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_DEPRECATED
Definition PxPreprocessor.h:418
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU32(* PxConstraintSolverPrep)(Px1DConstraint *constraints, PxVec3p &bodyAWorldOffset, PxU32 maxConstraints, PxConstraintInvMassScale &invMassScale, const void *constantBlock, const PxTransform &bodyAToWorld, const PxTransform &bodyBToWorld, bool useExtendedLimits, PxVec3p &cAtW, PxVec3p &cBtW)
Solver constraint generation shader.
Definition PxConstraintDesc.h:223
PX_FORCE_INLINE void * PxMemSet(void *dest, PxI32 c, PxU32 count)
Sets the bytes of the provided buffer to the specified value.
Definition PxMemory.h:67
Data structure for articulation joint drive configuration.
Definition PxSolverDefs.h:359
Enum
Definition PxSolverDefs.h:281
Data structure to set articulation joint limits.
Definition PxSolverDefs.h:327
Enum
Definition PxSolverDefs.h:268
@ eLOCKED
Locked axis, i.e. degree of freedom (DOF)
Definition PxSolverDefs.h:269
A structure to cache contact information produced by low-level contact generation functions.
Definition PxCollisionDefs.h:68
A header that defines the size of a specific batch of constraints (of same type and without dependenc...
Definition PxSolverDefs.h:98
Definition PxContactPoint.h:40
Struct that the solver uses to store the state and other properties of a body.
Definition PxSolverDefs.h:74
Struct that the solver uses to store velocity updates for a body.
Definition PxSolverDefs.h:55
Constraint descriptor used inside the solver.
Definition PxSolverDefs.h:108
Data structure used for preparing constraints before solving them.
Definition PxSolverDefs.h:178
Data structure used for preparing constraints before solving them.
Definition PxSolverDefs.h:198
Definition PxSolverDefs.h:446
Definition PxSolverDefs.h:440
Definition PxSolverDefs.h:419
Definition PxSolverDefs.h:486
Definition PxSolverDefs.h:505
Definition PxImmediateMode.h:319
Definition PxImmediateMode.h:281
Definition PxImmediateMode.h:373
Definition PxImmediateMode.h:355
Definition PxImmediateMode.h:388
Definition PxImmediateMode.h:379
Definition PxImmediateMode.h:194
Structure to store rigid body properties.
Definition PxImmediateMode.h:71
PxReal maxDepenetrationVelocity
32 Maximum de-penetration velocity
Definition PxImmediateMode.h:75
PX_ALIGN(16, PxVec3 linearVelocity)
12 Linear velocity
PxReal maxLinearVelocitySq
88 Squared maximum linear velocity
Definition PxImmediateMode.h:81
PxReal invMass
16 Inverse mass
Definition PxImmediateMode.h:73
PxVec3 angularVelocity
28 Angular velocity
Definition PxImmediateMode.h:74
PxReal linearDamping
80 Linear damping coefficient
Definition PxImmediateMode.h:79
PxReal maxContactImpulse
48 Maximum permissable contact impulse
Definition PxImmediateMode.h:77
PxReal maxAngularVelocitySq
92 Squared maximum angular velocity
Definition PxImmediateMode.h:82
PxTransform body2World
76 World space transform
Definition PxImmediateMode.h:78
PxReal angularDamping
84 Angular damping coefficient
Definition PxImmediateMode.h:80
PxU32 pad
96 Padding for 16-byte alignment
Definition PxImmediateMode.h:83
PxVec3 invInertia
44 Mass-space inverse interia diagonal vector
Definition PxImmediateMode.h:76
Structure to store linear and angular components of spatial vector.
Definition PxImmediateMode.h:60