Expand description
Native Rust port of the Spine 4.3 runtime.
The crate loads skeletons exported from the Spine editor, poses and animates them, and emits triangle batches for your renderer to draw. It has no GPU or windowing dependencies. Every developer using it needs their own Spine Editor license; see the README.
Only Spine 4.3 exports load: binary .skel or JSON, each with its
.atlas.
§Where to start
atlas::Atlasparses a.atlasfile. Loading the page images is up to you.load::SkeletonBinaryorload::SkeletonJson, given anload::AtlasAttachmentLoader, reads an export into adata::SkeletonData. Load it once and share it in anArc.skeleton::Skeletonis one posable instance of that data.animation::AnimationStateplays, queues and crossfades animations on tracks;animation::AnimationStateDataholds the crossfade times.render::SkeletonRendererturns a posed skeleton intorender::RenderCommands. Each command names its texture by atlas page index (render::TextureId).
§Example
use std::sync::Arc;
use spine_runtime::animation::{AnimationState, AnimationStateData};
use spine_runtime::atlas::Atlas;
use spine_runtime::load::{AtlasAttachmentLoader, SkeletonBinary};
use spine_runtime::render::SkeletonRenderer;
use spine_runtime::skeleton::{Physics, Skeleton};
let atlas = Atlas::parse(&std::fs::read_to_string("spineboy.atlas")?)?;
let mut loader = AtlasAttachmentLoader::new(&atlas);
let bytes = std::fs::read("spineboy-pro.skel")?;
let data = Arc::new(SkeletonBinary::with_loader(&mut loader).read(&bytes)?);
let mut skeleton = Skeleton::new(Arc::clone(&data));
let mut state = AnimationState::new(Arc::new(AnimationStateData::new(data)));
state.set_animation_by_name(0, "walk", true)?;
let mut renderer = SkeletonRenderer::new();
let mut events = Vec::new();
let dt = 1.0 / 60.0;
for _frame in 0..60 {
state.update(dt);
events.clear();
state.apply(&mut skeleton, &mut events);
skeleton.update(dt);
skeleton.update_world_transform(Physics::Update);
for command in renderer.render(&skeleton) {
// Upload command.positions, uvs, colors and indices; bind the
// texture for command.texture; set command.blend_mode.
}
}Coordinates are y-up. Rotations are in degrees and times in seconds.
Modules§
- animation
- Animation playback: plays animations on a
Skeleton, with tracks, queuing, crossfades and events. - atlas
- Parser for the Spine
.atlastext format. - data
- Setup-pose data shared by every
Skeletonof one asset. - load
- Skeleton loaders: turn a Spine 4.3 export into
SkeletonData. - math
- Math primitives shared by the runtime.
- render
- Render-command emission, the boundary between the runtime and a renderer.
- skeleton
- Per-instance skeleton state: bones, slots, constraints and their poses.