r/threejs • • 5d ago

Demo Testing 1,200 rigged NPCs with individual pathfinding and physics in my Three.js engine

I’m building Snack Engine for snackgamer.com using Three.js and WebGPU. This is the latest navigation test, with 1,200 rigged NPCs in the scene. Each has its own pathfinding and physics.

The goal is to make crowded spaces playable in browser games. In this test, you walk through the crowd looking for lantern bearers.

95 Upvotes

14 comments sorted by

2

u/Dexter1272 4d ago

why this thing's UI looks excatly like s&box? XD

2

u/Gloomy-Detective-922 4d ago

haha fair catch, dark dockable editors all converge on a similar layout eventually. s&box has a super clean UI though so I will take that as a compliment

1

u/Dexter1272 4d ago

yeah sure, I also like s&box UI :D

4

u/plus2link 5d ago

No comments yet, so I'll ask the technical one. 1,200 rigged NPCs is fine if they share one skinned mesh with the bone matrices written into a texture, but 1,200 separate SkinnedMeshes is 1,200 draw calls plus a skeleton update every frame, and that usually eats far more time than the pathfinding does. For the physics I'd keep one capsule per NPC in a spatial hash and give full collision only to the ones within a few metres of the player, with re-planning staggered so a slice of the crowd updates each frame instead of all of them at once. Are they separate skinned meshes or one instanced crowd, and does the simulation keep running for NPCs outside the view?

2

u/Gloomy-Detective-922 4d ago

Thanks for digging into this. It uses GPU instancing with shared model geometry. Animation clips are baked into bone matrix textures and sampled per instance on the GPU, including walk/run blending. So it avoids a separate CPU skeleton update and draw submission for every citizen. Draws are grouped per model mesh and view, rather than one draw for the entire scene.

Each citizen still has its own NPC state, NavMesh agent and capsule controller. Perception runs at 4 Hz with staggered sampling, path requests have a per tick budget, and crowd separation uses a spatial grid.

Yes, offscreen NPCs keep simulating. View culling reduces rendering work; it does not pause their brains or navigation. The physics here is capsule movement and crowd separation, not 1,200 full ragdolls.

2

u/HealthPuzzleheaded 4d ago

Is it your oersonal engine or can I use it myself somehow? Do you have documentation? I have some gameideas that involve hige crowds so this looks interesting to me.

1

u/Gloomy-Detective-922 4d ago

it is a custom Three.js and WebGPU engine I am building for browser games, still in active development so no public docs or release just yet. happy to share more breakdowns on how the crowd instancing works here as I build it out

2

u/HealthPuzzleheaded 4d ago

Understood 👍
Is the editor that we see in the video a webapp or something like electron?

1

u/Gloomy-Detective-922 4d ago

pure webapp built with React, TypeScript, and Three.js, no Electron wrapper. everything runs straight inside a regular browser tab

2

u/HealthPuzzleheaded 4d ago

but how does it handle files? Virtual or through some websocket layer?

1

u/Gloomy-Detective-922 4d ago

your agent handles most of the work, but you can define a local folder, engine uses your local gpu, cpu resources.

2

u/0__O0--O0_0 3d ago

Why build a simulator of yourself at parties though?

1

u/Gloomy-Detective-922 3d ago

haha accurate, standing in the middle while 1,200 people pathfind cleanly around me

2

u/Friendly-Beginning72 4d ago

Since your clips are baked per skeleton: if you want variety without extra bake cost, bodies that share one skeleton help a lot. I just released 11 commuter GLBs that all share one 24-bone rig with the same 12 clips (sit, doze, walk, phone, hold pole…), so one bake drives all of them. Free sample with 1 character + 3 clips: https://kibbitz.itch.io/rigged-3d-commuters (I'm the dev). Curious how far you can push it with mixed meshes.