Skip to main content

Skeleton

Struct Skeleton 

Source
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, ResourceStore, 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>

Source

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.

Source

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.

Trait Implementations§

Source§

impl<const BONES: usize> Clone for Skeleton<BONES>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const BONES: usize> Debug for Skeleton<BONES>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const BONES: usize> Forget for Skeleton<BONES>

§

impl<const BONES: usize> Freeze for Skeleton<BONES>
where [Bone; BONES]: Freeze,

§

impl<const BONES: usize> Move for Skeleton<BONES>

§

impl<const BONES: usize> RefUnwindSafe for Skeleton<BONES>

§

impl<const BONES: usize> Send for Skeleton<BONES>
where [Bone; BONES]: Send,

§

impl<const BONES: usize> Sync for Skeleton<BONES>
where [Bone; BONES]: Sync,

§

impl<const BONES: usize> Unpin for Skeleton<BONES>
where [Bone; BONES]: Unpin,

§

impl<const BONES: usize> UnsafeUnpin for Skeleton<BONES>

§

impl<const BONES: usize> UnwindSafe for Skeleton<BONES>
where [Bone; BONES]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.