Skip to main content

MotionController

Struct MotionController 

Source
pub struct MotionController {
    pub graph: MotionGraph,
    pub current_state: String,
    pub state_time: f32,
    pub blend_state: Option<String>,
    pub blend_time: f32,
    pub blend_duration: f32,
    pub parameters: HashMap<String, f32>,
    pub total_time: f32,
}
Expand description

Runtime controller that drives a MotionGraph.

Fields§

§graph: MotionGraph

The graph being controlled.

§current_state: String

Name of the currently active state.

§state_time: f32

Seconds spent in the current state (resets on transition).

§blend_state: Option<String>

Name of the state being blended into (if any).

§blend_time: f32

Seconds spent in the current blend.

§blend_duration: f32

Total duration of the current blend.

§parameters: HashMap<String, f32>

Named runtime float parameters used by transition conditions.

§total_time: f32

Total time since the controller was created / reset.

Implementations§

Source§

impl MotionController

Source

pub fn new(graph: MotionGraph) -> Self

Create a controller and start in the graph’s entry state (or "idle" as a fallback).

Source

pub fn set_parameter(&mut self, name: &str, value: f32)

Set (or overwrite) a named runtime parameter.

Source

pub fn get_parameter(&self, name: &str) -> f32

Read a named runtime parameter (0.0 if not set).

Source

pub fn update(&mut self, dt: f32)

Advance the controller by dt seconds.

  1. Advances state_time and total_time.
  2. Checks all transitions out of the current state in priority order.
  3. If a condition fires, starts a blend to the target state.
  4. Advances an in-progress blend; finalises it when complete.
Source

pub fn transition_to(&mut self, state: &str, blend_duration: f32)

Force-start a transition to state with the given cross-fade duration. If blend_duration is 0.0, the transition is instantaneous.

Source

pub fn blend_weight(&self) -> f32

Current blend weight in [0, 1].

  • 0.0 → 100 % current state.
  • 1.0 → 100 % destination state.

Returns 0.0 when not blending.

Source

pub fn evaluate_morphs(&self) -> HashMap<String, f32>

Evaluate blended morph weights at the current instant.

When not blending, returns the current state’s morph weights unchanged. When blending, returns a linear interpolation between the current and destination state morph weights.

Source

pub fn check_condition(&self, cond: &TransitionCondition) -> bool

Check whether a single TransitionCondition is currently satisfied.

Source

pub fn is_blending(&self) -> bool

Returns true while a cross-fade blend is in progress.

Source

pub fn current_state_name(&self) -> &str

The name of the currently active state.

Auto Trait Implementations§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.