makeCrowd()
Animate many rigged entities on a budget. Each update picks every member's pose frame (at fps near the camera, farFps beyond near, frozen beyond freeze), takes the baked pose from a cache shared by members of the same variant, bakes missing ones within budgetMs (a member that does not fit keeps...
function makeCrowd(opts: CrowdOptions): Crowd;Defined in: engine/src/animation/crowd.ts:169
Animate many rigged entities on a budget. Each update picks every member's pose frame (at
fps near the camera, farFps beyond near, frozen beyond freeze), takes the baked pose
from a cache shared by members of the same variant, bakes missing ones within budgetMs
(a member that does not fit keeps last frame's pose), and either stamps it into the world
through a BrickStamper or draws it through an InstanceLayer.
Stamping buckets headings (headings, default 16) and costs brick uploads for every member
that moves; instances turn and move smoothly and write nothing into the world.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | CrowdOptions | Exactly one of stamper or instances is required. |
Returns
The crowd.
Example
const crowd = makeCrowd({ stamper: makeBrickStamper(renderer, { size: SIZE }), near: 140, farFps: 6, freeze: 700 });
const members: CrowdMember[] = rats.map((entity, i) => ({
id: i + 1, entity, variant: "rat", anim: makeAnimator(entity, "walk"), base: ratBase,
x: 100 + i * 20, y: 1, z: 100, yaw: 0,
}));
// per frame:
for (const m of members) m.anim.update(dt);
const stats = crowd.update(members, frame.camPos as [number, number, number]);makeAnimator()
A clip player for one rigged entity: the current clip, a crossfade from the previous one, and the clip events crossed since the last update. Pure and headless; one per animated instance, since it holds that instance's time.
makePoseCache()
Make a cache for baked poses (or anything else keyed by string). When the estimated size goes over maxBytes (default 48 MiB) the least recently used entries are evicted. makeCrowd makes one itself; make your own to share poses between crowds or to cache poses you bake by hand.