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: MotionGraphThe graph being controlled.
current_state: StringName of the currently active state.
state_time: f32Seconds spent in the current state (resets on transition).
blend_state: Option<String>Name of the state being blended into (if any).
blend_time: f32Seconds spent in the current blend.
blend_duration: f32Total duration of the current blend.
parameters: HashMap<String, f32>Named runtime float parameters used by transition conditions.
total_time: f32Total time since the controller was created / reset.
Implementations§
Source§impl MotionController
impl MotionController
Sourcepub fn new(graph: MotionGraph) -> Self
pub fn new(graph: MotionGraph) -> Self
Create a controller and start in the graph’s entry state (or "idle"
as a fallback).
Sourcepub fn set_parameter(&mut self, name: &str, value: f32)
pub fn set_parameter(&mut self, name: &str, value: f32)
Set (or overwrite) a named runtime parameter.
Sourcepub fn get_parameter(&self, name: &str) -> f32
pub fn get_parameter(&self, name: &str) -> f32
Read a named runtime parameter (0.0 if not set).
Sourcepub fn update(&mut self, dt: f32)
pub fn update(&mut self, dt: f32)
Advance the controller by dt seconds.
- Advances
state_timeandtotal_time. - Checks all transitions out of the current state in priority order.
- If a condition fires, starts a blend to the target state.
- Advances an in-progress blend; finalises it when complete.
Sourcepub fn transition_to(&mut self, state: &str, blend_duration: f32)
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.
Sourcepub fn blend_weight(&self) -> f32
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.
Sourcepub fn evaluate_morphs(&self) -> HashMap<String, f32>
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.
Sourcepub fn check_condition(&self, cond: &TransitionCondition) -> bool
pub fn check_condition(&self, cond: &TransitionCondition) -> bool
Check whether a single TransitionCondition is currently satisfied.
Sourcepub fn is_blending(&self) -> bool
pub fn is_blending(&self) -> bool
Returns true while a cross-fade blend is in progress.
Sourcepub fn current_state_name(&self) -> &str
pub fn current_state_name(&self) -> &str
The name of the currently active state.
Auto Trait Implementations§
impl Freeze for MotionController
impl RefUnwindSafe for MotionController
impl Send for MotionController
impl Sync for MotionController
impl Unpin for MotionController
impl UnsafeUnpin for MotionController
impl UnwindSafe for MotionController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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