1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30#ifndef PX_PHYSICS_IMMEDIATE_MODE
31#define PX_PHYSICS_IMMEDIATE_MODE
32/** \addtogroup immediatemode
33@{ */
34
35#include "PxPhysXConfig.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#if !PX_DOXYGEN
46namespace immediate
47{
48#endif
49
50 /**
51 \brief Structure to store rigid body properties
52 */
53 struct PxRigidBodyData
54 {
55 PX_ALIGN(16, PxVec3 linearVelocity); //!< 12 Linear velocity
56 PxReal invMass; //!< 16 Inverse mass
57 PxVec3 angularVelocity; //!< 28 Angular velocity
58 PxReal maxDepenetrationVelocity; //!< 32 Maximum de-penetration velocity
59 PxVec3 invInertia; //!< 44 Mass-space inverse interia diagonal vector
60 PxReal maxContactImpulse; //!< 48 Maximum permissable contact impulse
61 PxTransform body2World; //!< 76 World space transform
62 PxReal linearDamping; //!< 80 Linear damping coefficient
63 PxReal angularDamping; //!< 84 Angular damping coefficient
64 PxReal maxLinearVelocitySq; //!< 88 Squared maximum linear velocity
65 PxReal maxAngularVelocitySq; //!< 92 Squared maximum angular velocity
66 PxU32 pad; //!< 96 Padding for 16-byte alignment
67 };
68
69 /**
70 \brief Callback class to record contact points produced by immediate::PxGenerateContacts
71 */
72 class PxContactRecorder
73 {
74 public:
75 /**
76 \brief Method to record new contacts
77 \param [in] contactPoints The contact points produced
78 \param [in] nbContacts The number of contact points produced
79 \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
80 \return a boolean to indicate if this callback successfully stored the contacts or not.
81 */
82 virtual bool recordContacts(const Gu::ContactPoint* contactPoints, const PxU32 nbContacts, const PxU32 index) = 0;
83
84 virtual ~PxContactRecorder(){}
85 };
86
87 /**
88 \brief Constructs a PxSolverBodyData structure based on rigid body properties. Applies gravity, damping and clamps maximum velocity.
89 \param [in] inRigidData The array rigid body properties
90 \param [out] outSolverBodyData The array of solverBodyData produced to repreent these bodies
91 \param [in] nbBodies The total number of solver bodies to create
92 \param [in] gravity The gravity vector
93 \param [in] dt The timestep
94 */
95 PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructSolverBodies(const PxRigidBodyData* inRigidData, PxSolverBodyData* outSolverBodyData, const PxU32 nbBodies, const PxVec3& gravity, const PxReal dt);
96
97 /**
98 \brief Constructs a PxSolverBodyData structure for a static body at a given pose.
99 \param [in] globalPose The pose of this static actor
100 \param [out] solverBodyData The solver body representation of this static actor
101 */
102 PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructStaticSolverBody(const PxTransform& globalPose, PxSolverBodyData& solverBodyData);
103
104 /**
105 \brief Groups together sets of independent PxSolverConstraintDesc objects to be solved using SIMD SOA approach.
106 \param [in] solverConstraintDescs The set of solver constraint descs to batch
107 \param [in] nbConstraints The number of constraints to batch
108 \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.
109 \param [in] nbBodies The number of bodies
110 \param [out] outBatchHeaders The batch headers produced by this batching process. This array must have at least 1 entry per input constraint
111 \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.
112 \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.
113 \param [in] nbArticulations The number of articulations
114 \return The total number of batches produced. This should be less than or equal to nbConstraints.
115
116 \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
117 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
118 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
119 will ensure that the minimum number of batches are produced.
120 */
121 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxBatchConstraints( const PxSolverConstraintDesc* solverConstraintDescs, const PxU32 nbConstraints, PxSolverBody* solverBodies, const PxU32 nbBodies,
122 PxConstraintBatchHeader* outBatchHeaders, PxSolverConstraintDesc* outOrderedConstraintDescs,
123 Dy::ArticulationV** articulations=NULL, const PxU32 nbArticulations=0);
124
125 /**
126 \brief Creates a set of contact constraint blocks. Note that, depending the results of PxBatchConstraints, each batchHeader may refer to up to 4 solverConstraintDescs.
127 This function will allocate both constraint and friction patch data via the PxConstraintAllocator provided. Constraint data is only valid until PxSolveConstraints has completed.
128 Friction data is to be retained and provided by the application for friction correlation.
129
130 \param [in] batchHeaders Array of batch headers to process
131 \param [in] nbHeaders The total number of headers
132 \param [in] contactDescs An array of contact descs defining the pair and contact properties of each respective contacting pair
133 \param [in] allocator An allocator callback to allocate constraint and friction memory
134 \param [in] invDt The inverse timestep
135 \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
136 then these pairs will always be solved by bias.
137 \param [in] frictionOffsetThreshold The friction offset threshold. Contacts whose separations are below this threshold can generate friction constraints.
138 \param [in] correlationDistance The correlation distance used by friction correlation to identify whether a friction patch is broken on the grounds of relation separation.
139
140 \return a boolean to define if this method was successful or not.
141 */
142 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateContactConstraints(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxSolverContactDesc* contactDescs,
143 PxConstraintAllocator& allocator, const PxReal invDt, const PxReal bounceThreshold, const PxReal frictionOffsetThreshold, const PxReal correlationDistance);
144
145 /**
146 \brief Creates a set of joint constraint blocks. Note that, depending the results of PxBatchConstraints, the batchHeader may refer to up to 4 solverConstraintDescs
147 \param [in] batchHeaders The array of batch headers to be processed
148 \param [in] nbHeaders The total number of batch headers to process
149 \param [in] jointDescs An array of constraint prep descs defining the properties of the constraints being created
150 \param [in] allocator An allocator callback to allocate constraint data
151 \param [in] dt The timestep
152 \param [in] invDt The inverse timestep
153 \return a boolean indicating if this method was successful or not.
154 */
155 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraints(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal invDt);
156
157 /**
158 \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.
159 \param [in] batchHeaders The set of batchHeaders to be processed
160 \param [in] nbBatchHeaders The number of batch headers to process.
161 \param [in] constraints The set of constraints to be used to produce constraint rows
162 \param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
163 \param [in] allocator An allocator callback to allocate constraint data
164 \param [in] dt The timestep
165 \param [in] invDt The inverse timestep
166 \return a boolean indicating if this method was successful or not.
167 @see PxCreateJointConstraints
168 */
169 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);
170
171 struct PxImmediateConstraint
172 {
173 PxConstraintSolverPrep prep;
174 const void* constantBlock;
175 };
176 /**
177 \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.
178 \param [in] batchHeaders The set of batchHeaders to be processed
179 \param [in] nbBatchHeaders The number of batch headers to process.
180 \param [in] constraints The set of constraints to be used to produce constraint rows
181 \param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
182 \param [in] allocator An allocator callback to allocate constraint data
183 \param [in] dt The timestep
184 \param [in] invDt The inverse timestep
185 \return a boolean indicating if this method was successful or not.
186 @see PxCreateJointConstraints
187 */
188 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);
189
190 /**
191 \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.
192 \param [in] batchHeaders The set of batch headers to be solved
193 \param [in] nbBatchHeaders The total number of batch headers to be solved
194 \param [in] solverConstraintDescs The reordererd set of solver constraint descs referenced by the batch headers
195 \param [in,out] solverBodies The set of solver bodies the bodies reference
196 \param [out] linearMotionVelocity The resulting linear motion velocity
197 \param [out] angularMotionVelocity The resulting angular motion velocity.
198 \param [in] nbSolverBodies The total number of solver bodies
199 \param [in] nbPositionIterations The number of position iterations to run
200 \param [in] nbVelocityIterations The number of velocity iterations to run
201 \param [in] dt Timestep. Only needed if articulations are sent to the function.
202 \param [in] invDt Inverse timestep. Only needed if articulations are sent to the function.
203 \param [in] nbSolverArticulations Number of articulations to solve constraints for.
204 \param [in] solverArticulations Array of articulations to solve constraints for.
205 */
206 PX_C_EXPORT PX_PHYSX_CORE_API void PxSolveConstraints(const PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, const PxSolverConstraintDesc* solverConstraintDescs,
207 const PxSolverBody* solverBodies, PxVec3* linearMotionVelocity, PxVec3* angularMotionVelocity, const PxU32 nbSolverBodies, const PxU32 nbPositionIterations, const PxU32 nbVelocityIterations,
208 const float dt=0.0f, const float invDt=0.0f, const PxU32 nbSolverArticulations=0, Dy::ArticulationV** solverArticulations=NULL);
209
210 /**
211 \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.
212
213 \param [in,out] solverBodyData The array of solver body data to be integrated
214 \param [in] solverBody The bodies' linear and angular velocities
215 \param [in] linearMotionVelocity The bodies' linear motion velocity array
216 \param [in] angularMotionState The bodies' angular motion velocity array
217 \param [in] nbBodiesToIntegrate The total number of bodies to integrate
218 \param [in] dt The timestep
219 */
220 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);
221
222 /**
223 \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
224 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
225 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
226 performed again, it is the application's responsibility to reset the PxCache.
227
228 \param [in] geom0 Array of geometries to perform collision detection on.
229 \param [in] geom1 Array of geometries to perform collision detection on
230 \param [in] pose0 Array of poses associated with the corresponding entry in the geom0 array
231 \param [in] pose1 Array of poses associated with the corresponding entry in the geom1 array
232 \param [in,out] contactCache Array of contact caches associated with each pair geom0[i] + geom1[i]
233 \param [in] nbPairs The total number of pairs to process
234 \param [in] contactRecorder A callback that is called to record contacts for each pair that detects contacts
235 \param [in] contactDistance The distance at which contacts begin to be generated between the pairs
236 \param [in] meshContactMargin The mesh contact margin.
237 \param [in] toleranceLength The toleranceLength. Used for scaling distance-based thresholds internally to produce appropriate results given simulations in different units
238 \param [in] allocator A callback to allocate memory for the contact cache
239
240 \return a boolean indicating if the function was successful or not.
241 */
242 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,
243 const PxReal contactDistance, const PxReal meshContactMargin, const PxReal toleranceLength, PxCacheAllocator& allocator);
244
245 /**
246 \brief Register articulation-related solver functions. This is equivalent to PxRegisterArticulationsReducedCoordinate() for PxScene-level articulations.
247 Call this first to enable reduced coordinates articulations in immediate mode.
248
249 @see PxRegisterArticulationsReducedCoordinate
250 */
251 PX_C_EXPORT PX_PHYSX_CORE_API void PxRegisterImmediateArticulations();
252
253 struct PxArticulationJointData
254 {
255 PxTransform parentPose;
256 PxTransform childPose;
257 };
258
259 struct PxFeatherstoneArticulationJointData : PxArticulationJointData
260 {
261 PxArticulationJointType::Enum type;
262 PxArticulationMotion::Enum motion[PxArticulationAxis::eCOUNT];
263 PxArticulationLimit limits[PxArticulationAxis::eCOUNT];
264 PxArticulationDrive drives[PxArticulationAxis::eCOUNT];
265 PxReal targetPos[PxArticulationAxis::eCOUNT];
266 PxReal targetVel[PxArticulationAxis::eCOUNT];
267 PxReal frictionCoefficient;
268 PxReal maxJointVelocity;
269 };
270
271 struct PxFeatherstoneArticulationData
272 {
273 PxArticulationFlags flags;
274 };
275
276 struct PxMutableLinkData
277 {
278 PxVec3 inverseInertia;
279 float inverseMass;
280 float linearDamping;
281 float angularDamping;
282 float maxLinearVelocitySq;
283 float maxAngularVelocitySq;
284 bool disableGravity;
285 };
286
287 struct PxLinkData
288 {
289 PxTransform pose;
290 PxVec3 linearVelocity;
291 PxVec3 angularVelocity;
292 };
293
294 struct PxFeatherstoneArticulationLinkData : PxMutableLinkData
295 {
296 PxFeatherstoneArticulationLinkData() { initData(); }
297
298 void initData()
299 {
300 inboundJoint.type = PxArticulationJointType::eUNDEFINED; // For root
301 inboundJoint.parentPose = PxTransform(PxIdentity);
302 inboundJoint.childPose = PxTransform(PxIdentity);
303 inboundJoint.frictionCoefficient = 0.05f;
304 inboundJoint.maxJointVelocity = 100.0f;
305
306 pose = PxTransform(PxIdentity);
307 parent = 0;
308 inverseInertia = PxVec3(1.0f);
309 inverseMass = 1.0f;
310 linearDamping = 0.05f;
311 angularDamping = 0.05f;
312 maxLinearVelocitySq = 100.0f * 100.0f;
313 maxAngularVelocitySq = 50.0f * 50.0f;
314 disableGravity = false;
315
316 for(PxU32 i=0;i<PxArticulationAxis::eCOUNT;i++)
317 {
318 inboundJoint.motion[i] = PxArticulationMotion::eLOCKED;
319 inboundJoint.limits[i].low = inboundJoint.limits[i].high = 0.0f;
320 inboundJoint.drives[i].stiffness = 0.0f;
321 inboundJoint.drives[i].damping = 0.0f;
322 inboundJoint.drives[i].maxForce = 0.0f;
323 inboundJoint.drives[i].driveType = PxArticulationDriveType::eFORCE;
324 }
325 memset(s: inboundJoint.targetPos, c: 0xff, n: sizeof(PxReal)*PxArticulationAxis::eCOUNT);
326 memset(s: inboundJoint.targetVel, c: 0xff, n: sizeof(PxReal)*PxArticulationAxis::eCOUNT);
327 }
328
329 PxFeatherstoneArticulationJointData inboundJoint;
330
331 // Non-mutable link data
332 PxTransform pose;
333 Dy::ArticulationLinkHandle parent;
334 };
335
336 /**
337 \brief Creates an immediate-mode reduced-coordinate articulation.
338 \param [in] data Articulation data
339 \return Articulation handle
340
341 @see PxReleaseArticulation
342 */
343 // PT: Design note: I use Dy::ArticulationV* to be consistent with PxSolverDefs.h
344 PX_C_EXPORT PX_PHYSX_CORE_API Dy::ArticulationV* PxCreateFeatherstoneArticulation(const PxFeatherstoneArticulationData& data);
345
346 /**
347 \brief Releases an immediate-mode reduced-coordinate articulation.
348 \param [in] articulation Articulation handle
349
350 @see PxCreateFeatherstoneArticulation
351 */
352 PX_C_EXPORT PX_PHYSX_CORE_API void PxReleaseArticulation(Dy::ArticulationV* articulation);
353
354 /**
355 \brief Creates an articulation cache.
356 \param [in] articulation Articulation handle
357 \return Articulation cache
358
359 @see PxReleaseArticulationCache
360 */
361 PX_C_EXPORT PX_PHYSX_CORE_API PxArticulationCache* PxCreateArticulationCache(Dy::ArticulationV* articulation);
362
363
364 /**
365 \brief Copy the internal data of the articulation to the cache
366 \param[in] articulation articulation handle.
367 \param[in] cache Articulation data
368 \param[in] flag Indicates which values of the articulation system are copied to the cache
369
370 @see createCache PxApplyArticulationCache
371 */
372 PX_C_EXPORT PX_PHYSX_CORE_API void PxCopyInternalStateToArticulationCache(Dy::ArticulationV* articulation, PxArticulationCache& cache, PxArticulationCacheFlags flag);
373
374 /**
375 \brief Apply the user defined data in the cache to the articulation system
376 \param[in] articulation articulation handle.
377 \param[in] cache Articulation data.
378 \param[in] flag Defines which values in the cache will be applied to the articulation
379
380 @see createCache PxCopyInternalStateToArticulationCache
381 */
382 PX_C_EXPORT PX_PHYSX_CORE_API void PxApplyArticulationCache(Dy::ArticulationV* articulation, PxArticulationCache& cache, PxArticulationCacheFlags flag);
383
384 /**
385 \brief Release an articulation cache
386
387 \param[in] cache The cache to release
388
389 @see PxCreateArticulationCache PxCopyInternalStateToArticulationCache PxCopyInternalStateToArticulationCache
390 */
391 PX_C_EXPORT PX_PHYSX_CORE_API void PxReleaseArticulationCache(PxArticulationCache& cache);
392
393 /**
394 \brief Adds a link to an immediate-mode reduced-coordinate articulation. The articulation becomes the link's owner/parent.
395 \param [in] articulation Articulation handle
396 \param [in] data Link data
397 \param [in] isLastLink Hint to tell the system whether the added link is the last one or not.
398 This is a minor optimization, it is also ok to always use either true or false here.
399 \return Articulation link handle
400 */
401 PX_C_EXPORT PX_PHYSX_CORE_API Dy::ArticulationLinkHandle PxAddArticulationLink(Dy::ArticulationV* articulation, const PxFeatherstoneArticulationLinkData& data, bool isLastLink=false);
402
403 /**
404 \brief Retrieves owner/parent articulation handle from a link handle.
405 \param [in] link Link handle
406 \return Articulation handle
407 */
408 PX_C_EXPORT PX_PHYSX_CORE_API Dy::ArticulationV* PxGetLinkArticulation(const Dy::ArticulationLinkHandle link);
409
410 /**
411 \brief Retrieves link index from a link handle.
412 \param [in] link Link handle
413 \return Link index
414 */
415 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxGetLinkIndex(const Dy::ArticulationLinkHandle link);
416
417 /**
418 \brief Retrieves non-mutable link data from a link handle.
419 The data here is computed by the articulation code but cannot be directly changed by users.
420 \param [in] link Link handle
421 \param [out] data Link data
422 \return True if success
423
424 @see PxGetAllLinkData
425 */
426 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetLinkData(const Dy::ArticulationLinkHandle link, PxLinkData& data);
427
428 /**
429 \brief Retrieves non-mutable link data from an articulation handle (all links).
430 The data here is computed by the articulation code but cannot be directly changed by users.
431 \param [in] articulation Articulation handle
432 \param [out] data Link data for N links, or NULL to just retrieve the number of links.
433 \return Number of links in the articulation = number of link data structure written to the data array.
434
435 @see PxGetLinkData
436 */
437 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxGetAllLinkData(const Dy::ArticulationV* articulation, PxLinkData* data);
438
439 /**
440 \brief Retrieves mutable link data from a link handle.
441 \param [in] link Link handle
442 \param [out] data Data for this link
443 \return True if success
444
445 @see PxSetMutableLinkData
446 */
447 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetMutableLinkData(const Dy::ArticulationLinkHandle link, PxMutableLinkData& data);
448
449 /**
450 \brief Sets mutable link data for given link.
451 \param [in] link Link handle
452 \param [in] data Data for this link
453 \return True if success
454
455 @see PxGetMutableLinkData
456 */
457 PX_C_EXPORT PX_PHYSX_CORE_API bool PxSetMutableLinkData(Dy::ArticulationLinkHandle link, const PxMutableLinkData& data);
458
459 /**
460 \brief Retrieves joint data from a link handle.
461 \param [in] link Link handle
462 \param [out] data Joint data for this link
463 \return True if success
464
465 @see PxSetJointData
466 */
467 PX_C_EXPORT PX_PHYSX_CORE_API bool PxGetJointData(const Dy::ArticulationLinkHandle link, PxFeatherstoneArticulationJointData& data);
468
469 /**
470 \brief Sets joint data for given link.
471 \param [in] link Link handle
472 \param [in] data Joint data for this link
473 \return True if success
474
475 @see PxGetJointData
476 */
477 PX_C_EXPORT PX_PHYSX_CORE_API bool PxSetJointData(Dy::ArticulationLinkHandle link, const PxFeatherstoneArticulationJointData& data);
478
479 /**
480 \brief Computes unconstrained velocities for a given articulation.
481 \param [in] articulation Articulation handle
482 \param [in] gravity Gravity vector
483 \param [in] dt Timestep
484 */
485 PX_C_EXPORT PX_PHYSX_CORE_API void PxComputeUnconstrainedVelocities(Dy::ArticulationV* articulation, const PxVec3& gravity, const PxReal dt);
486
487 /**
488 \brief Updates bodies for a given articulation.
489 \param [in] articulation Articulation handle
490 \param [in] dt Timestep
491 */
492 PX_C_EXPORT PX_PHYSX_CORE_API void PxUpdateArticulationBodies(Dy::ArticulationV* articulation, const PxReal dt);
493
494 /**
495 \brief Computes unconstrained velocities for a given articulation.
496 \param [in] articulation Articulation handle
497 \param [in] gravity Gravity vector
498 \param [in] dt Timestep/numPosIterations
499 \param [in] totalDt Timestep
500 \param [in] invDt 1/(Timestep/numPosIterations)
501 \param [in] invTotalDt 1/Timestep
502 */
503 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);
504
505 /**
506 \brief Updates bodies for a given articulation.
507 \param [in] articulation Articulation handle
508 \param [in] dt Timestep
509 */
510 PX_C_EXPORT PX_PHYSX_CORE_API void PxUpdateArticulationBodiesTGS(Dy::ArticulationV* articulation, const PxReal dt);
511
512
513 /**
514 \brief Constructs a PxSolverBodyData structure based on rigid body properties. Applies gravity, damping and clamps maximum velocity.
515 \param [in] inRigidData The array rigid body properties
516 \param [out] outSolverBodyVel The array of PxTGSSolverBodyVel structures produced to represent these bodies
517 \param [out] outSolverBodyTxInertia The array of PxTGSSolverBodyTxInertia produced to represent these bodies
518 \param [out] outSolverBodyData The array of PxTGSolverBodyData produced to repreent these bodies
519 \param [in] nbBodies The total number of solver bodies to create
520 \param [in] gravity The gravity vector
521 \param [in] dt The timestep
522 */
523 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);
524
525 /**
526 \brief Constructs a PxSolverBodyData structure for a static body at a given pose.
527 \param [in] globalPose The pose of this static actor
528 \param [out] solverBodyVel The velocity component of this body (will be zero)
529 \param [out] solverBodyTxInertia The intertia and transform delta component of this body (will be zero)
530 \param [out] solverBodyData The solver body representation of this static actor
531 */
532 PX_C_EXPORT PX_PHYSX_CORE_API void PxConstructStaticSolverBodyTGS(const PxTransform& globalPose, PxTGSSolverBodyVel& solverBodyVel, PxTGSSolverBodyTxInertia& solverBodyTxInertia, PxTGSSolverBodyData& solverBodyData);
533
534 /**
535 \brief Groups together sets of independent PxSolverConstraintDesc objects to be solved using SIMD SOA approach.
536 \param [in] solverConstraintDescs The set of solver constraint descs to batch
537 \param [in] nbConstraints The number of constraints to batch
538 \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.
539 \param [in] nbBodies The number of bodies
540 \param [out] outBatchHeaders The batch headers produced by this batching process. This array must have at least 1 entry per input constraint
541 \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.
542 \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.
543 \param [in] nbArticulations The number of articulations
544 \return The total number of batches produced. This should be less than or equal to nbConstraints.
545
546 \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
547 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
548 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
549 will ensure that the minimum number of batches are produced.
550 */
551 PX_C_EXPORT PX_PHYSX_CORE_API PxU32 PxBatchConstraintsTGS(const PxSolverConstraintDesc* solverConstraintDescs, const PxU32 nbConstraints, PxTGSSolverBodyVel* solverBodies, const PxU32 nbBodies,
552 PxConstraintBatchHeader* outBatchHeaders, PxSolverConstraintDesc* outOrderedConstraintDescs,
553 Dy::ArticulationV** articulations = NULL, const PxU32 nbArticulations = 0);
554
555
556 /**
557 \brief Creates a set of contact constraint blocks. Note that, depending the results of PxBatchConstraints, each batchHeader may refer to up to 4 solverConstraintDescs.
558 This function will allocate both constraint and friction patch data via the PxConstraintAllocator provided. Constraint data is only valid until PxSolveConstraints has completed.
559 Friction data is to be retained and provided by the application for friction correlation.
560
561 \param [in] batchHeaders Array of batch headers to process
562 \param [in] nbHeaders The total number of headers
563 \param [in] contactDescs An array of contact descs defining the pair and contact properties of each respective contacting pair
564 \param [in] allocator An allocator callback to allocate constraint and friction memory
565 \param [in] invDt The inverse timestep/nbPositionIterations
566 \param [in] invTotalDt The inverse time-step
567 \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
568 then these pairs will always be solved by bias.
569 \param [in] frictionOffsetThreshold The friction offset threshold. Contacts whose separations are below this threshold can generate friction constraints.
570 \param [in] correlationDistance The correlation distance used by friction correlation to identify whether a friction patch is broken on the grounds of relation separation.
571
572 \return a boolean to define if this method was successful or not.
573 */
574 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateContactConstraintsTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders, PxTGSSolverContactDesc* contactDescs,
575 PxConstraintAllocator& allocator, const PxReal invDt, const PxReal invTotalDt, const PxReal bounceThreshold, const PxReal frictionOffsetThreshold, const PxReal correlationDistance);
576
577 /**
578 \brief Creates a set of joint constraint blocks. Note that, depending the results of PxBatchConstraints, the batchHeader may refer to up to 4 solverConstraintDescs
579 \param [in] batchHeaders The array of batch headers to be processed
580 \param [in] nbHeaders The total number of batch headers to process
581 \param [in] jointDescs An array of constraint prep descs defining the properties of the constraints being created
582 \param [in] allocator An allocator callback to allocate constraint data
583 \param [in] dt The total time-step/nbPositionIterations
584 \param [in] totalDt The total time-step
585 \param [in] invDt The inverse (timestep/nbPositionIterations)
586 \param [in] invTotalDt The inverse total time-step
587 \param [in] lengthScale PxToleranceScale::length, i.e. a meter in simulation units
588 \return a boolean indicating if this method was successful or not.
589 */
590 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbHeaders,
591 PxTGSSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt, const PxReal totalDt, const PxReal invDt,
592 const PxReal invTotalDt, const PxReal lengthScale);
593
594 /**
595 \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.
596 \param [in] batchHeaders The set of batchHeaders to be processed
597 \param [in] nbBatchHeaders The number of batch headers to process.
598 \param [in] constraints The set of constraints to be used to produce constraint rows
599 \param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
600 \param [in] allocator An allocator callback to allocate constraint data
601 \param [in] dt The total time-step/nbPositionIterations
602 \param [in] totalDt The total time-step
603 \param [in] invDt The inverse (timestep/nbPositionIterations)
604 \param [in] invTotalDt The inverse total time-step
605 \param [in] lengthScale PxToleranceScale::length, i.e. a meter in simulation units
606 \return a boolean indicating if this method was successful or not.
607 @see PxCreateJointConstraints
608 */
609 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithShadersTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxConstraint** constraints, PxTGSSolverConstraintPrepDesc* jointDescs, PxConstraintAllocator& allocator, const PxReal dt,
610 const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal lengthScale);
611
612 /**
613 \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.
614 \param [in] batchHeaders The set of batchHeaders to be processed
615 \param [in] nbBatchHeaders The number of batch headers to process.
616 \param [in] constraints The set of constraints to be used to produce constraint rows
617 \param [in,out] jointDescs An array of constraint prep descs defining the properties of the constraints being created
618 \param [in] allocator An allocator callback to allocate constraint data
619 \param [in] dt The total time-step/nbPositionIterations
620 \param [in] totalDt The total time-step
621 \param [in] invDt The inverse (timestep/nbPositionIterations)
622 \param [in] invTotalDt The inverse total time-step
623 \param [in] lengthScale PxToleranceScale::length, i.e. a meter in simulation units
624 \return a boolean indicating if this method was successful or not.
625 @see PxCreateJointConstraints
626 */
627
628 PX_C_EXPORT PX_PHYSX_CORE_API bool PxCreateJointConstraintsWithImmediateShadersTGS(PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, PxImmediateConstraint* constraints, PxTGSSolverConstraintPrepDesc* jointDescs,
629 PxConstraintAllocator& allocator, const PxReal dt, const PxReal totalDt, const PxReal invDt, const PxReal invTotalDt, const PxReal lengthScale);
630
631
632 /**
633 \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.
634 \param [in] batchHeaders The set of batch headers to be solved
635 \param [in] nbBatchHeaders The total number of batch headers to be solved
636 \param [in] solverConstraintDescs The reordererd set of solver constraint descs referenced by the batch headers
637 \param [in,out] solverBodies The set of solver bodies the bodies reference
638 \param [in,out] txInertias The set of solver body TxInertias the bodies reference
639 \param [in] nbSolverBodies The total number of solver bodies
640 \param [in] nbPositionIterations The number of position iterations to run
641 \param [in] nbVelocityIterations The number of velocity iterations to run
642 \param [in] dt time-step/nbPositionIterations
643 \param [in] invDt 1/(time-step/nbPositionIterations)
644 \param [in] nbSolverArticulations Number of articulations to solve constraints for.
645 \param [in] solverArticulations Array of articulations to solve constraints for.
646 */
647 PX_C_EXPORT PX_PHYSX_CORE_API void PxSolveConstraintsTGS(const PxConstraintBatchHeader* batchHeaders, const PxU32 nbBatchHeaders, const PxSolverConstraintDesc* solverConstraintDescs,
648 PxTGSSolverBodyVel* solverBodies, PxTGSSolverBodyTxInertia* txInertias, const PxU32 nbSolverBodies, const PxU32 nbPositionIterations, const PxU32 nbVelocityIterations,
649 const float dt, const float invDt, const PxU32 nbSolverArticulations, Dy::ArticulationV** solverArticulations);
650
651 /**
652 \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.
653
654 \param [in,out] solverBody The array of solver bodies to be integrated
655 \param [in] txInertia The delta pose and inertia terms
656 \param [in,out] poses The original poses of the bodies. Updated to be the new poses of the bodies
657 \param [in] nbBodiesToIntegrate The total number of bodies to integrate
658 \param [in] dt The timestep
659 */
660 PX_C_EXPORT PX_PHYSX_CORE_API void PxIntegrateSolverBodiesTGS(PxTGSSolverBodyVel* solverBody, PxTGSSolverBodyTxInertia* txInertia, PxTransform* poses, const PxU32 nbBodiesToIntegrate, const PxReal dt);
661
662
663#if !PX_DOXYGEN
664}
665#endif
666
667#if !PX_DOXYGEN
668}
669#endif
670
671/** @} */
672#endif
673
674

source code of qtquick3dphysics/src/3rdparty/PhysX/include/PxImmediateMode.h