Antkeeper  0.0.1
animation-pose.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
22 #include <algorithm>
23 #include <execution>
24 
26  pose(skeleton),
27  m_matrix_palette(skeleton.get_bone_count())
28 {
29  reset();
30 }
31 
32 void animation_pose::update(bone_index_type first_index, std::size_t bone_count)
33 {
34  // Update absolute transforms
35  pose::update(first_index, bone_count);
36 
37  // Get skeleton rest pose
38  const auto& rest_pose = m_skeleton->get_rest_pose();
39 
40  // Update skinning matrix palette
41  std::for_each
42  (
43  // std::execution::par_unseq,
44  std::execution::seq,
45  m_matrix_palette.begin() + first_index,
46  m_matrix_palette.begin() + (first_index + bone_count),
47  [&](auto& skinning_matrix)
48  {
49  const bone_index_type bone_index = static_cast<bone_index_type>(&skinning_matrix - m_matrix_palette.data());
50  skinning_matrix = (m_absolute_transforms[bone_index] * rest_pose.get_inverse_absolute_transform(bone_index)).matrix();
51  }
52  );
53 }
54 
56 {
57  if (!m_skeleton)
58  {
59  return;
60  }
61 
62  // Get skeleton rest pose
63  const auto& rest_pose = m_skeleton->get_rest_pose();
64 
65  // Reset transforms and skinning matrix palette
66  std::for_each
67  (
68  // std::execution::par_unseq,
69  std::execution::seq,
70  m_relative_transforms.begin(),
72  [&](auto& relative_transform)
73  {
74  const bone_index_type bone_index = static_cast<bone_index_type>(&relative_transform - m_relative_transforms.data());
75 
76  relative_transform = rest_pose.get_relative_transform(bone_index);
77  m_absolute_transforms[bone_index] = rest_pose.get_absolute_transform(bone_index);
78  m_matrix_palette[bone_index] = bone_matrix_type::identity();
79  }
80  );
81 }
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
void update()
Updates the pose after one or more relative transforms have been changed.
Definition: pose.cpp:31
void reset()
Resets the animation pose to the skeleton's rest pose.
animation_pose() noexcept=default
Constructs an empty animation pose.
Base class for skeleton poses.
Definition: pose.hpp:32
void update()
Updates the pose after one or more relative transforms have been changed.
Definition: pose.cpp:31
const skeleton * m_skeleton
Skeleton with which the pose is associated.
Definition: pose.hpp:135
std::vector< bone_transform_type > m_relative_transforms
Relative ransforms for each bone in a skeleton.
Definition: pose.hpp:138
Skeleton rest pose.
Definition: rest-pose.hpp:29
Skeletal animation skeleton.
Definition: skeleton.hpp:35
const rest_pose & get_rest_pose() const noexcept
Returns the skeleton's rest pose.
Definition: skeleton.hpp:187