voxolith

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

ParameterTypeDescription
optsCrowdOptionsExactly one of stamper or instances is required.

Returns

Crowd

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]);

On this page