Skip to content

Commit

Permalink
Expose mutable Animation Clips (bevyengine#13067)
Browse files Browse the repository at this point in the history
# Objective

- Be able to edit animation inside the editor and save them once
modified. This will allow bevy to modify animation assets with code.
- Fixes bevyengine#13052

## Solution

- Expose the previously const getters of the Animation curves

---
  • Loading branch information
nzhao95 authored Apr 23, 2024
1 parent ddc9599 commit 83f1184
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ impl AnimationClip {
&self.curves
}

#[inline]
/// Get mutable references of [`VariableCurve`]s for each animation target. Indexed by the [`AnimationTargetId`].
pub fn curves_mut(&mut self) -> &mut AnimationCurves {
&mut self.curves
}

/// Gets the curves for a single animation target.
///
/// Returns `None` if this clip doesn't animate the target.
Expand All @@ -266,12 +272,29 @@ impl AnimationClip {
self.curves.get(&target_id)
}

/// Gets mutable references of the curves for a single animation target.
///
/// Returns `None` if this clip doesn't animate the target.
#[inline]
pub fn curves_for_target_mut(
&mut self,
target_id: AnimationTargetId,
) -> Option<&'_ mut Vec<VariableCurve>> {
self.curves.get_mut(&target_id)
}

/// Duration of the clip, represented in seconds.
#[inline]
pub fn duration(&self) -> f32 {
self.duration
}

/// Set the duration of the clip in seconds.
#[inline]
pub fn set_duration(&mut self, duration_sec: f32) {
self.duration = duration_sec;
}

/// Adds a [`VariableCurve`] to an [`AnimationTarget`] named by an
/// [`AnimationTargetId`].
///
Expand Down

0 comments on commit 83f1184

Please sign in to comment.