Atoms Crowd  7.0.0
RagdollOperator.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 #ifndef ATOMS_UNREAL
10 #include <AtomsGraph/Ports.h>
11 
12 #include <Atoms/Globals.h>
13 #include <Atoms/Graph/Operator.h>
14 #include <AtomsCore/Joint.h>
15 #include <AtomsUtils/Utils.h>
16 #include <Atoms/Physx/RigidBodyConstraint.h>
17 #include <Atoms/HeightField.h>
18 
19 namespace Atoms
20 {
21  class AtomsPhysx;
22  class RigidBody;
23  class RigidBodyConstraint;
24 
25  class ATOMS_EXPORT RagdollOperator : public Operator
26  {
27  public:
28 
29  enum Mode
30  {
31  kNone = 0,
32  kStatic,
33  kKinematic,
34  kRagdoll,
35  kPartialRagdoll,
36  kMotorRagdoll,
37  kPartialMotorRagdoll
38  };
39 
41  {
42  public:
43  ConstraintData() : constraint(nullptr) {}
44  RigidBodyConstraint* constraint;
45  AtomsCore::Matrix matrix;
46  AtomsCore::Matrix drivePose;
48  };
49 
50  class JointData
51  {
52  public:
53  JointData():
54  rigidBody(nullptr),
55  scale(1.0, 1.0, 1.0)
56  {
57  }
58  RigidBody* rigidBody;
59  AtomsCore::Matrix jointOffset;
60  AtomsCore::Matrix jointOffsetInverse;
61  std::map<size_t, ConstraintData> constraints;
62  AtomsCore::Vector3 scale;
63  };
64 
65  NODE_STANDARD_MEMBERS
66 
68 
69  virtual ~RagdollOperator();
70 
71  bool compute(const AtomsGraph::ComputeData* computeData);
72 
73  void updateDynamics();
74 
75  void reset();
76 
77  inline void setPhysics(AtomsPhysx* physx) { m_physx = physx; }
78 
79  inline const std::map<size_t, JointData>& rbs() const { return m_rbs; }
80  inline std::map<size_t, JointData>& rbs() { return m_rbs; }
81 
82  inline void setRagdollSetup(const std::string& value) { m_ragdollSetup = value; }
83 
84  inline void setPartialRagdollFilter(const std::string& value)
85  {
86  auto clearString = AtomsUtils::eraseFromString(value, ' ');
87  AtomsUtils::splitString(clearString, ',', m_partialRagdollFilter);
88  }
89 
90  inline void setDynamicOnCollision(int value) { m_dynamicOnCollision = value; }
91 
92  inline void setCollisionForceThreshold(double value) { m_collisionForceThreshold = value; }
93 
94  inline void setMotorRagdollDamping(double value) { m_motorRagdollDamping = value; }
95 
96  inline void setMotorRagdollStiffness(double value) { m_motorRagdollStiffness = value; }
97 
98  inline void setBreakable(int value) { m_breakable = value; }
99 
100  inline void setBreakableFilter(const std::string& value)
101  {
102  auto clearString = AtomsUtils::eraseFromString(value, ' ');
103  AtomsUtils::splitString(clearString, ',', m_breakableFilter);
104  }
105 
106  inline void setAnimationBlending(double value) { m_animationBlending = value; }
107 
108  inline void setStuckOnCollision(bool value) { m_stuckOnCollision = value; }
109 
110  inline void setPartialRagdollSkipChildren(bool value) { m_partialRagdollSkipChildren = value; }
111 
112  inline void setMotorRagdollAcceleration(short value) { m_motorRagdollAcceleration = value; }
113 
114  inline void setMotorRagdollMaxForce(double value) { m_motorRagdollMaxForce = value; }
115 
116  inline void setBreakForce(const AtomsCore::Vector2& value) { m_breakForce = value; }
117 
118  inline void setSelfCollision(bool value) { m_selfCollision = value; }
119 
120  inline void setMode(short value) { m_mode = value; }
121 
122  void updateKinematic(double value);
123 
124  void setDynamicSwitchOnChildren(const AtomsCore::Joint* joint);
125 
126  inline void setHeightField(const std::string& value) { m_heightField = value; }
127 
128  inline void setGravityField(const std::string& value) { m_gravityField = value; }
129 
130  inline void setStuckOnCollisionBreakForce(const AtomsCore::Vector2& value) { m_stuckOnCollisionBreakForce = value; }
131 
132  inline const std::vector<size_t>& rbsOrder() const { return m_rbsOrder; }
133 
134  inline void setDynamicOnCollisionFilter(const std::string& value)
135  {
136  auto clearString = AtomsUtils::eraseFromString(value, ' ');
137  AtomsUtils::splitString(clearString, ',', m_dynamicOnCollisionFilter);
138  }
139 
140  inline void setStuckOnCollisionImpulse(double value) { m_stuckOnCollisionImpulse = value; }
141 
142  inline void setCollisionPool(int value) { m_collisionPool = value; }
143 
144  inline void setDynamicOnCollisionPool(int value) { m_dynamicOnCollisionPool = value; }
145 
146  inline void setStuckOnCollisionPool(int value) { m_stuckOnCollisionPool = value; }
147 
148  inline void setAddContactData(bool value) { m_addContactData = value; }
149 
150  private:
151 
152  AtomsGraph::PosePort* m_inPose;
153 
154  AtomsPhysx* m_physx;
155 
156  bool m_init;
157 
158  std::map<size_t, JointData> m_rbs;
159 
160  std::vector<size_t> m_rbsOrder;
161 
162  AtomsCore::Pose pose;
163 
164  short m_prevMode;
165 
166  short m_mode;
167 
168  short m_currentMode;
169 
170  std::string m_ragdollSetup;
171 
172  std::vector<std::string> m_partialRagdollFilter;
173 
174  std::map<size_t, size_t> m_partialRagdollSetup;
175 
176  int m_dynamicOnCollision;
177 
178  std::vector<std::string> m_dynamicOnCollisionFilter;
179 
180  double m_collisionForceThreshold;
181 
182  double m_motorRagdollDamping;
183 
184  double m_motorRagdollStiffness;
185 
186  short m_motorRagdollAcceleration;
187 
188  double m_motorRagdollMaxForce;
189 
190  AtomsCore::Vector2 m_breakForce;
191 
192  int m_breakable;
193 
194  std::vector<std::string> m_breakableFilter;
195 
196  double m_animationBlending;
197 
198  bool m_stuckOnCollision;
199 
200  double m_stuckOnCollisionImpulse;
201 
202  AtomsCore::Vector2 m_stuckOnCollisionBreakForce;
203 
204  bool m_partialRagdollSkipChildren;
205 
206  bool m_inRestPose;
207 
208  bool m_selfCollision;
209 
210  std::string m_heightField;
211 
212  std::string m_gravityField;
213 
214  Atoms::HeightField* hfPtr;
215  Atoms::HeightField* gfPtr;
216 
217  int m_collisionPool;
218 
219  int m_dynamicOnCollisionPool;
220 
221  int m_stuckOnCollisionPool;
222 
223  bool m_addContactData;
224  };
225 }
226 #endif
Definition: AtomsPhysx.h:40
Container for all agent types.
Definition: HeightField.h:17
Operator node.
Definition: Operator.h:26
Definition: RagdollOperator.h:41
Definition: RagdollOperator.h:51
Definition: RagdollOperator.h:26
bool compute(const AtomsGraph::ComputeData *computeData)
Compute function.
void reset()
Operator reset function.
Definition: RigidBodyConstraint.h:78
Definition: RigidBodyConstraint.h:216
Definition: RigidBody.h:155
Joint class.
Definition: Joint.h:30
Pose class.
Definition: Pose.h:32
Definition: Node.h:21
Generic node port class.
Definition: PortTemplate.h:24
AtomsMath::Vector2 Vector2
Vector2 class.
Definition: AtomsMath.h:54
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Matrix Matrix
Matrix class.
Definition: AtomsMath.h:63
Atoms namespace.
Definition: Agent.h:29