Add animation store for pre-made clips
aac.AnimationStore(folder) seeds a clip from an existing .anim asset and returns a normal ClipBuilder, so pre-made clips work anywhere generated clips do and can still be edited (looping, keyframes, toggles, blend shapes). The Unity side clones the asset into the container and applies the script's changes to the clone, leaving the original untouched. - ClipData gains optional source; looping becomes Option<bool> so an untouched store clip keeps the asset's own looping setting. - Add rust/examples/animation_store.rhai, a worked store example.
This commit is contained in:
+28
-4
@@ -5,6 +5,7 @@ use rhai::{Engine, EvalAltResult};
|
||||
|
||||
pub fn register(engine: &mut Engine) {
|
||||
register_clips(engine);
|
||||
register_animation_store(engine);
|
||||
register_blend_trees(engine);
|
||||
register_state_motion(engine);
|
||||
}
|
||||
@@ -32,8 +33,9 @@ fn register_clips(engine: &mut Engine) {
|
||||
a.write(|graph| {
|
||||
graph.clips.push(ClipData {
|
||||
name: name.to_string(),
|
||||
looping: false,
|
||||
looping: Some(false),
|
||||
curves: Vec::new(),
|
||||
source: None,
|
||||
})
|
||||
});
|
||||
Ok(ClipBuilder {
|
||||
@@ -42,9 +44,9 @@ fn register_clips(engine: &mut Engine) {
|
||||
})
|
||||
});
|
||||
|
||||
engine.register_fn("looping", |clip: ClipBuilder, value: bool| {
|
||||
clip.data_mut(|data| data.looping = value);
|
||||
clip
|
||||
engine.register_fn("looping", |clip: ClipBuilder, value: bool| -> Result<ClipBuilder, Box<EvalAltResult>> {
|
||||
clip.set_looping(value).map_err(err)?;
|
||||
Ok(clip)
|
||||
});
|
||||
|
||||
engine.register_fn(
|
||||
@@ -77,6 +79,28 @@ fn register_clips(engine: &mut Engine) {
|
||||
);
|
||||
}
|
||||
|
||||
fn register_animation_store(engine: &mut Engine) {
|
||||
engine.register_fn(
|
||||
"AnimationStore",
|
||||
|a: &mut Aac, folder: &str| -> Result<AnimationStore, Box<EvalAltResult>> {
|
||||
if folder.trim().is_empty() {
|
||||
return Err(err("animation store folder is empty".to_string()));
|
||||
}
|
||||
Ok(AnimationStore {
|
||||
aac: a.clone(),
|
||||
folder: folder.to_string(),
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
engine.register_fn(
|
||||
"clip",
|
||||
|store: AnimationStore, name: &str| -> Result<ClipBuilder, Box<EvalAltResult>> {
|
||||
store.clip(name).map_err(err)
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn register_blend_trees(engine: &mut Engine) {
|
||||
engine.register_fn("blend_tree", |a: &mut Aac, name: &str| -> Result<BlendTreeBuilder, Box<EvalAltResult>> {
|
||||
if name.trim().is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user