Atoms Crowd  7.0.0
PelvisOperator.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 
10 #include <AtomsGraph/Ports.h>
11 
12 #include <Atoms/Globals.h>
13 #include <Atoms/Graph/Operator.h>
14 #include <Atoms/HeightFields.h>
15 #include <AtomsUtils/Mesh.h>
16 #include <functional>
17 
18 namespace Atoms
19 {
20  class ATOMS_EXPORT PelvisOperator : public Operator
21  {
22  public:
23 
24  NODE_STANDARD_MEMBERS
25 
27 
28  virtual ~PelvisOperator();
29 
30  bool compute(const AtomsGraph::ComputeData* computeData);
31 
32  void reset();
33 
34  void computePelvisAndFeetHeightField(
35  AtomsCore::Vector3& jointRootWorldTranlsate,
36  AtomsCore::Quaternion& jointRootWorldRotate,
37  AtomsCore::Vector3& jointRootWorldScale,
38  const std::string& hf,
39  const std::string& gf,
40  HeightFields* hfManager,
41  const AtomsCore::Skeleton& skeleton,
42  AtomsCore::Vector3& upDirVec,
43  AtomsCore::Quaternion& initialRootRotation,
44  double heightFieldOffset,
45  bool compensateStretchLeg,
46  bool useHeightFieldOnCreationOnly);
47 
48  void computePelvisAndFeetHeightFieldInParentSpace(
49  AtomsCore::Vector3& jointRootWorldTranlsate,
50  AtomsCore::Quaternion& jointRootWorldRotate,
51  AtomsCore::Vector3& jointRootWorldScale,
52  const std::string& hf,
53  const std::string& gf,
54  HeightFields* hfManager,
55  const AtomsCore::Skeleton& skeleton,
56  AtomsCore::Vector3& upDirVec,
57  AtomsCore::Quaternion& initialRootRotation,
58  double heightFieldOffset,
59  bool compensateStretchLeg,
60  bool useHeightFieldOnCreationOnly);
61 
62  void computeSpinesHeightfields(
63  const std::string& hf,
64  const std::string& gf,
65  HeightFields* hfManager,
66  const AtomsCore::Skeleton& skeleton,
67  AtomsCore::Vector3& upDirVec,
68  double heightFieldOffset,
69  bool useHeightFieldOnCreationOnly);
70 
71  void computeSpinesHeightfieldsInParentSpace(
72  const std::string& hf,
73  const std::string& gf,
74  HeightFields* hfManager,
75  const AtomsCore::Skeleton& skeleton,
76  AtomsCore::Vector3& upDirVec,
77  double heightFieldOffset,
78  bool useHeightFieldOnCreationOnly);
79 
80  void compensateLegStretch(
81  AtomsCore::Vector3& jointRootWorldTranlsate,
82  AtomsCore::Quaternion& jointRootWorldRotate,
83  AtomsCore::Vector3& jointRootWorldScale,
84  const AtomsCore::Skeleton& skeleton,
85  AtomsCore::JointPose &rootPose,
86  Atoms::HeightField* hfMesh,
87  AtomsCore::Vector3& upDirVec,
88  double heightFieldOffset);
89 
90  void compensateLegStretchInParentSpace(
91  AtomsCore::Vector3& jointRootWorldTranlsate,
92  AtomsCore::Quaternion& jointRootWorldRotate,
93  AtomsCore::Vector3& jointRootWorldScale,
94  const AtomsCore::Skeleton& skeleton,
95  AtomsCore::JointPose &rootPose,
96  Atoms::HeightField* hfMesh,
97  AtomsCore::Vector3& upDirVec,
98  double heightFieldOffset);
99 
100  inline void useLocomotion(bool value) { m_isLocomotion = value; }
101 
102  inline void setNavMeshAdaptationCallback(std::function<bool(Atoms::Agent*, AtomsMath::Vector3*, double)>& callback) { m_navMeshAdaptationCallback = callback; }
103 
104  inline double groundHeight() { return m_groundHeight; }
105 
106  inline void setGroundHeight(double value) { m_groundHeight = value; }
107 
108  private:
109 
110  std::function<bool(Atoms::Agent*, AtomsMath::Vector3*, double)> m_navMeshAdaptationCallback;
111 
112  AtomsGraph::PosePort* m_inPose;
113  AtomsGraph::BooleanPort* m_useDirectionFromMetadataPort;
114  AtomsGraph::BooleanPort* m_useOnlyPositionPort;
115  AtomsGraph::BooleanPort* m_raycastGravityFieldPort;
116  AtomsGraph::VectorPort* m_directionPort;
117  AtomsGraph::DoublePort* m_heightFieldOffsetPort;
118  AtomsGraph::StringPort* m_heightFieldPort;
119  AtomsGraph::StringPort* m_gravityFieldPort;
120  AtomsGraph::BooleanPort* m_useHeightFieldOnCreationOnly;
121  AtomsGraph::DoublePort* m_particleAlignUpAxisTresholdAngle;
122  AtomsGraph::DoublePort* m_upVectorMaxAngle;
123  AtomsGraph::DoublePort* m_softIkDistance;
124  AtomsGraph::BooleanPort* m_sitAdaptationPort;
125  //AtomsGraph::BooleanPort* m_useHFAsGravityPort;
126 
127  AtomsGraph::BooleanPort* m_compensateLegStretchPort;
128 
129  AtomsGraph::BooleanPort* m_downCastOnly;
130  AtomsGraph::DoublePort* m_downCastOffset;
131 
132  AtomsCore::Vector3 m_pelvisCacheTranslation;
133  AtomsCore::Vector3 m_pelvisCacheVelocity;
134  AtomsCore::Quaternion m_pelvisCacheRotation;
135 
136  AtomsCore::Quaternion m_particleCacheRotation;
137  AtomsCore::Vector3 m_particleCacheUpVector;
138  AtomsCore::Vector3 m_particleCacheUnmodUpVector;
139  AtomsCore::Vector3 m_particleCacheDirectionVector;
140  AtomsCore::Vector3 m_particleCacheTranslation;
141  AtomsCore::Vector3 m_particleCacheVelocity;
142  AtomsCore::Vector3 m_previousParticleDirection;
143 
144  AtomsCore::Quaternion m_upDirRotation;
145 
146  double m_groundHeight;
147 
148  AtomsCore::Vector3 m_prevHfOffsetVariation;
149  AtomsCore::Vector3 m_previousDirection;
150 
151  AtomsCore::Vector3 m_staticGroundOffset;
152 
153  std::vector<unsigned int> m_footFrameAfterDown;
154  std::vector<unsigned int> m_footWasDown;
155  std::vector<AtomsCore::Matrix> m_detachedJointMatrices;
156 
157  AtomsPtr<AtomsCore::MapMetadata> m_hfAnimatedMetaMap;
158 
159  AtomsCore::Matrix m_animRootMtx;
160  AtomsCore::Vector3 m_animLocalVelocity;
161  AtomsCore::Vector3 m_animLocalUpVector;
162  AtomsCore::Vector3 m_animPrevUpVector;
163  AtomsCore::Vector3 m_virtualRootOffset;
164  AtomsCore::Matrix m_oldAnimFaceMtx;
165  double m_agentTypeHeight;
166  double m_animPointU;
167  double m_animPointV;
168  double m_virtualRootPelvisHeight;
169  int m_animPointFaceId;
170 
171  bool m_particleFirst;
172  bool m_pelvisFirst;
173  bool m_first;
174  bool m_hasCacheReader;
175  bool m_isLocomotion;
176  bool m_useVirtualRoot;
177 
178  public:
179 
180  static const std::string maxTurnAngleKey;
181  static const std::string ikSolverKey;
182  static const std::string ikTolleranceKey;
183  static const std::string ikMaxIterationsKey;
184 
185  static const std::string pelvisBehave3dCacheDirKey;
186  static const std::string pelvisBehave3dCacheUpKey;
187  };
188 }
Agent.
Definition: Agent.h:44
Container for all agent types.
Definition: HeightField.h:17
Container for all agent types.
Definition: HeightFields.h:19
Operator node.
Definition: Operator.h:26
Definition: PelvisOperator.h:21
void reset()
Operator reset function.
bool compute(const AtomsGraph::ComputeData *computeData)
Compute function.
Joint pose.
Definition: JointPose.h:20
Skeleton class.
Definition: Skeleton.h:68
Definition: Node.h:21
Generic node port class.
Definition: PortTemplate.h:24
AtomsMath::Quaternion Quaternion
Quaternion class.
Definition: AtomsMath.h:67
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Matrix Matrix
Matrix class.
Definition: AtomsMath.h:63
Atoms namespace.
Definition: Agent.h:29