sandbox
Loading...
Searching...
No Matches
skeleton.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_ANIMATIONS_SKELETON_HPP_
3#define LIBSBX_ANIMATIONS_SKELETON_HPP_
4
5#include <string>
6#include <cstdint>
7#include <unordered_map>
8#include <cmath>
9#include <optional>
10
11#include <libsbx/utility/logger.hpp>
12#include <libsbx/utility/hashed_string.hpp>
13
14#include <libsbx/math/matrix4x4.hpp>
16
17#include <libsbx/animations/animation.hpp>
18
19namespace sbx::animations {
20
21class skeleton {
22
23public:
24
25 struct bone {
26 inline static constexpr auto null = std::uint32_t{0xFFFFFFFF};
27
28 std::uint32_t parent_id;
29 math::matrix4x4 local_bind_matrix;
30 math::matrix4x4 inverse_bind_matrix;
31 }; // struct bone
32
33 inline static constexpr auto max_bones = std::uint32_t{64u};
34
35 skeleton() = default;
36
37 auto reserve(const std::size_t size) -> void;
38
39 auto shrink_to_fit() -> void;
40
41 auto add_bone(const std::string& name, const bone& bone) -> void;
42
43 auto root_transform() const -> const math::matrix4x4&;
44
45 auto inverse_root_transform() const -> const math::matrix4x4&;
46
47 auto set_inverse_root_transform(const math::matrix4x4& inverse_root_transform) -> void;
48
49 auto bones() const -> const std::vector<bone>&;
50
51 auto evaluate_pose(const animation& animation, std::float_t time) const -> std::vector<math::matrix4x4>;
52
53 auto bone_count() const -> std::uint32_t;
54
55 auto name_for_bone(const std::size_t index) const -> const utility::hashed_string&;
56
57 auto bone_index(const utility::hashed_string& name) const -> std::optional<std::uint32_t>;
58
59private:
60
61 std::vector<bone> _bones;
62 std::vector<utility::hashed_string> _bone_names_by_id;
63 std::unordered_map<utility::hashed_string, std::uint32_t> _bone_id_by_name;
64
65 math::matrix4x4 _inverse_root_transform;
66 math::matrix4x4 _root_transform;
67
68}; // class skeleton
69
70} // namespace sbx::animation
71
72#endif // LIBSBX_ANIMATIONS_SKELETON_HPP_
Definition: animation.hpp:18
Definition: skeleton.hpp:21
Definition: matrix4x4.hpp:26
Matrix casting and decomposition utilities.
Definition: skeleton.hpp:25