32 std::size_t bone_count = 1;
38 throw std::invalid_argument(
"Invalid bone chain");
45 m_bone_indices.resize(bone_count);
46 m_bone_indices.front() = effector_bone_index;
47 for (std::size_t i = 1; i < bone_count; ++i)
57 auto&
pose = skeletal_mesh.get_pose();
63 const auto ps_goal_center = m_goal_center * skeletal_mesh.get_transform();
65 for (std::size_t i = 0; i < m_max_iterations; ++i)
67 for (std::size_t j = 0; j < m_bone_indices.size(); ++j)
70 const auto ps_effector_position = ps_effector_bone_transform * m_effector_position;
87 const auto ps_effector_direction =
math::normalize(ps_effector_position - ps_bone_transform.translation);
90 const auto ps_goal_direction =
math::normalize(ps_goal_center - ps_bone_transform.translation);
98 constraint->solve(bone_rotation);
std::uint16_t bone_index_type
Bone index type.
ccd_ik_solver(ik_rig &ik_rig, bone_index_type root_bone_index, bone_index_type effector_bone_index)
Constructs a CCD IK solver.
void solve() override
Sets the maximum number of solving iterations.
const ik_constraint * get_constraint(bone_index_type index) const
Returns the IK constraint of a bone.
const scene::skeletal_mesh & get_skeletal_mesh() const noexcept
Returns the skeleton with which the IK rig is associated.
Base class for skeleton poses.
const skeleton * get_skeleton() const noexcept
Returns the skeleton with which the pose is associated.
void update()
Updates the pose after one or more relative transforms have been changed.
const bone_transform_type & get_relative_transform(bone_index_type index) const
Returns the relative transform describing a bone pose.
const bone_transform_type & get_absolute_transform(bone_index_type index) const
Returns the absolute transform describing a bone pose.
void set_relative_rotation(bone_index_type index, const bone_transform_type::quaternion_type &rotation)
Sets the relative rotation of a bone pose.
const animation_pose & get_pose() const noexcept
Returns the animation pose of the skeletal mesh.
Skeletal animation skeleton.
bone_index_type get_bone_parent(bone_index_type child_index) const
Returns the index of the parent of a bone.
constexpr T sqr_distance(const vector< T, N > &p0, const vector< T, N > &p1) noexcept
Calculates the square distance between two points.
quaternion< T > normalize(const quaternion< T > &q)
Normalizes a quaternion.
quaternion< T > rotation(const vec3< T > &from, const vec3< T > &to, T tolerance=T{1e-6})
Constructs a quaternion representing the minimum rotation from one direction to another direction.
@ bone_index
Vertex bone indices (uvec4)