spine

Spine 4.2 evaluation and immutable backend-neutral render snapshots

garnet-spine

Standalone Spine 4.2 JSON and binary evaluation with the official pinned spine-cpp runtime and backend-neutral Garnet drawing snapshots. No window, ECS, graphics device, image decoder, or renderer from Spine is required. The native runtime evaluates the pose and extracts clipped CPU geometry; Garnet executes GPU work.

License and version

The bundled runtime is not MIT. Read its license before use or redistribution. It requires the applicable Spine Editor license terms (including the per-user condition in the alternative grant), and retaining its license/copyright notice. This adapter does not grant a Spine Editor license.

UPSTREAM pins commit 5cb78e77d3711ddcd80c7bd043bb11cf70fcc88c on the stable 4.2 branch. Freeze the editor/export version with the runtime; other major/minor exports are rejected before native loading. JSON uses Asset.new(json_text, atlas_text); binary .skel uses Asset.new(binary_bytes, atlas_text) with the same page resolver. Asset.load(skeleton_source, atlas_source) { |page| ... } reads both from Garnet::Content::Sources and detects JSON by a leading {. Binary header/version checks precede native parsing. 4.3 beta is outside this profile. Runtime inputs are trusted editor exports, not an untrusted asset sandbox.

Use

Run make -C native -j6 (also run by the shard's postinstall hook). The native build needs a C++11 compiler and archiver. The workspace supports local path dependencies; add garnet-spine with path: ../spine to the consuming shard.

require "garnet-spine"

asset = Garnet::Spine::Asset.new(json_text, atlas_text) do |page|
  # Application-owned IO/decoder policy. Return a Garnet::Graphics::Texture.
  # Validate/use page.name, width, height, premultiplied?, and sampler.
  textures.fetch(page.name)
end
actor = asset.instantiate
begin
  actor.mix("walk", "idle", 0.15_f32)
  actor.play("walk")
  events = actor.advance(1_f32 / 60) # call once per simulation tick
  pose = actor.snapshot             # repeat for multiple views without advancing
  output = renderer.render(pose.drawing, target)
  events.each { |event| puts event.name }
ensure
  actor.close
  asset.close
end

play accepts track:, loop:, queue: and delay:. reset clears tracks and returns to setup pose. Mix configuration belongs to each instance. advance returns copied named timeline events with time, integer, float and string values; no native callback enters game code. Lifecycle/completion events and audio dispatch are not exposed in this profile. The owner chooses event routing and scheduling.

asset.animations returns copied name/duration metadata; asset.skins returns copied skin names. actor.skin = "name" switches the instance's skin and resets slot attachments to that skin's setup choices. actor.attachment("slot", "name") selects an attachment; passing nil hides it. Unknown names fail before changing the selection. These operations do not mutate the shared setup asset or another instance; attachment animation keys may replace a manual selection on a later tick.

For procedural animation, apply local edits in the phase between animation and world/constraint evaluation:

events = actor.advance(delta_seconds) do |skeleton|
  local = skeleton.bone_transform("hand")
  skeleton.set_bone("hand", rotation: local.rotation + 10_f32)
end

Bone rotations and shears use Spine's degrees; scale may be negative. set_bone accepts any subset of x/y/rotation/scale_x/scale_y/shear_x/shear_y and rejects nonfinite values. Outside an advance callback, edits immediately reevaluate with Physics_Pose, without advancing simulation time. Within the callback, world evaluation and Physics_Update happen once afterward. Snapshot extraction is rejected until that phase completes. Recursive advance is rejected. Callbacks may close the instance safely; copied events remain valid and no freed native handle is evaluated afterward. Callback errors propagate after world evaluation for an instance that remains open.

Data and rendering contracts

  • An Asset owns shared atlas and skeleton setup data; each Instance owns its skeleton, state, mixes, physics time and render scratch. All calls belong to the application owner thread. Asset close rejects live instances. Close is idempotent; finalizers are a fallback, with native reference retention across finalizer order. Do not call finalize yourself.
  • snapshot copies borrowed native geometry, matrices and names. Old poses remain renderable after further updates and native close. Equal UV/index streams reuse the preceding snapshot's descriptors; positions are replaced. Renderer caches/retirement continue to use ordinary generic resources.
  • Regions, weighted/unweighted meshes, deformation, runtime constraints, atlas rotation/trimming, multiple pages, clipping and slot draw order use upstream evaluation. Bones are not ECS entities. Slot frames are their bone frames, not the attachment quad's local center or a point attachment's transform.
  • Skeleton coordinates remain Y-up. Reflect Y on the container once when composing into a usual Garnet Y-down scene; geometry and sockets agree.
  • Normal, additive, multiply and screen use shared per-draw blend state. The adapter preserves render command order and batching. Additive saturates premultiplied color and alpha. Multiply uses the destination color factor used by the upstream runtime renderer.
  • Tints use the runtime's packed straight RGBA values as linear material multipliers; texture sampling follows each generic texture's color-space and alpha metadata. Resolver texture dimensions and PMA must match atlas metadata. Clamped nearest/nearest and linear/linear sampling are supported; mipmaps, mixed filters and repeated atlas pages are rejected.
  • Two-color tint uses interpolated light and dark vertex streams. Point, path and bounding-box attachments participate in runtime evaluation when applicable. Public hit-test APIs and custom shader attachments remain future work.

Checks and example

From the workspace, scripts/check-composition unit includes the Spine and socket specs. The gl, gles, metal, and vulkan modes include region, deformed-mesh, clipping and overlapping-additive-slot pixel fixtures. scripts/check-composition example-spine builds the optional scene example; see garnet-spine-scene.

Implementation checkpoint: 219 unit examples pass, including 12 Spine and socket examples. GL, GLES, Metal and Vulkan each pass 56 shared integration examples; Vulkan ran with VK_LAYER_KHRONOS_validation. The native GLFW example presented 16 smoke frames and delivered the authored step event. Native builds, all three shard dependency checks (standalone, scene, composition), and Metal/Vulkan shader compilation pass. Initial launches stalled before entry in macOS dyld; the host subsequently recovered and these suites were executed successfully. Large-character performance and full format conformance are not claimed.

On the unlocked desktop, successive live captures also verified the socket marker following the region and remaining aligned after native window zoom.

Repository

spine

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 2
  • 1 day ago
  • November 30, 2026
License

Other

Links
Synced at

Wed, 02 Dec 2026 02:09:17 GMT

Languages