RavEngine
Loading...
Searching...
No Matches
ScArticulationSim.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 SC_ARTICULATION_SIM_H
30#define SC_ARTICULATION_SIM_H
31
32#include "foundation/PxUserAllocated.h"
33#include "ScArticulationCore.h"
34#include "PxsSimpleIslandManager.h"
35#include "DyArticulationTendon.h"
36
37namespace physx
38{
39namespace Bp
40{
41 class BoundsArray;
42}
43
44namespace Sc
45{
46 class BodySim;
47 class ArticulationJointSim;
48 class ArticulationSpatialTendonSim;
49 class ArticulationFixedTendonSim;
50 class ArticulationSensorSim;
51 class ArticulationCore;
52 class Scene;
53 class ConstraintSim;
54
56 {
57 enum Enum
58 {
59 eNONE = 0,
60 eUPDATE = 1 << 0
61 };
62 };
63
65
66
68 {
69 public:
71 Scene& scene,
72 BodyCore& root);
73
75
76 PX_FORCE_INLINE Dy::FeatherstoneArticulation* getLowLevelArticulation() const { return mLLArticulation; }
77 PX_FORCE_INLINE ArticulationCore& getCore() const { return mCore; }
78
79 //we don't need removeBody method anymore because when the articulation is removed from the scene, the articulation sim will
80 //get completely distroy and when we re-add the articulation to the scene, all the data will get recomputed
81 void addBody(BodySim& body,
82 BodySim* parent,
84
85 void removeBody(BodySim& body);
86
87
88 //we don't need removeTendon method anymore because when the articulation is removed from the scene, the articulation sim will
89 //get completely distroy and when we re-add the articulation to the scene, all the data will get recomputed
90 void addTendon(ArticulationSpatialTendonSim*);
91
92 //we don't need removeTendon method anymore because when the articulation is removed from the scene, the articulation sim will
93 //get completely distroy and when we re-add the articulation to the scene, all the data will get recomputed
94 void addTendon(ArticulationFixedTendonSim*);
95
96 //we don't need removeSensor method anymore because when the articulation is removed from the scene, the articulation sim will
97 //get completely distroy and when we re-add the articulation to the scene, all the data will get recomputed
98 void addSensor(ArticulationSensorSim* sensor, const PxU32 linkID);
99
100 void createLLStructure(); // resize LL memory if necessary
101 void initializeConfiguration();
102 void debugCheckWakeCounterOfLinks(PxReal wakeCounter) const;
103 void debugCheckSleepStateOfLinks(bool isSleeping) const;
104
105 bool isSleeping() const;
106 void internalWakeUp(PxReal wakeCounter); // called when sim sets sleep timer
107 void sleepCheck(PxReal dt);
108 void putToSleep();
109 void updateCCDLinks(PxArray<BodySim*>& sims);
110 void updateCached(PxBitMapPinned* shapehapeChangedMap);
111 void markShapesUpdated(PxBitMapPinned* shapeChangedMap);
112 void updateContactDistance(PxReal* contactDistance, const PxReal dt, const Bp::BoundsArray& boundsArray);
113
114 void setActive(const bool b, const PxU32 infoFlag=0);
115
116 void updateForces(PxReal dt, bool notify = true);
117 void saveLastCCDTransform();
118
119 void clearAcceleration(PxReal dt);
120
121
122 void setKinematicLink(const bool value);
123 //external reduced coordinate implementation
124 PxU32 getDofs() const;
125
126 //This function return the dof of the inbound joint, which belong to a link with corresponding linkID
127 PxU32 getDof(const PxU32 linkID) const;
128
129 PxArticulationCache* createCache();
130
131 PxU32 getCacheDataSize() const;
132
133 PxU32 getScratchMemorySize() const;
134
135 void zeroCache(PxArticulationCache&) const;
136
137 bool applyCache(PxArticulationCache& cache, const PxArticulationCacheFlags flag) const;
138
139 void copyInternalStateToCache(PxArticulationCache& cache, const PxArticulationCacheFlags flag) const;
140
141 void packJointData(const PxReal* maximum, PxReal* reduced) const;
142
143 void unpackJointData(const PxReal* reduced, PxReal* maximum) const;
144
145 void commonInit();
146
147 void computeGeneralizedGravityForce(PxArticulationCache& cache);
148
149 void computeCoriolisAndCentrifugalForce(PxArticulationCache& cache);
150
151 void computeGeneralizedExternalForce(PxArticulationCache& cache);
152
153 void computeJointAcceleration(PxArticulationCache& cache);
154
155 void computeJointForce(PxArticulationCache& cache);
156
157 void computeKinematicJacobian(const PxU32 linkID, PxArticulationCache& cache);
158
159 void computeDenseJacobian(PxArticulationCache& cache, PxU32& nRows, PxU32& nCols);
160
161 void computeCoefficientMatrix(PxArticulationCache& cache);
162
163 bool computeLambda(PxArticulationCache& cache, PxArticulationCache& rollBackCache, const PxReal* jointTorque, const PxVec3 gravity, const PxU32 maxIter);
164
165 void computeGeneralizedMassMatrix(PxArticulationCache& cache);
166
167 PxU32 getCoefficientMatrixSize() const;
168
169 void setRootLinearVelocity(const PxVec3& velocity);
170 void setRootAngularVelocity(const PxVec3& velocity);
171 PxSpatialVelocity getLinkVelocity(const PxU32 linkId) const;
172
173 PxSpatialVelocity getLinkAcceleration(const PxU32 linkId) const;
174
175
176 //internal method implementation
177 PX_FORCE_INLINE PxNodeIndex getIslandNodeIndex() const { return mIslandNodeIndex; }
178
179 void setGlobalPose();
180
181 PxU32 findBodyIndex(BodySim &body) const;
182
183 void setJointDirty(Dy::ArticulationJointCore& jointCore);
184
185 void addLoopConstraint(ConstraintSim* constraint);
186 void removeLoopConstraint(ConstraintSim* constraint);
187
188 PX_FORCE_INLINE PxU32 getMaxDepth() { return mMaxDepth; }
189
190 void setArticulationDirty(PxU32 flag);
191
192 PX_FORCE_INLINE void setDirtyFlag(ArticulationSimDirtyFlag::Enum flag) { mDirtyFlags = flag; }
193 PX_FORCE_INLINE ArticulationSimDirtyFlags getDirtyFlag() const { return mDirtyFlags; }
194
195 PX_FORCE_INLINE const Dy::ArticulationLink& getLink(const PxU32 linkId) const { return mLinks[linkId]; }
196
197 PxU32 getRootActorIndex() const;
198 const PxSpatialForce& getSensorForce(const PxU32 lowLevelIndex) const;
199
200
201
202 void updateKinematic(PxArticulationKinematicFlags flags);
203
204 void copyJointStatus(const PxU32 linkIndex);
205
206 PX_FORCE_INLINE void getLLArticulationInitialized(bool val) { mIsLLArticultionInitialized = val; }
207 PX_FORCE_INLINE bool getLLArticulationInitialized() { return mIsLLArticultionInitialized; }
208 private:
209 ArticulationSim& operator=(const ArticulationSim&);
210
211 Dy::FeatherstoneArticulation* mLLArticulation;
212 Scene& mScene;
213 ArticulationCore& mCore;
215 PxArray<BodySim*> mBodies;
220 PxArray<PxSpatialForce> mSensorForces;
221
222
223 PxNodeIndex mIslandNodeIndex;
224 PxArray <Dy::ArticulationLoopConstraint> mLoopConstraints;
225 PxU32 mMaxDepth;
226 bool mIsLLArticultionInitialized;
227 ArticulationSimDirtyFlags mDirtyFlags;
228
229 };
230
231} // namespace Sc
232
233}
234
235#endif
Definition BpAABBManagerBase.h:101
Definition DyFeatherstoneArticulation.h:590
Definition PxArray.h:53
Data structure used to read and write internal articulation data.
Definition PxArticulationReducedCoordinate.h:99
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
PxNodeIndex.
Definition PxNodeIndex.h:51
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition ScArticulationCore.h:52
Definition ScArticulationTendonSim.h:85
Definition ScArticulationJointSim.h:42
Definition ScArticulationSensorSim.h:46
Definition ScArticulationSim.h:68
Definition ScArticulationTendonSim.h:49
Definition ScBodyCore.h:49
Definition ScBodySim.h:60
Definition ScConstraintSim.h:48
Definition ScScene.h:240
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition DyArticulationJointCore.h:44
Data structure to represent spatial forces.
Definition PxArticulationReducedCoordinate.h:53
Data structure to represent spatial velocities.
Definition PxArticulationReducedCoordinate.h:66
Definition ScArticulationSim.h:56