Animated vector characters with rigkit
rigkit turns a character drawn in Python into a Rive file (.riv). That is the product: what the app ships, what you test and what you demo. It also writes an animated SVG of the same poses, but only as an emergency fallback (a browser where Rive can't run, or a failed Rive load in production). The SVG is never a substitute for the .riv, and you never test on it.
Animation lives in one pose table (JavaScript) that moves named parts about named joints. Any character whose parts use those names plays every state.
reference image ─► draw.py (Python, rigkit) ─► <name>.rig.json ─► rigkit build ─┬─► <out>/<name>.riv (+ .riv.json) THE PRODUCT (needs the user's `rive login`)
front + side --preview / --parts parts tree, joints, art ├─► <out>/<name>/scene.rml the Rive source
rigkit.config.js: states, poses, switches, inputs, characters ────────────────┘─► <out>/<name>.rigkit.js metadata + SVG fallback
rigkit check ◄── every .riv up to date? (must pass)
Find rigkit first. It's either a dependency (node_modules/rigkit) or a folder next to the project. Its README has the full reference. rigkit.config.js in the project says which characters exist and which preset they use.
Ground rules
- Original characters only. A style or genre is fine. A recreation of an existing character is not: no copied names, looks or model sheets.
- Reference images stay out of git unless the user owns them. Commit the
draw.pyscripts, the config, and whatever the build writes that the app needs. - Rive is required, and signing in is the user's step.
rigkit buildpublishes the.rivand needs the user's ownrive login. Never sign in or enter credentials for them. If the build says the Rive CLI isn't signed in, stop. Tell the user to runrive loginand thenrigkit build, and do not report the work as done. Don't use--no-publishor--svg-onlyto get past it, and never offer the SVG as a substitute. - Done means
rigkit checkpasses. It fails while any.rivis missing, unstamped or older than its rig or config. Run it before you say the art work is finished. - Test and demo against the
.riv. Use the demo page or the app withrivset andstrict: true, never the SVG. - A Free Rive plan puts a watermark splash on published files. Say so, and don't try to remove it.
0. Which kind
- Side-on character (it stands on things and walks across the screen): the biped. Use
rigkit init <name>,rigkit.biped, and thebipedpreset: a front view for acting, a side view for travel. - Top-down game character (an RPG or adventure view, seen from above at a slant): use
rigkit init <name> --topdown,rigkit.topdown, and thetopdownpreset. It has three views (down, up, side) and afacinginput (0 down, 1 up, 2 right, 3 left) that picks the view in every state, with a centre anchor. The reference needs a down view, an up (back) view and a side view facing right. In the up view the arms go behind the body (topdown.up(..., arms='front')to change that), give hands their own art (hand-l,u-hand-l, ...) so they can be hidden, put a cloak or coat over the arms withu-coat, and draw ears (ear-l,u-ear-l,s-ear-n/s-ear-f) with their roots well inside the head, which is drawn over them. - Something that turns to face where it's going (a car, a ship, a top-down shooter): one view; the app rotates it.
- Prop (a chest, door, coin or plant): build the tree with
Partdirectly and give its config entry its ownstatesandposes, asexamples/chestdoes (anim.js). Props usually takeanchor: 'center'.
1. A reference
Ask the user for a turnaround: the character in a front view and a side view facing right. Both views should have the same proportions, flat colours, a bold even outline and a plain background, with the arms a little away from the body and the legs slightly apart.
Get the image one of these ways, and record it with rigkit source (or the editor's Source page), which keeps everything in <character>/source/source.json:
- A configured provider. Run
rigkit source providers <dir>to see which providers have a key, and which onegenerateinrigkit.config.jsnames. If one is ready, use it:rigkit source generate characters/<name> --turnaround --prompt "<the user's description>" # biped: front + side rigkit source generate characters/<name> --turnaround topdown --prompt "<description>" # down, up, side rigkit source generate characters/<name> --prompt "<change>" --reference base # from the chosen image--turnaroundturns a plain description into the model-sheet request the drawing step needs. Each image is a paid request on the user's account. Keep--countat 1 or 2, and ask before making more or before running several rounds. - No provider ready. Ask the user which they'd like:
openai(OPENAI_API_KEY),gemini(GEMINI_API_KEY), or neither. They set the key themselves, in their shell or in a git-ignored.envnext torigkit.config.js. Never ask them to paste a key into the chat, never write a key into any file, and never print one. - No API at all. The user makes the image in any tool (ChatGPT, an image app, their own drawing), and you
rigkit source importit. Or, if you have a browser and the user agrees, drive their own signed-in image tool for them. They sign in themselves; you never enter credentials.
Then:
import <dir> <image|video> [--time T | --frame N]andframebring in an image or a video frame.choosepicks the base (image,frame:Norg1:2).use --view front --stage WxHwrites the fittedreference-<view>.pngbesidedraw.py. Make one per view: crop each view out of the turnaround sheet first, or import each view separately.
Characters must be original: describe the user's character, never "like ". The turnaround prompt already asks for an original design.
Draw over the reference; don't trace it. Auto-tracing generated art gives lumpy outlines and parts that don't separate at the joints, so they tear when posed.
2. Draw the parts in code
Start a project with rigkit init <name>. It writes rigkit.config.js and a starter characters/<name>/draw.py. For a richer model, copy an example from rigkit's examples/.
Helpers live in rigkit.vec; all take absolute SVG path data in stage pixels:
capsule(x1, y1, x2, y2, r1, r2): a tapered limb with round ends. Use it for every arm and leg segment.capsule_open(...): the same outline without the start cap.ellipse,fill(d, colour, outline=True),line(d),band. Set the outline colour and width once withset_style(ink=..., line=...).sampleandpoly_dwork with shapely for geometry such as cutting a patch to an outline (seeclip()in the examples).
Rules that keep the rig clean when it moves:
-
Each moving piece is its own part. With the biped preset, use the art names listed at the top of
rigkit/biped.py:head,torso,upper-arm-l,forearm-l,thigh-l,shin-l,eye-white-l,pupil-l,brow-l,mouth-smile|flat|o|pant, … and the side view'ss-names, where-n/-fmark the near and far limb. Leaving a part out is fine; it comes out empty. -
Round joints. A child limb (forearm, shin) starts with an unoutlined round cap centred on its pivot, a hair narrower than the parent's end, and is drawn in front of it:
[fill(capsule(*a, *b, r1, r2), COLOUR, False), line(capsule_open(*a, *b, r1, r2))]Hips sit under the thighs' caps. Then a bent elbow or knee shows no gap and no doubled outline.
-
Joints at the cap centres. Pivots go in
JOINTS/SIDE_JOINTS, in stage coordinates, at the centre of each round cap. -
Side view far limbs are the near ones shifted a little (
FAR_DX) and a shade darker. -
Mirror, don't redraw.
mx(x)mirrors about the centre line, so left and right stay identical. -
Expressions are alternatives that share a joint (the mouths). The preset shows one per state through the
mouthswitch.
The script ends by building the character:
ch = Character('name', box=(W, H), scale=RIG_UNITS / STAGE_PX, feet=(W / 2, H - 4), stroke_scale=2)
ch.view('front', biped.front(P, JOINTS), feet=(CX, 950), reference='reference-front.png')
ch.view('side', biped.side(S, SIDE_JOINTS), feet=(CX, 950), reference='reference-side.png')
ch.group('mouth', biped.groups()['mouth'])
ch.run()
boxis the character's size as the app places it, in rig units.scalemaps the stage drawing into the box, for example (head top to sole in rig units) / (the same in stage px).stroke_scalethickens outlines that would be too thin once small.
For a creature that isn't a biped (a snake, a bird), build the tree yourself with Part(name, pivot, [art and child Parts]) and write a pose table to match.
Check the drawing (needs pip install shapely pymupdf pillow):
python3 draw.py --previewwritespreview-front.pngandpreview-side.png, each with the reference beside the drawing. Look at them with Read and compare silhouette, proportions and where the joints sit.python3 draw.py --turnwritespreview-turn.png: every view (side views also mirrored) at the stage size and at game size, open and blinking. Check it for things that change abruptly as the character turns: ears, eyes, hands, hats.- For eyes that should match across views, draw them all from one
rigkit.eyes.Eyedesign (EYE.at(x, y)for front and near eyes,EYE.far(x, y, foreshorten=, occlude=[...])for a three-quarter head's far eye) instead of separate ellipses per view.--turnwarns when an eye is mostly covered by a hat or nose. python3 draw.py --partsplusrigkit editorlets you look at parts over the reference in the browser, nudge them and edit points. Its edits go toparts/only; carry any change you want to keep back intodraw.py.
Repeat until it looks right.
3. Build
rigkit build
This has the Rive CLI check the markup, render <out>/<name>/build/<name>.png (look at it), and publish <out>/<name>.riv with its stamp <name>.riv.json. It also copies both to the character's riv path, if the config sets one, and writes scene.rml and the art module (metadata + SVG fallback).
If it fails with "the Rive CLI is not signed in": stop and ask the user to run rive login themselves, then build again. That is the whole fix. If the Rive CLI isn't installed, ask the user to install it.
rigkit demo
This opens a page that plays every character's .riv in every state, plus the inputs. A red banner means a .riv is missing or stale: fix that first. Use the browser pane: check the front view, the side view facing both ways (dir), gaze, a held paw, and the states that bend joints the most (climb, ex-overhead, scared). Leave the "SVG fallback" checkbox off; that copy isn't what ships.
rigkit check
This must pass (exit 0) before you call the work done. Put it in the project's tests or CI too.
To render one Rive state as an image, use the CLI's commands: viewport 400x400, fit contain, data state=<index> (the state's position in states), advance 400ms, screenshot out.png. Write advance in ms.
4. Animation (only when asked to change motion)
Everything is in the config, usually by spreading require('rigkit/presets/biped') and overriding parts of it:
states:{name: {view?, mouth?}}. The order is the number thestateinput takes, so add new states at the end.poses(options):{state: {frames, loop, parts: {part: {rot, x, y, sx, sy, opacity}}}}, at 60 fps. Build values withswing,keys,repeat,pairandstridefromrigkit/motion. Angles are in degrees, positive clockwise; offsets are in rig units from rest.switches: groups of parts where a state shows one option.inputs(options):blend(two poses, mixed by a number) ortoggle(a pose switched on by a condition).- Per-character
optionsincharacters[]:look(pupil travel),headLimit(a wide head makes raised arms bend at the elbow) andsimpleArmsfor the biped;strideandswingfor the topdown preset. - A character can bring its own setup.
states,poses,switches,inputs,marginandanchoron itscharacters[]entry replace the project's, so a prop and characters can share one project. - A
viewsinput ({type: 'number', views: [{view, mirror?}, ...]}) picks the view by number in every state. That's how top-down facing works.
5. Use it in an app
<script src="https://unpkg.com/@rive-app/[email protected]"></script>
<script src="rigkit/js/runtime/rigkit.js"></script>
<script src="rigkit-build/cat.rigkit.js"></script>
<div id="cat" style="width: 120px"></div>
<script>
const cat = rigkit.puppet(document.getElementById('cat'), rigkit.art.cat, {
riv: 'rigkit-build/cat.riv', // always: the .riv is what ships
strict: true, // in dev and tests: a Rive problem is an error, not a quiet switch to the SVG
});
cat.setState('walk'); cat.set('dir', -1); cat.set('lookX', 80); cat.set('holding', true);
</script>
The container sets the width; the character stands on its bottom edge. Ship the .riv and its stamp. In production, leave strict off so a failed load falls back to the SVG; fallback: true marks code that shows the SVG on purpose (a browser without Rive). Commit the build output the app loads, and say what you didn't check. If the .riv couldn't be published, say plainly that the work isn't finished until the user runs rive login and rigkit build.