gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
Loading...
Searching...
No Matches
skeleton.h
1// © Joseph Cameron - MIT License
2
3#ifndef GDK_GRAPHICS_EXT_ANIMATION_SKELETON_H
4#define GDK_GRAPHICS_EXT_ANIMATION_SKELETON_H
5
6#include <gdk/graphics/ext/animation/animation_types.h>
7
8#include <cstddef>
9#include <string>
10#include <string_view>
11#include <vector>
12#include <span>
13
14namespace gdk::graphics::animation {
16 struct skeleton final {
17 struct bone final {
18 int parent = -1;
19 vector3_type local_position;
20 quaternion_type local_rotation;
21 std::string name;
22 };
23
24 std::vector<bone> bones;
25 std::vector<matrix4x4_type> supplied_inverse_binds;
26
28 [[nodiscard]] std::vector<matrix4x4_type> bind_world_transforms() const;
29
31 [[nodiscard]] skeleton with_oriented_bone_frames() const;
32
34 [[nodiscard]] std::vector<matrix4x4_type> inverse_bind_transforms() const;
35 };
36
38 struct vertical_extent final {
39 float lowest = 0;
40 float highest = 0;
41
42 [[nodiscard]] float height() const { return highest - lowest; }
43 };
44
45 [[nodiscard]] vertical_extent bind_vertical_extent(const skeleton &aSkeleton);
46
48 [[nodiscard]] float limb_half_width(const skeleton &aSkeleton);
49
51 [[nodiscard]] int find_bone(const skeleton &aSkeleton, std::string_view aName);
52
54 [[nodiscard]] std::vector<std::string> duplicate_bone_names(const skeleton &aSkeleton);
55
57 struct pose final {
58 std::vector<quaternion_type> local_rotations;
59
60 [[nodiscard]] static pose rest(const skeleton &aSkeleton);
61 };
62
64 [[nodiscard]] pose blend(const pose &aFrom, const pose &aTo, const float aT);
65
67 using bone_mask = std::vector<float>;
68
70 [[nodiscard]] bone_mask mask_for_subtree(const skeleton &aSkeleton, const std::size_t aRoot,
71 const float aWeight = 1.0f);
72
74 [[nodiscard]] pose blend(const pose &aFrom, const pose &aTo, const bone_mask &aMask);
75
77 [[nodiscard]] pose difference(const pose &aBase, const pose &aTarget);
78
80 [[nodiscard]] pose add(const pose &aBase, const pose &aDelta, const bone_mask &aMask);
81
83 [[nodiscard]] pose add(const pose &aBase, const pose &aDelta, const float aWeight);
84
86 struct clip final {
87 struct key final {
88 float time = 0;
89 pose p;
90 vector3_type root_position;
91 };
92
93 std::vector<key> keys;
94 float duration = 1.0f;
95 vector3_type root_motion_per_cycle;
96 bool loops = true;
97 };
98
100 [[nodiscard]] pose sample(const clip &aClip, const float aTime);
101
103 [[nodiscard]] vector3_type sample_root_position(const clip &aClip, const float aTime);
104
106 [[nodiscard]] vector3_type root_delta(const clip &aClip, const float aFrom, const float aTo);
107
109 [[nodiscard]] std::vector<matrix4x4_type> pose_world_transforms(
110 const skeleton &aSkeleton, const pose &aPose);
111
113 struct socket final {
114 std::size_t bone = 0;
115 matrix4x4_type offset;
116 };
117
119 [[nodiscard]] matrix4x4_type socket_transform(std::span<const matrix4x4_type> aWorld,
120 const socket &aSocket);
121
123 [[nodiscard]] quaternion_type bone_world_rotation(const skeleton &aSkeleton, const pose &aPose,
124 const std::size_t aBone);
125
127 [[nodiscard]] std::vector<matrix4x4_type> skinning_palette(
128 const skeleton &aSkeleton, const pose &aPose,
129 std::span<const matrix4x4_type> aInverseBind
130 );
131}
132
133#endif
Definition skeleton.h:87
a looping sequence of keyframed poses
Definition skeleton.h:86
one bone rotation per bone, relative to its parent.
Definition skeleton.h:57
a chain of bones in bind pose.
Definition skeleton.h:16
skeleton with_oriented_bone_frames() const
the same skeleton with each bone's local frame pointing +Y at its first child
std::vector< matrix4x4_type > inverse_bind_transforms() const
the inverse of each bind-pose world transform
std::vector< matrix4x4_type > bind_world_transforms() const
world-space transform of each bone in bind pose
a thing attached to a bone: which bone, and where it sits in that bone's space.
Definition skeleton.h:113
the vertical span of a rig in bind pose
Definition skeleton.h:38