---
name: ferret-crowd
description: Use to put hundreds or thousands of animated characters in a Ferret scene (@ferret/crowd): any skinned model drawn full near, GPU-skinned (VAT) in the middle, as animated impostors far and as dots on the horizon; measured ladders, wandering agents, commands.
---

# Crowd

## When to use
Many animated characters on screen at once: streets, battles, stadiums, herds. For still objects (wrecks, trees, aircraft without bones) use `ferret-perspective` alone.

## The model
A `CrowdModel` is made once per character from a skinned instance (`mid`, its lightest tier) and a factory of full instances; agents of that model share its VAT set, impostor atlas and full-instance pool. Each agent is an entity with a `Perspective` ladder (`full`, `vat`, `impostor`, `point`, `none`) and a `CrowdAgent` (clip, phase, rate, tint); every rung shows the same moment of the same clip.

## Steps
1. `new BabylonBackend(scene)`, `world.addService(new PerspectiveService({ backend, budget: { maxFull } }))`, `world.addService(new CrowdService(backend))`.
2. A model: `crowdModelFromLibrary(scene, lib, id, { walk: 'cc-clips/Walk_Fwd', idle: 'cc-clips/Idle' }, { cache, maxFull })`, or `CrowdModel.prepare(scene, { key, clips, mid, full })` for your own glb.
3. Agents: `spawnCrowdAgent(world, model, { position, heading, clip, phase, rate, tint, wander | path })`, or move the entity yourself and call `agent.play(name)`.
4. Pass the persistent cache: the bakes and the measured ladder are kept by `key` (name the content and a version).
5. Look with `crowd.stats`, `crowd.list`, `perspective.force` (`?force=vat` in examples/crowd), and `node tools/crowd/check.mjs`.

## Check afterwards
`crowd.stats` shows a handful of `full`, most agents at `vat` / `impostor`; the run is the same with and without the view (agents move in the fixed step); the sample's numbers on the RTX hold.

## What usually goes wrong
- Agents slide: the clip's speed is measured from root motion or the feet; give `speed` in the clip spec when the measurement is wrong.
- VAT figures missing parts: parts must ride a bone (child nodes of a joint) or be skinned; loose objects elsewhere are left out.
- VAT figures in the wrong place or mirrored: a mesh with its own world transform; the set compensates `W * A * W^-1` with the first mesh's `W`, so all meshes of a model need the same world matrix.
- Shader errors with many bones and instances: the VAT rung uses 4 influences; do not add more per-instance attributes.
- Bake takes long the first time: it is cached; pass `cache` and keep `key` stable.

## Files

- `reference/crowd.md` — gameplay/crowd.md
- `reference/api-crowd.md` — every export of `@ferret/crowd` with signature and doc comment
- `reference/commands.md` — 4 commands of these packages with their arguments
