FERRETGame engine over Babylon.js
Ferret

The live loop: change, frame

Skill ferret-live-edit · download all skills · SKILL.md

When to use#

Setting light, sun, fog, sky, post, where things stand, a behaviour's parameters, spawns, zones. Any "make it look like the reference" iteration. Never loop through package rebuild, dist build and browser load for these: that is 20 to 40 minutes a turn; a command is seconds.

The model#

The viewer (tools/viewer) is a headless Chromium on the NVIDIA GPU with an HTTP command API. A level folder opened in it has the editor session "edit" (ferret-level-editor): edit.patch changes the draft and, with live, the level reloads at once. Nothing reaches the files until edit.save, which writes only manifest.json, navmesh.bin, .ferret, .fprj under the served folder.

Steps#

  1. Start the viewer server on the level folder: FERRET_GPU=1 node tools/viewer/server.mjs --headless --port <p> --files <repo root> --level /files/<path to the level folder>, started at BelowNormal priority; commands POST /api/command {name,args}, frame GET /api/screenshot.png?w=&h=.
  2. edit.open {level:"edit", live:true} (for --level the name is always "edit"). Look first: camera.set {position,target,fov} or camera.view, a frame.
  3. Change by command: edit.patch {ops:[{op:"replace",path:"/environment/sun/intensity",value:2.5}]} (JSON pointers into the manifest: /environment/{sun,ambient,fog,sky,reflection,post,probes}, /entities/N/params/...), or the typed edit.entity.*, edit.spawn.*, edit.zone.*. Frame at once; compare with the reference (ferret-frame-check).
  4. edit.validate must be empty; edit.diff lists what changed; edit.save writes the manifest. edit.undo while trying.
  5. Materials are changed live like light: edit.material.set|get|list|remove {scope: type|instance, uid, material} (see ferret-level-editor); the command help lists what exists, do not invent one.
  6. Sources (tools/*.mjs, the build inputs) are changed after the person's "ok", from the saved manifest. A full rebuild of the package and the dist only when geometry changes, and once at the end.

Check afterwards#

The frame shows the change; edit.validate is empty; the saved manifest.json differs from the old one only by what edit.diff said (git diff); the renderer string is the RTX (WEBGL_debug_renderer_info says "NVIDIA GeForce RTX 3050"); the viewer and its Chromium are stopped when you finish.

What usually goes wrong#

  • edit.open fails "is not a parameter of this behaviour": the behaviour's static schema misses that param (add it to the schema in the engine).
  • A saved test value left in a tracked manifest: keep a copy of the file before experiments and restore it.
  • Capture windows over the person's work: headless only.
  • A viewer left running after the task: stop it and say so in the report.

Files#