pub struct Skeleton<const BONES: usize> { /* private fields */ }Expand description
An immutable, parent-first 2D skeleton evaluated without preceding frames.
This is forward kinematics only: no IK, constraints, dynamics, or mesh skinning. Multiple roots and empty skeletons are allowed. Solved coordinates are local to the skeleton; put the assembled scene inside a normal transformed group to position, scale, or mirror the complete character. No renderer changes are needed.
§Example
use motion_core::prelude::*;
use motion_core::{
DisplayList, RasterLimits, ResourcePool, ValidatedDisplayList, MAX_PATH_VERBS,
MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let rig = Skeleton::new([Bone::new(None, (0.0, 0.0)), Bone::new(Some(0), (60.0, 0.0))])?;
let mut pose = Pose::default();
pose.bones[0].rotation = std::f64::consts::FRAC_PI_2;
let joints = rig.solve(&pose)?;
assert!((joints[1].position().1 - 60.0).abs() < 0.001);
let artwork = joints[0]
.apply(Path2D::parse_svg("M0 0L60 0")?.stroke(12.0, Color::from_hex(0x23272c)));Implementations§
Source§impl<const BONES: usize> Skeleton<BONES>
impl<const BONES: usize> Skeleton<BONES>
Sourcepub fn new(bones: [Bone; BONES]) -> Result<Self, ValidationError>
pub fn new(bones: [Bone; BONES]) -> Result<Self, ValidationError>
Validates and stores the rest hierarchy without allocating a graph.
§Errors
Returns std::io::ErrorKind::InvalidInput for a nonfinite rest offset or a
parent index that is not smaller than its child index. The latter rejects
self-parenting, cycles, forward references, and out-of-range parents.
Sourcepub fn solve(
&self,
pose: &Pose<BONES>,
) -> Result<[BoneTransform; BONES], ValidationError>
pub fn solve( &self, pose: &Pose<BONES>, ) -> Result<[BoneTransform; BONES], ValidationError>
Solves joint pivots and orientations in skeleton space in one linear pass.
Takes only the rest skeleton and this pose; sampling out of order or concurrently has no hidden state. A bone’s translation is applied before its rotation, so its children inherit both the pivot and orientation.
§Errors
Returns std::io::ErrorKind::InvalidInput for nonfinite channels, overflowing
local translations, or nonrepresentable solved positions/angles. The
complete result is discarded on error; no partially solved pose is returned.