3 #ifndef GDK_GFX_ANIMATED_MODEL_H 4 #define GDK_GFX_ANIMATED_MODEL_H 9 #include <unordered_map> 10 #include <unordered_set> 12 #include <gdk/vertex_data.h> 13 #include <gdk/graphics_types.h> 49 graphics_mat4x4_type transform;
51 std::unordered_set<bone *> children;
55 std::unordered_set<std::unique_ptr<bone>> all_bones = {};
58 std::unordered_set<bone *> root_bones = {};
61 bool is_format_same(
const skeleton &other)
const 63 if (all_bones.size() != other.all_bones.size())
66 auto iThisBone = all_bones.begin();
67 auto iThatBone = other.all_bones.begin();
69 while (iThisBone != all_bones.end())
71 if ((*iThisBone)->name != (*iThatBone)->name)
90 using key_frame_collection_type =
91 std::set<std::pair<
float, skeleton>>;
93 key_frame_collection_type m_KeyFrames;
95 skeleton calculate_skeleton_at(
float timeSec)
97 auto iLowFrame(m_KeyFrames.begin()),
98 iHighFrame(m_KeyFrames.begin());
100 float interpolationWeight(0);
102 for (
auto i = m_KeyFrames.begin(); i != m_KeyFrames.end(); ++i)
104 if (timeSec < (*i).first)
108 auto lowTime = iLowFrame->first;
109 auto highTime = iHighFrame->first;
111 interpolationWeight =
112 (timeSec - lowTime) / (highTime - lowTime);
120 skeleton interpolated_skeleton;
127 return interpolated_skeleton;
130 animation(key_frame_collection_type &&aKeyFrames)
131 : m_KeyFrames(std::move(aKeyFrames))
133 const auto &firstSkeleton = m_KeyFrames.begin()->second;
135 for (
auto iFrame = m_KeyFrames.begin();
136 iFrame != m_KeyFrames.end(); ++iFrame)
137 if (!firstSkeleton.is_format_same(iFrame->second))
138 throw std::invalid_argument(
"animation: " 139 "skeleton format must be the same in all keyframes");
144 std::unordered_map<std::string, animation> m_animations;
150 std::shared_ptr<gdk::model> m_pModel;
152 void animate(
const std::unordered_set<std::pair<std::string, float>>
153 &aContributingFrames)
160 void animate(
const std::pair<std::string, float> &aFrame)
Definition: animated_model.h:40
used to construct a model. Vertex data represents a set of vertex data in system memory ...
Definition: vertex_data.h:44
Definition: animated_model.h:45