10 #include <Atoms/Globals.h>
11 #include <AtomsCore/AtomsMath.h>
12 #include <Atoms/Physx/RigidBody.h>
13 #include <Atoms/Physx/RigidBodyConstraint.h>
15 #include <unordered_map>
22 class PxDefaultCpuDispatcher;
30 class PxCudaContextManager;
35 class ContactFilterCallback;
36 class ContactModifyCallback;
37 class AtomsCCDContactModification;
45 std::unordered_map<int, std::vector<int>> aggregates;
46 std::unordered_map<int, bool> aggregateEnableCollisions;
77 bool isValid()
const {
return m_physics !=
nullptr; }
87 void updateKinematics(
float stepSize);
89 void updateDynamicPool(
float stepSize);
91 void updateKinematicAgents(
float stepSize);
93 void updatedForces(
float stepSize);
97 void clearFeedbacks();
99 void storeTransforms();
105 void updateConstraints();
107 void createLazyData();
109 void createDynamicConstraintData();
111 void updateForceCollisionThreshold();
117 const std::string& pvdHost()
const;
119 void setPvdHost(
const std::string& host);
123 void setPvdPort(
int value);
125 unsigned int pvdTimeout()
const;
127 void setPvdTimeout(
unsigned int value);
134 void setFps(
double value);
136 unsigned int subSamples()
const;
138 void setSubSamples(
unsigned int value);
140 double scale()
const;
142 void setScale(
double value);
148 void enablePvd(
bool value);
150 bool isPvdEnabled()
const;
152 bool isInitialized()
const;
154 unsigned int threadsNumber()
const;
156 void setThreadsNumber(
unsigned int value);
158 void setFrictionOffsetThreshold(
double value);
160 void setCcdMaxSeparation(
double value);
162 void setSolverOffsetSlop(
double value);
164 void setBounceThresholdVelocity(
double value);
166 short solverType()
const;
168 void setSolverType(
short value);
170 void setKinematicKinematicFilter(
bool value);
172 void setStaticKinematicFilter(
bool value);
176 void setUseGpu(
bool value);
178 bool enableStabilization()
const;
180 void setEnableStabilization(
bool value);
182 bool enableEnhancedDeterminism()
const;
184 void setEnableEnhancedDeterminism(
bool value);
186 bool enableFrictionEveryIteration()
const;
188 void setEnableFrictionEveryIteration(
bool value);
190 bool enablePCM()
const;
192 void setEnablePCM(
bool value);
194 bool enableAdaptiveForce()
const;
196 void setEnableAdaptiveForce(
bool value);
198 bool enableCCD()
const;
200 void setEnableCCD(
bool value);
202 double elapsedTime()
const;
205 RigidBody* addRigidBody(
206 const std::string& name,
207 const RigidBodyAttributes& attributes,
209 bool lazyCreation =
false);
215 std::unordered_map<size_t, RigidBody>& rigidBodies();
217 const RigidBody* rigidBody(
size_t id)
const;
219 const std::unordered_map<size_t, RigidBody>& rigidBodies()
const;
221 const std::unordered_map<size_t, std::string>& rigidBodyNames()
const;
223 const std::map<std::string, size_t>& rigidBodyNameIds()
const;
225 std::map<std::string, RigidBodyConstraint>& constraints();
227 const std::map<std::string, RigidBodyConstraint>& constraints()
const;
229 const std::map<std::pair<size_t, size_t>, std::string>& constraintNames()
const;
231 physx::PxRigidActor* createPhysicObject(
size_t id,
const RigidBodyAttributes& attributes, physx::PxGeometry* geo,
const physx::PxTransform* shapeOffset);
233 physx::PxRigidActor* createRigidBody(
size_t id,
const RigidBodyAttributes& attributes,
AtomsUtils::Mesh* mesh=
nullptr);
235 void setupDynamicAttributes(physx::PxRigidDynamic* rigid,
const RigidBodyAttributes& attributes)
const;
237 void setupKinematicAttributes(physx::PxRigidDynamic* rigid,
const RigidBodyAttributes& attributes)
const;
239 void updateRigidBodyMeshPoints(RigidBody& rb,
const std::vector<AtomsCore::Vector3f>& newPoints);
243 RigidBodyConstraint* addRigidBodyConstraint(
244 const std::string& name,
245 const RigidBodyConstraintAttributes& attributes,
250 RigidBodyConstraint* addRigidBodyConstraint(
251 const std::string& name,
252 const RigidBodyConstraintAttributes& attributes,
257 bool lazyCreation =
false);
259 RigidBodyConstraint* addRigidBodyDynamicConstraint(
260 const std::string& name,
261 const RigidBodyConstraintAttributes& attributes,
267 physx::PxJoint* createRigidBodyConstraint(
268 const RigidBodyConstraintAttributes& attributes,
269 physx::PxRigidActor* first,
270 physx::PxTransform& firstMatrix,
271 physx::PxRigidActor* second,
272 physx::PxTransform& secondMatrix);
275 const std::unordered_map<
int, std::vector<int>> &aggregates,
276 const std::unordered_map<int, bool> &aggregateEnableCollisions,
278 bool lazyCreation =
false);
280 void removeRigidBody(
size_t id);
282 void removeConstraint(
const std::string& name);
286 AtomsPhysx(
const AtomsPhysx&) =
delete;
287 AtomsPhysx& operator=(
const AtomsPhysx&) =
delete;
289 AtomsPhysx(
const AtomsPhysx&);
290 AtomsPhysx& operator=(
const AtomsPhysx&);
294 std::unordered_map<size_t, RigidBody> m_rbs;
296 std::unordered_map<size_t, std::string> m_rbNames;
298 std::map<std::string, size_t> m_rbNameIds;
300 std::map<std::string, RigidBodyConstraint> m_constraints;
302 std::map<std::pair<size_t, size_t>, std::string> m_constraintNames;
304 std::vector<physx::PxAggregate *> m_aggregates;
306 std::vector<physx::PxHeightField*> m_heigthFields;
308 physx::PxFoundation* m_foundation;
310 physx::PxPhysics* m_physics;
312 physx::PxCooking* m_cooking;
314 physx::PxCudaContextManager* m_cudaContextManager;
316 physx::PxDefaultCpuDispatcher* m_dispatcher;
318 physx::PxScene* m_scene;
322 std::string m_pvdHost;
326 unsigned int m_pvdTimeout;
330 unsigned int m_subSamples;
338 unsigned int m_maxThreads;
340 double m_frictionOffsetThreshold;
342 double m_ccdMaxSeparation;
344 double m_solverOffsetSlop;
346 double m_bounceThresholdVelocity;
350 bool m_isInitialized;
354 bool m_filterKinematicKinematicCollision;
356 bool m_filterStaticKinematicCollision;
358 std::atomic<size_t> m_freeId;
360 AtomsUPtr<ContactFilterCallback> m_contactFilterCallback;
362 AtomsUPtr<ContactModifyCallback> m_contactModifyCallback;
364 AtomsUPtr<AtomsCCDContactModification> m_ccdContactModifyCallback;
366 mutable std::mutex m_mutex;
368 std::map<size_t, LazyAggregateData> m_lazyAggregates;
370 std::map<std::string, LazyRigidBodyData> m_lazyRigidBodies;
372 std::map<std::string, LazyRigidBodyConstraintData> m_lazyConstraints;
374 std::map<size_t, physx::PxMaterial*> m_lazyMaterials;
378 bool m_enableStabilization;
380 bool m_enableEnhancedDeterminism;
382 bool m_enableFrictionEveryIteration;
386 bool m_enableAdaptiveForce;
390 double m_elapsedTime;
Definition: AtomsPhysx.h:40
Definition: RigidBody.h:40
Definition: RigidBodyConstraint.h:23
Definition: RigidBody.h:155
Mesh class.
Definition: Mesh.h:30
AtomsMath::Matrixf Matrixf
Matrix class.
Definition: AtomsMath.h:64
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Vector3f Vector3f
Vector3 class.
Definition: AtomsMath.h:58
AtomsMath::Quaternionf Quaternionf
Quaternion class.
Definition: AtomsMath.h:68
Atoms namespace.
Definition: Agent.h:29
Definition: AtomsPhysx.h:44
Definition: AtomsPhysx.h:57
Definition: AtomsPhysx.h:50