后端无关的动画图形创建框架。
MotionGfx is a backend-agnostic motion graphics framework. It provides a modular foundation for procedural animations.
…The Registry keeps track of how to animate your types behind the
scenes. motiongfx is type-erased at runtime, so it needs the
registry to know how to read and write each field. You don't need to
set it up manually, just create one and pass it to the builder.
Registration happens automatically the first time you add an
animation.
# use motiongfx::prelude::*;
let mut registry = Registry::new();The TimelineBuilder is where you describe your animations. Create
one from the registry, typed to your data holder:
# use motiongfx::prelude::*;
# let mut registry = Registry::new();
# type World = Vec;
let mut b = registry.create_builder::();Animations are built up in layers:
.play(duration).…Before playing an animation, you need to bake it. Baking reads the starting values from your world and prepares the animation data. This only needs to happen once, right after building the timeline.
To advance the animation, set a target time, then queue and sample. Queuing figures out which actions are active at that time, and sampling writes the new values back into your world.
A timeline can also have multiple tracks, each acting as a chapter.
Use set_target_track to jump between them.
# #[path = "docs/world.rs"] mod _doc; use _doc::*;
# let mut subjects = World(vec![0.0]);
# let (registry, mut timeline) = timeline();
// Bake once after building the timeline.
timeline.bake_actions(®istry, &subjects);
// Set target time, queue, then sample.
timeline.set_target_time(cs(50));
timeline.queue_actions();
timeline.sample_queued_actions(®istry, &mut subjects);
assert!((subjects.0[0] - 5.0).abs() < f32::EPSILON);You can control how fragments play relative to each other. There are 4 ordering combinators:
use motiongfx::prelude::*;
// Using empty fragments as an example only.
let f0 = TrackFragment::new();
let f1 = TrackFragment::new();
let f = [f0, f1].ord_chain();
// Or...
// use motiongfx::track::chain;
// let f = chain([f0, f1]);f1 plays after f0 finishes.
use motiongfx::prelude::*;
let f0 = TrackFragment::new();
let f1 = TrackFragment::new();
let f = [f0, f1].ord_all();f0 and f1 play at the same time, and the result finishes when
both are done.
use motiongfx::prelude::*;
let f0 = TrackFragment::new();
let f1 = TrackFragment::new();
let f = [f0, f1].ord_any();f0 and f1 play at the same time, and the result finishes when
either one is done.
use motiongfx::prelude::*;
let f0 = TrackFragment::new();
let f1 = TrackFragment::new();
let f = [f0, f1].ord_flow(cs(50));f1 starts 0.5 seconds after f0 begins, regardless of how long
f0 takes.
You can join us on the Voxell discord server.
motiongfx is dual-licensed under either:
This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are very good reasons to include both.
暂无开放 Issues,或尚未同步最近议题。