Antkeeper  0.0.1
ik-rig.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 
21 
23  m_skeletal_mesh(&skeletal_mesh),
24  m_constraints(skeletal_mesh.get_pose().get_skeleton()->get_bone_count())
25 {}
26 
27 void ik_rig::set_constraint(bone_index_type index, std::shared_ptr<ik_constraint> constraint)
28 {
29  m_constraints[index] = std::move(constraint);
30 }
31 
33 {
34  for (auto& constraint: m_constraints)
35  {
36  constraint.reset();
37  }
38 }
39 
41 {
42  for (const auto& solver: m_solvers)
43  {
44  solver->solve();
45  }
46 }
47 
48 void ik_rig::add_solver(std::shared_ptr<ik_solver> solver)
49 {
50  m_solvers.emplace_back(std::move(solver));
51 }
52 
54 {
55  m_solvers.clear();
56 }
std::uint16_t bone_index_type
Bone index type.
Definition: bone.hpp:31
void clear_constraints()
Removes all constraints from the IK rig.
Definition: ik-rig.cpp:32
void remove_solvers()
Removes all solvers from the IK rig.
Definition: ik-rig.cpp:53
void add_solver(std::shared_ptr< ik_solver > solver)
Adds a solver to the IK rig.
Definition: ik-rig.cpp:48
void solve()
Solves each solver in the IK rig.
Definition: ik-rig.cpp:40
void set_constraint(bone_index_type index, std::shared_ptr< ik_constraint > constraint)
Sets the IK constraint of a bone.
Definition: ik-rig.cpp:27
ik_rig(scene::skeletal_mesh &skeletal_mesh)
Constructs an IK rig.
Definition: ik-rig.cpp:22