PeriDyno 1.0.0
Loading...
Searching...
No Matches
JointInfo.h
Go to the documentation of this file.
1
2#pragma once
3#include <vector>
4#include <memory>
5#include <string>
6#include "Vector.h"
7#include "OBase.h"
8#include "Module.h"
9
10
11namespace dyno {
12
13 struct Pose
14 {
15 Pose() {}
16
17 Pose(std::vector<Vec3f> t, std::vector<Vec3f> s, std::vector<Quat1f> r)
18 {
19 mTranslation = t;
20 mRotation = r;
21 mScale = s;
22 }
23
25 {
26 mTranslation.clear();
27 mScale.clear();
28 mRotation.clear();
29 }
30
31 int size() { return mTranslation.size(); }
32
33 void resize(int s)
34 {
35 mTranslation.resize(s);
36 mRotation.resize(s);
37 mScale.resize(s);
38 };
39
40 std::vector<Vec3f> mTranslation;
41 std::vector<Quat1f> mRotation;
42 std::vector<Vec3f> mScale;
43 };
44
45 class JointInfo : public OBase
46 {
47 typedef int joint;
48
49 public:
50
52
54 DArray<Mat4f>& InverseBindMatrix,
55 DArray<Mat4f>& LocalMatrix,
56 DArray<Mat4f>& WorldMatrix,
57 std::vector<int>& allJoints,
58 std::map<joint, std::vector<joint>>& jointDir,
59 std::map<joint, Vec3f>& bindPoseTranslation,
60 std::map<joint, Vec3f>& bindPoseScale,
61 std::map<joint, Quat1f>& bindPoseRotation
62 );
63
65
67 DArray<Mat4f>& InverseBindMatrix,
68 DArray<Mat4f>& LocalMatrix,
69 DArray<Mat4f>& WorldMatrix,
70 std::vector<int>& allJoints,
71 std::map<joint, std::vector<joint>>& jointDir,
72 std::map<joint, Vec3f>& bindPoseTranslation,
73 std::map<joint, Vec3f>& bindPoseScale,
74 std::map<joint, Quat1f>& bindPoseRotation
75 );
76
77 void setJoint(const JointInfo& j);
78
79 bool isEmpty();
80
82
83 void updateCurrentPose(std::map<joint, Vec3f> t, std::map<joint, Vec3f> s, std::map<joint, Quat1f> r);
84
85 void setJointName(const std::map<int,std::string> name) { this->mJointName = name; }
86
87 void setPose(Pose pose)
88 {
90 mCurrentRotation.assign(pose.mRotation);
91 mCurrentScale.assign(pose.mScale);
92
94
95 };
96
97 public:
98
99 std::map<int, std::string> mJointName;
100
104
105 std::vector<Vec3f> mBindPoseTranslation;
106 std::vector<Vec3f> mBindPoseScale;
107 std::vector<Quat<Real>> mBindPoseRotation;
108
109 //动画:
110
114
115 std::vector<joint> mAllJoints;
116 std::map<joint, std::vector<joint>> mJointDir;
117
118 int mMaxJointID = -1;
119 };
120
121
123 {
124 //这个结构要在开始时候直接把所有动画数据读入内存,供给动画状态机使用。
125 typedef int joint;
126
127 public:
128
130
132
134 std::map<joint, std::vector<Vec3f>>& jointTranslation,
135 std::map<joint, std::vector<Real>>& jointTimeCodeTranslation,
136 std::map<joint, std::vector<Vec3f>>& jointScale,
137 std::map<joint, std::vector<Real>>& jointIndexTimeCodeScale,
138 std::map<joint, std::vector<Quat1f>>& jointRotation,
139 std::map<joint, std::vector<Real>>& jointIndexRotation,
140 std::shared_ptr<JointInfo> skeleton
141 );
142
143
144 void updateJointsTransform(float time);
145
147
148 std::vector<Vec3f> getJointsTranslation(float time);
149
150 std::vector<Quat1f> getJointsRotation(float time);
151
152 std::vector<Vec3f> getJointsScale(float time);
153
154 float getTotalTime() { return mTotalTime; }
155
156 int findMaxSmallerIndex(const std::vector<float>& arr, float v);
157
158 Vec3f lerp(Vec3f v0, Vec3f v1, float weight);
159
161
162 Quat<Real> slerp(const Quat<Real>& q1, const Quat<Real>& q2, float weight);
163
164 Quat<Real> nlerp(const Quat<Real>& q1, const Quat<Real>& q2, float weight);
165
166 std::vector<int> getJointDir(int Index, std::map<int, std::vector<int>> joint_Dir);
167
168 void setLoop(bool loop) { mLoop = loop; }
169
170 Pose getPose(float inTime);
171
172 void updateAnimationPose(float inTime){
173
174 auto pose = this->getPose(inTime);
175 mSkeleton->setPose(pose);
176
177 };
178
180
181 float& getBlendInTime() { return mBlendInTime; }
182
183 float& getBlendOutTime() { return mBlendOutTime; }
184
185 float& getPlayRate() { return mPlayRate; }
186
187 public:
188
189 std::shared_ptr<JointInfo> mSkeleton = NULL;
190
191 //动画及时间戳
192 std::map<joint, std::vector<Vec3f>> mJoint_Index_Translation;
193 std::map<joint, std::vector<Real>> mJoint_Index_TimeCode_Translation;
194
195 std::map<joint, std::vector<Vec3f>> mJoint_Index_Scale;
196 std::map<joint, std::vector<Real>> mJoint_Index_TimeCode_Scale;
197
198 std::map<joint, std::vector<Quat1f>> mJoint_Index_Rotation;
199 std::map<joint, std::vector<Real>> mJoint_Index_TimeCode_Rotation;
200
201 private:
202 //当前时间下的动画数据,在某些情况下仅记录三维软件中具有动画变化的骨骼
203 std::vector<Vec3f> mTranslation;
204 std::vector<Vec3f> mScale;
205 std::vector<Quat1f> mRotation;
206
208
209 float mTotalTime = 0;
210
211 float currentTime = -1;
212
213 bool mLoop = true;
214 float mBlendInTime = 0.0f;
215 float mBlendOutTime = 0.0f;
216 float mPlayRate = 1.0f;
217
218 float mAnimationTime = 0.0f;
219
220 };
221
222
223
224
225
226
227}
228
int findMaxSmallerIndex(const std::vector< float > &arr, float v)
std::vector< Vec3f > getJointsScale(float time)
Quat< Real > nlerp(const Quat< Real > &q1, const Quat< Real > &q2, float weight)
std::vector< Vec3f > mScale
Definition JointInfo.h:204
void setLoop(bool loop)
Definition JointInfo.h:168
std::map< joint, std::vector< Quat1f > > mJoint_Index_Rotation
Definition JointInfo.h:198
void setAnimationData(std::map< joint, std::vector< Vec3f > > &jointTranslation, std::map< joint, std::vector< Real > > &jointTimeCodeTranslation, std::map< joint, std::vector< Vec3f > > &jointScale, std::map< joint, std::vector< Real > > &jointIndexTimeCodeScale, std::map< joint, std::vector< Quat1f > > &jointRotation, std::map< joint, std::vector< Real > > &jointIndexRotation, std::shared_ptr< JointInfo > skeleton)
std::vector< Quat1f > getJointsRotation(float time)
std::vector< int > getJointDir(int Index, std::map< int, std::vector< int > > joint_Dir)
Quat< Real > slerp(const Quat< Real > &q1, const Quat< Real > &q2, float weight)
std::vector< Vec3f > getJointsTranslation(float time)
void updateJointsTransform(float time)
std::map< joint, std::vector< Real > > mJoint_Index_TimeCode_Scale
Definition JointInfo.h:196
std::map< joint, std::vector< Vec3f > > mJoint_Index_Translation
Definition JointInfo.h:192
std::shared_ptr< JointInfo > mSkeleton
Definition JointInfo.h:189
std::map< joint, std::vector< Real > > mJoint_Index_TimeCode_Rotation
Definition JointInfo.h:199
void updateAnimationPose(float inTime)
Definition JointInfo.h:172
Pose getPose(float inTime)
std::map< joint, std::vector< Vec3f > > mJoint_Index_Scale
Definition JointInfo.h:195
Transform3f updateTransform(joint jId, float time)
Vec3f lerp(Vec3f v0, Vec3f v1, float weight)
DArray< Mat4f > mJointWorldMatrix
Definition JointInfo.h:207
std::vector< Quat1f > mRotation
Definition JointInfo.h:205
std::map< joint, std::vector< Real > > mJoint_Index_TimeCode_Translation
Definition JointInfo.h:193
std::vector< Vec3f > mTranslation
Definition JointInfo.h:203
Quat< Real > normalize(const Quat< Real > &q)
void updateWorldMatrixByTransform()
DArray< Mat4f > mJointLocalMatrix
Definition JointInfo.h:102
DArray< Mat4f > mJointInverseBindMatrix
Definition JointInfo.h:101
void setJoint(const JointInfo &j)
std::map< joint, std::vector< joint > > mJointDir
Definition JointInfo.h:116
std::vector< Vec3f > mBindPoseScale
Definition JointInfo.h:106
std::vector< joint > mAllJoints
Definition JointInfo.h:115
DArray< Mat4f > mJointWorldMatrix
Definition JointInfo.h:103
std::vector< Quat< Real > > mBindPoseRotation
Definition JointInfo.h:107
void setPose(Pose pose)
Definition JointInfo.h:87
DArray< Vec3f > mCurrentScale
Definition JointInfo.h:113
std::map< int, std::string > mJointName
Definition JointInfo.h:99
JointInfo(DArray< Mat4f > &InverseBindMatrix, DArray< Mat4f > &LocalMatrix, DArray< Mat4f > &WorldMatrix, std::vector< int > &allJoints, std::map< joint, std::vector< joint > > &jointDir, std::map< joint, Vec3f > &bindPoseTranslation, std::map< joint, Vec3f > &bindPoseScale, std::map< joint, Quat1f > &bindPoseRotation)
std::vector< Vec3f > mBindPoseTranslation
Definition JointInfo.h:105
void updateCurrentPose(std::map< joint, Vec3f > t, std::map< joint, Vec3f > s, std::map< joint, Quat1f > r)
void setJointName(const std::map< int, std::string > name)
Definition JointInfo.h:85
DArray< Quat< Real > > mCurrentRotation
Definition JointInfo.h:112
void UpdateJointInfo(DArray< Mat4f > &InverseBindMatrix, DArray< Mat4f > &LocalMatrix, DArray< Mat4f > &WorldMatrix, std::vector< int > &allJoints, std::map< joint, std::vector< joint > > &jointDir, std::map< joint, Vec3f > &bindPoseTranslation, std::map< joint, Vec3f > &bindPoseScale, std::map< joint, Quat1f > &bindPoseRotation)
DArray< Vec3f > mCurrentTranslation
Definition JointInfo.h:111
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
Transform< float, 3 > Transform3f
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
std::vector< Quat1f > mRotation
Definition JointInfo.h:41
Pose(std::vector< Vec3f > t, std::vector< Vec3f > s, std::vector< Quat1f > r)
Definition JointInfo.h:17
std::vector< Vec3f > mScale
Definition JointInfo.h:42
int size()
Definition JointInfo.h:31
void resize(int s)
Definition JointInfo.h:33
std::vector< Vec3f > mTranslation
Definition JointInfo.h:40