-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationComponent.h
More file actions
126 lines (95 loc) · 3.3 KB
/
AnimationComponent.h
File metadata and controls
126 lines (95 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include"GltfModelComponent.h"
#include"GpuBufferFactory.h"
#include"DescriptorSetFactory.h"
//ノードごとのトランスフォームを記録
struct NodeTransform
{
std::vector<glm::vec3> translation;
std::vector<glm::quat> rotation;
std::vector<glm::vec3> scale;
std::vector<glm::mat4> matrix;
std::vector<glm::mat4> nodeTransform;
void setNodeCount(int nodeCount)
{
translation.resize(nodeCount);
rotation.resize(nodeCount);
scale.resize(nodeCount);
matrix.resize(nodeCount);
nodeTransform.resize(nodeCount);
std::fill(translation.begin(), translation.end(), glm::vec3(0.0f));
std::fill(rotation.begin(), rotation.end(), glm::quat());
std::fill(scale.begin(), scale.end(), glm::vec3(1.0f));
std::fill(matrix.begin(), matrix.end(), glm::mat4(1.0f));
std::fill(nodeTransform.begin(), nodeTransform.end(), glm::mat4(1.0f));
}
};
//通常のレンダリングのアニメーション用の行列
struct AnimationUBO
{
alignas(16) glm::mat4 nodeMatrix;
alignas(16) glm::mat4 matrix;
alignas(16) std::array<glm::mat4, 128> boneMatrix;
alignas(16) int boneCount;
};
class AnimationComponent : public IComponent
{
private:
//バッファの作成
std::shared_ptr<GpuBufferFactory> bufferFactory;
//ディスクリプタセットレイアウトの作成
std::shared_ptr<GpuDescriptorSetLayoutFactory> layoutFactory;
//ディスクリプタセットの作成
std::shared_ptr<DescriptorSetFactory> descriptorSetFactory;
//プリミティブごとのDescriptorSet
std::vector<std::shared_ptr<DescriptorSet>> descriptorSet;
//Gltfモデルのデータ
std::shared_ptr<GltfModel> gltfModel;
//ノードごとのトランスフォーム
NodeTransform nodeTransform;
//経過時間
double deltaTime;
//アニメーションを再生し始めた時間
double startTime;
//アニメーションの切り替えフラッグ、アニメーション開始時間をリセット
//同一アニメーションをループさせる際、アニメーションが終了したときもtrueに
bool animationChange;
//現在再生しているアニメーションの名前
std::string currentPlayAnimationName;
//次の再生する予定のアニメーション
std::string nextPlayAnimationName;
//gltfモデルの持つアニメーションの名前の配列
std::vector<std::string> animationNames;
//アニメーション用行列の配列
std::vector<std::array<glm::mat4, 128>> jointMatrices;
//アニメーション用行列を記録するためのバッファ
std::vector<std::shared_ptr<GpuBuffer>> animationBuffer;
//アニメーション用行列を結び付けるディスクリプタセット
std::vector<std::shared_ptr<DescriptorSet>> descriptorSet;
//GPU上のバッファを作成する
void createBuffer();
void createBuffer(const GltfNode* node);
//ディスクリプタセットを作る
void createDescriptorSet();
void createDescriptorSet(const GltfNode* node);
public:
AnimationComponent(std::shared_ptr<GpuBufferFactory> buffer
, std::shared_ptr<GpuDescriptorSetLayoutFactory> layout
, std::shared_ptr<DescriptorSetFactory> desc);
//3Dモデルを設定する
void setGltfModel(std::shared_ptr<GltfModel> model);
//アニメーションを切り替える
void switchPlayAnimation(std::string next);
////特定のスケルトンのアニメーション行列を取得
std::shared_ptr<DescriptorSet> getJointMatrices(int index);
//コンポーネントをアタッチした時点で実行
void OnAwake() override {};
//アタッチ後の次のフレーム開始時点で実行
void OnStart() override;
//更新フェーズで実行
void OnUpdate() override {};
//更新フェーズ後に実行
void OnLateUpdate() override {};
//フレーム終了時に実行
void OnFrameEnd() override;
};