bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.24k stars 3.57k forks source link

Mutable Animation Clips #13052

Closed nzhao95 closed 6 months ago

nzhao95 commented 6 months ago

Hello,

I am trying to write a skeletal animation edition tool using bevy. However, the animation clips used by bevy are read only. I understand that this is probably due to the fact that animation assets are tied to their loading files and the logic of having code modifying it can seem weird. However for a game editor I believe it would still make sense to have tools that allow animation edition within bevy ?

Would it be possible to have mutable access to VariableCurves or expose functions that would allow the modification of animation asset inside bevy ?

My goal is then to export this animation into a brand new animation file.

For now the only solution I can think of is to fork bevy and force this mutable animation setup OR make a new animation plugin which would consist of a lot of duplicated code. Another way would be to create a brand new AnimationClip everytime I make an edit using the only mutable function exposed by AnimationClip (add_curve_to_target) but this would kill my performance...

I'm failry new to Rust and Bevy so bare with me if there are obvious solutions. Thanks !

NthTensor commented 6 months ago

Each AnimationGraphNode contains an Handle<AnimationClip>. You can get a mutable interference to the underlying clip from Assets<AnimationClip>. So it looks like we are just missing methods

fn curves_mut(&mut self) -> &mut HashMap<AnimationTargetId, Vec<VariableCurve>>
fn curves_for_target_mut(&mut self, target_id: AnimationTargetId) -> Option<&mut Vec<VariableCurve>>

on AnimationClip. Seem correct?

nzhao95 commented 6 months ago

Hello, thanks for getting back so quickly. Exactly those mutable getters would be really nice to have. For my use case it's really crucial. I don't know if there are good reasons not to have them but if they aren't it would be super cool to have them !

NthTensor commented 6 months ago

I think we just never bothered to add them. Looks like a good addition to me. I've tagged this as a good first issue.

nzhao95 commented 6 months ago

Cool ! Should I write the code and ask for a PR or is it going to be taken care of ?

NthTensor commented 6 months ago

It would be lovely if you would write a PR for this. Otherwise it may be some time before someone starts working on it.

nzhao95 commented 6 months ago

Nice ! I'll get on it thanks a ton