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#
new BabylonBackend(scene),world.addService(new PerspectiveService({ backend, budget, governor })).backend.represent(entity, 'full' | 'mesh', root);await backend.addImpostor(entity, 'impostor', { root | bytes, options, modelKey, cache }).entity.add(Perspective, { ladder, fade, fill, color }). Ladder thresholds: measure them (tools/perspective/thresholds.mjs), do not guess.- Animated crowds:
poseEveryon levels,loop: { duration, frames }with ananimbake for impostors. - Look with
perspective.list/stats/debug. - For Unreal: nothing in the game changes;
ue_buildtranslates the module and the facade givesBabylonBackendon UE (switch instead of cross-fade, nearest-view impostor quad, disc points; bake and measure stay in the browser). Cook an atlas withtools/perspective/ue/cook.mjs; check withtools/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
modelKeymust name the model's content, with a version. - An entity without a
Perspectiveis 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
Perspectiveentity 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#
reference/perspective.md— gameplay/perspective.mdreference/api-perspective.md— every export of@ferret/perspectivewith signature and doc commentreference/api-perspective-2.md— every export of@ferret/perspectivewith signature and doc commentreference/commands.md— 7 commands of these packages with their arguments