FERRETGame engine over Babylon.js
Ferret

Perspective

Skill ferret-perspective · download all skills · SKILL.md

When to use#

Many objects at a distance; frame over budget because of detail nobody can see.

The model#

Size in pixels of the bounding sphere picks a rung of a ladder per entity; the simulation never sees the camera (the service runs in update). Rungs: full, mesh, impostor, point, none. Hysteresis, dither cross-fade, maxFull/maxMesh budget, FrameGovernor.

Steps#

  1. new BabylonBackend(scene), world.addService(new PerspectiveService({ backend, budget, governor })).
  2. backend.represent(entity, 'full' | 'mesh', root); await backend.addImpostor(entity, 'impostor', { root | bytes, options, modelKey, cache }).
  3. entity.add(Perspective, { ladder, fade, fill, color }). Ladder thresholds: measure them (tools/perspective/thresholds.mjs), do not guess.
  4. Animated crowds: poseEvery on levels, loop: { duration, frames } with an anim bake for impostors.
  5. Look with perspective.list/stats/debug.
  6. For Unreal: nothing in the game changes; ue_build translates the module and the facade gives BabylonBackend on UE (switch instead of cross-fade, nearest-view impostor quad, disc points; bake and measure stay in the browser). Cook an atlas with tools/perspective/ue/cook.mjs; check with tools/perspective/ue/proof.mjs.

Ships and boats#

Every craft that can be far is an entity with a Perspective ladder [full, point] (add the component once the model is in, so the bounds exist); a ship at the horizon is then a point that grows into the model by size, never a model that appears whole. A rung for soldiers in low postures: draw the standing and the low picture together as out and in with the amount of the posture as the mix, so a man does not jump (examples/dunkirk/src/far-crowd.ts).

Check afterwards#

perspective.stats shows most objects at cheap rungs; fixed-step state is identical with and without the service (the test does this); draw calls drop.

What usually goes wrong#

  • Impostor looks darker or blocky: it is a picture of 12 x 12 views; use it only at 3-5 px, a mesh above.
  • Scene still slow: the disabled meshes of unused rungs still exist; make them with representLazy.
  • Cache never hit: the modelKey must name the model's content, with a version.
  • An entity without a Perspective is never touched.
  • Thresholds were measured for aircraft only; for people measure the model (perspective.thresholds) before trusting them.
  • On UE the impostor is one baked view, so it is good only down to about 15 px; keep a mesh above that.
  • The inspector does not show rungs; use the commands.
  • Craft that come and go (ships, boats): spawn them beyond the visibility so the fog hides them, create the Perspective entity after the model is ready, remove them only out of sight. Never create one in view.

Relevance and part culling#

RelevanceService (@ferret/view: how soon a thing can be in the frame, by camera mode) and PartCuller (small parts of a model dropped by pixels): see the section of the same name in reference/perspective.md.

Files#