CSEngine
Loading...
Searching...
No Matches
DAEAnimationLoader.h
1//
2// Created by ounols on 19. 3. 31.
3//
4
5#pragma once
6
7
8#include <utility>
9
10#include "../../Matrix.h"
11#include "../XML/XML.h"
12
13namespace CSE {
14
16 std::string jointNameId;
17 int jointId;
18 mat4 jointLocalTransform;
19
20 JointTransformData(int jointId, std::string jointNameId, const mat4& jointLocalTransform) :
21 jointNameId(std::move(jointNameId)),
22 jointId(jointId),
23 jointLocalTransform(jointLocalTransform) {
24 }
25 };
26
27 struct KeyFrameData {
28 float time = 0;
29 std::vector<JointTransformData*> jointTransforms;
30
31 explicit KeyFrameData(float time) : time(time) {
32 }
33 };
34
36 float lengthSeconds;
37 std::vector<KeyFrameData*> keyFrames;
38
39 AnimationData(float lengthSeconds, std::vector<KeyFrameData*> keyFrames) :
40 lengthSeconds(lengthSeconds),
41 keyFrames(std::move(keyFrames)) {
42 }
43 };
44
46 public:
48
50
51 bool Load(const char* path, std::string name);
52
53 AnimationData* GetAnimation() const {
54 return m_animationData;
55 }
56
57 private:
58 void LoadAnimation();
59
60 std::string findRootJointName();
61
62 std::vector<float> getKeyTimes();
63
64 static std::vector<KeyFrameData*> initKeyFrames(const std::vector<float>& times);
65
66 static void loadJointTransforms(std::vector<KeyFrameData*> frames, const XNode& jointData,
67 const std::string& rootNodeId);
68
69 static std::string getJointName(const XNode& jointData);
70
71 static std::string getDataId(const XNode& jointData);
72
73 static void
74 processTransforms(const std::string& jointName, std::vector<float> rawData,
75 std::vector<KeyFrameData*> keyFrames, bool root);
76
77 private:
78 std::string m_name;
79 const XNode* m_root{};
80 XNode m_joint;
81 XNode m_animation;
82
83 AnimationData* m_animationData = nullptr;
84 };
85
86}
Definition XML.h:43