Skip to main content

rebirth_ik/
lib.rs

1//! # rebirth-ik
2//!
3//! Inverse kinematics in safe Rust — a rebirth of the abandoned C library
4//! [TheComet/ik](https://github.com/TheComet/ik) (MIT, © 2017 Alex Murray).
5//!
6//! * [`Skeleton`] + [`Fabrik`]: FABRIK over arbitrary bone *trees* with several effectors,
7//!   effector weights, joint constraints and optional joint rotations.
8//! * [`solve_chain`]: allocation-free FABRIK for a single chain of points (`no_std`).
9//! * [`one_bone`] / [`two_bone`]: closed-form solvers (with pole vector for knees and elbows).
10//! * `rayon` feature: [`solve_chains_par`] for crowds.
11//!
12//! ```
13//! use rebirth_ik::*;
14//!
15//! // a three-bone arm hanging up from the origin
16//! let mut skel = Skeleton::new();
17//! let root = skel.add_root(Vec3::ZERO);
18//! let a = skel.add_child(root, Vec3::new(0.0, 1.0, 0.0));
19//! let b = skel.add_child(a, Vec3::new(0.0, 1.0, 0.0));
20//! let hand = skel.add_child(b, Vec3::new(0.0, 1.0, 0.0));
21//! skel.set_effector(hand, Effector::new(Vec3::new(1.5, 1.5, 0.0)));
22//!
23//! let mut solver = Fabrik::new(&skel, Config::default());
24//! let info = solver.solve(&mut skel);
25//! assert!(info.converged);
26//! assert!(skel.global_position(hand).distance(Vec3::new(1.5, 1.5, 0.0)) < 1e-2);
27//! ```
28
29#![cfg_attr(not(feature = "std"), no_std)]
30#![forbid(unsafe_code)]
31
32extern crate alloc;
33
34#[cfg(all(not(feature = "std"), not(feature = "libm")))]
35compile_error!(
36    "rebirth-ik needs either the `std` feature or the `libm` feature for floating point math"
37);
38
39pub mod analytic;
40pub mod chain;
41pub mod constraint;
42pub mod math;
43pub mod single;
44pub mod skeleton;
45pub mod solver;
46
47pub use analytic::{one_bone, segment_rotation, two_bone};
48pub use chain::{Chain, ChainTree};
49pub use constraint::Constraint;
50pub use math::{Quat, Vec3};
51#[cfg(feature = "rayon")]
52pub use single::solve_chains_par;
53pub use single::{segment_lengths, solve_chain, ChainResult};
54#[cfg(feature = "std")]
55pub use single::{solve_chains, ChainBuf};
56pub use skeleton::{Effector, EffectorFlags, Node, NodeId, Skeleton};
57pub use solver::{Config, Fabrik, SolveInfo};