lottie
Garnet Lottie
garnet-lottie evaluates a bounded Lottie JSON profile into ordinary retained Garnet vector drawings. It uses garnet-animation for timing and garnet-graphics-signals for renderer integration. Parsing does not initialize a native evaluator or renderer.
require "garnet-lottie"
document = Garnet::Lottie::Document.parse(File.read("animation.json"))
player = document.instantiate(:loop)
player.timeline.play
player.timeline.advance(delta_time)
texture = renderer.render(player.drawing, document.target)
# Explicit evaluation without a player:
drawing = document.sample(500.milliseconds)
Document.load(source) reads a Garnet::Content::Source with the same limits as parse (reading at most max_bytes plus one byte). Document#instantiate(mode, paused:) creates a Player, matching the Spine, Effekseer and model assets; Document#player is deprecated in its favour. Requiring the shard registers a default "lottie" importer (Garnet::Content::Importer.defaults). Lottie files are plain .json, so it claims no extension: track them with database.track(path, "lottie").
Players expose the existing timeline's seek, pause, once, loop and ping-pong controls. Backward seeks sample deterministically. Time is relative to the composition's in point. Layer intervals are half-open, so sampling the out point produces an empty drawing. Parenting inherits transforms, not opacity. Documents/players are owner-thread objects; returned drawings are immutable. Multiple players may share a document's bounded last-pose caches; interleaving them can cause additional extraction.
Initial profile
- Shape/null layers, layer parenting and nested shape groups.
- Animated position, anchor, scale, rotation and group/layer opacity.
- Split X/Y transform positions with independently animated scalar tracks, including layer, parent and shape-group transforms; explicit
s:falsevector positions are also accepted. Split positions require both axes and reject Z tracks. - Static and animated Bézier paths; animated rectangle/rounded-rectangle and ellipse dimensions.
- Solid RGBA fills/strokes, nonzero/even-odd fills, stroke caps/joins/miter.
- Animated stroke dash/gap lengths and offsets, including odd-length patterns.
- Static/animated scalar, vector and color properties, hold and per-component Bézier easing. RGB channels convert from sRGB to Garnet linear color.
- Retained geometry across transform changes; unchanged timeline reads reuse the signal snapshot and retained renderer output.
Unsupported rendering data raises ParseError with a JSON location. ParseError subclasses Lottie::Error < Garnet::Error (it was an ArgumentError before); nonpositive parse limits raise ArgumentError. This includes assets/precompositions/images/text, masks/mattes, gradients, trim paths and modifiers, blend modes, effects, expressions, auto orientation, spatial tangents, 3D, nonzero layer start offsets, time stretching, and discontinuous legacy end values. Styles spanning nested groups and interleaved geometry/style scopes are rejected. Hidden shapes and reversed primitive direction are rejected; hidden layers are supported. Paint colors require four channels. Keyframe times must strictly increase. Descriptive fields are accepted only where explicitly listed by the parser.
Stroke dash entries must alternate d/g, beginning with a dash; one optional o offset may appear at the end. Values use ordinary scalar tracks. Odd patterns repeat with alternating roles through the shared vector stroke implementation. Negative patterns and patterns whose total length is zero render as solid strokes.
Animated paths use the existing vector morph primitive and immutable animation tracks. Vertex order, vertex count and open/closed state must match across all keyframes and legacy end values; no automatic topology matching is performed. Vertices and their incoming/outgoing tangent offsets interpolate together. Linear, hold and bounded Bézier easing are supported; path easing with Y controls outside 0..1 is rejected at loading. Path keyframes use one shape per s/e array, strictly increasing times at nanosecond precision, and continuous legacy end values. Repeated hold poses reuse the same path and retained drawing.
Parsing defaults to 1 MiB, nesting depth 64 and 20,000 JSON values, with positive integer dimensions up to 16384. Numbers must be finite and within 1e9. Limits can be lowered using max_bytes, max_depth and max_items. The loader performs no external resource access. Parsed keyframe times must fit the timeline's signed nanosecond range; oversized frame/time conversions are rejected during loading. Composition duration must be at least one nanosecond and at most 4e9 seconds to leave room for a doubled ping-pong cycle. Sampling outside the composition interval yields an empty drawing, even if a layer's declared interval extends further.
Validation and evaluator choice
The evaluator experiment records a passing public-API extraction probe against pinned ThorVG source and the decision to use Crystal for this bounded profile. ThorVG is not a Garnet runtime dependency. Its CPU renderer generates independent test captures only.
Validation passes: 206 workspace unit examples (27 in this shard), and 52 shared integration examples each on GL, GLES, Metal and Vulkan. Fixtures cover translation, reverse seeking, retained geometry/output, parenting, stacking, even-odd paths, strokes, rounded rectangles, ellipses, nonuniform transforms, asymmetric easing, path morphing and isolated opacity. Morph fixtures also check that changing geometry preserves prior rendered output. Independent reference interiors match at 64×64 and 128×128; rasterizer-specific antialiased edge coverage is excluded. One pinned ThorVG group-opacity discrepancy is documented and retained as a capture; Garnet's atomic opacity follows the specification and a separate analytic regression. This evidence establishes the declared subset, not full Lottie/Bodymovin compatibility.
From this directory, run shards install, crystal spec, and crystal run examples/sample.cr for headless sampling. From the workspace root, run scripts/check-composition unit and sequential gl, gles, metal, vulkan modes for integration. Reference regeneration and checksum verification are documented in the experiment report.
For manual publication and scheduled ECS playback, see the optional lottie scene adapter.
lottie
- 0
- 0
- 0
- 1
- 4
- 1 day ago
- November 30, 2026
MIT License
Wed, 02 Dec 2026 02:09:19 GMT