@babylonjs-toolkit/agent 1.2.11 → 1.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/lib/claude-settings.js +8 -1
- package/lib/doctor.js +2 -1
- package/lib/install.js +9 -7
- package/package.json +1 -1
- package/skills/bt-optimize/SKILL.md +94 -48
- package/skills/bt-optimize/planning.md +104 -0
- package/skills/bt-optimize/scripts/BtCombine.cs +18 -2
- package/skills/bt-optimize/scripts/BtOptimize.cs +817 -17
- package/skills/bt-optimize/scripts/qa/gltf-stats.mjs +74 -13
- package/skills/bt-optimize/scripts/qa/profile-browser.mjs +161 -2
- package/skills/bt-plan/SKILL.md +4 -1
- package/skills/bt-spec/SKILL.md +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Planning optimization work — the bt-optimize playbook for bt-spec, bt-plan and bt-execute
|
|
2
|
+
|
|
3
|
+
Read this when a spec, a plan (Quick or full) or a plan task is about making a Unity scene run faster or lighter as
|
|
4
|
+
BabylonJS web content — "optimize `Level01.unity`", "create a quick plan to optimize …", "spec out optimizing the
|
|
5
|
+
forest level", "cut the draw calls", "this level runs at 30 FPS in the browser". The work itself is bt-optimize's
|
|
6
|
+
pipeline (`SKILL.md`): the spec records the decisions below, the plan arranges bt-optimize's phases as tasks, and
|
|
7
|
+
bt-execute's builders run the skill's scripts — **never re-implement them**. Running `/bt-optimize <scene>` directly
|
|
8
|
+
does the same work in one go; a spec or plan adds the dashboard, checkpoints and an independent verifier.
|
|
9
|
+
|
|
10
|
+
Not this playbook: a slow web app, script or UI (that is bt-profile), or authoring a new level.
|
|
11
|
+
|
|
12
|
+
## What every optimization delivers
|
|
13
|
+
|
|
14
|
+
1. **One scene to export.** All work happens on the working copy `<Scene>_Optimized.unity` beside the source. The
|
|
15
|
+
source is never edited and stays the before/after baseline. The working copy is the scene to export and to load in
|
|
16
|
+
the game from then on. Its generated folders sit beside it and are part of it — never delete them while it is in
|
|
17
|
+
use: `<Scene>_Optimized/` (baked lighting), `_UnskinnedMeshes/`, `_RetargetedClips/`, `_VatCrowd/`,
|
|
18
|
+
`_CombinedMeshes/`. The report and the final message name the scene to export in their first lines, with that
|
|
19
|
+
table, so nobody has to guess which file is "the optimized one".
|
|
20
|
+
2. **Measured, not guessed.** Frame rate, frame time and draws per pass (shadow maps, depth, main, post) before → after
|
|
21
|
+
at the same pinned camera poses, plus the main-pass draws split by the object that owns them (`drawOwners`).
|
|
22
|
+
3. **The same look.** Unity captures of source and copy at the pinned poses, browser shots at the same poses, and —
|
|
23
|
+
when a web game loads the scene — a look in the game through the game's own camera (the export viewer's default
|
|
24
|
+
camera renders without the scene's post-processing).
|
|
25
|
+
|
|
26
|
+
## The standard decisions
|
|
27
|
+
|
|
28
|
+
State each in the spec's Functional Requirements / Decisions, or the plan's Codebase Analysis (Quick Plan) or
|
|
29
|
+
Decisions log (Heavy Plan). Change one only on the user's word or on measured evidence, and say which.
|
|
30
|
+
|
|
31
|
+
| # | Decision | Default | How it is proven |
|
|
32
|
+
|---|---|---|---|
|
|
33
|
+
| O1 | Work on the working copy; the source is the baseline | `--out` default `<Scene>_Optimized.unity`, rebuilt with `--reset` when the plan starts over | `BtCombine.PrepareCopy`; `working-copy.txt` names the source |
|
|
34
|
+
| O2 | Account for every draw before planning fixes | Pinned poses `--pin 40,60,75` (inside the scene's own motion) saved to the feature's `tests/poses-pinned.json` and replayed with `--poses` | Every owner group of 5%+ of main-pass draws is fixed or has a measured reason; `mainDraws` equals `passes.main` |
|
|
35
|
+
| O3 | Unskin every skinned mesh that does not deform | Tune `unskinRigid` — one-bone imports, offset bind poses, script hosts, renderer curves, frozen poses | `BtOptimize.Verify`: no rigid skinned mesh left; every remaining SkinnedMeshRenderer has its reason in `tune.md` |
|
|
36
|
+
| O4 | Instance every repeated mesh | `instanceRepeatsFrom` 4; **2** when the user asks to instance "wherever possible" | Every repeated shape in `drawOwners.repeats` is one instanced draw or listed with its reason; `Verify`: no repeat lightmapped or probe-lit |
|
|
37
|
+
| O5 | Nothing that moves is static | Tune `unfreezeAnimated` (static objects a clip, Timeline or physics body moves) | `Verify`: no static mover |
|
|
38
|
+
| O6 | Deforming crowds draw instanced | Tune `vatCrowdsFrom` 4: AnimatorControlRig VAT mode, VAT materials, renderer world scale 1, probes off | One draw per crowd material in view, each copy still animating its own state in the browser. One draw for a whole multi-colour crowd needs the runtime per-skin texture array (`shader-materials.md`) — a web-game follow-up |
|
|
39
|
+
| O7 | Lighting | Practical point / spot lights with no browser driver baked; shadowed ones stay runtime with shadows off. **"Keep the current look / lighting"** → `--keep-gi` and the copy's lighting settings equal the source's | `Verify`: lighting equal to the source, no new GI contributors (with `--keep-gi`); captures match |
|
|
40
|
+
| O8 | Merge static meshes only when it saves draws | Run `BtCombine.Analyze`; merge when `combine-plan.md` shows draws saved. A level already drawn as one renderer per material saves nothing → `--no-combine`, recorded with the plan's numbers | `BtCombine.Verify` problems=0 when merged |
|
|
41
|
+
| O9 | Prune shadow casters whose shadow lands on nothing visible | Candidates from `survey.md` (flat surfaces) and the browser's per-cascade dump (`--casters true`: roads, ground, water, far backdrops); `BtOptimize.PruneShadowCasters` with the list | Each entry kept only when Unity captures at every pinned pose show no shadow change; shadow-map draws fall |
|
|
42
|
+
| O10 | Project-wide levers are proposals, not changes | Shadow cascade count / distance, KTX2 textures, CSS-pixel resolution change every scene: measure and propose them as follow-ups unless the user asked | — |
|
|
43
|
+
| O11 | Anything the engine cannot do is a re-runnable script | One project script (`AgentScripts/<slug>/…`) with entry points run after Tune, each safe to re-run after `--reset` | The report's **Redo after `--reset`** lists the full sequence |
|
|
44
|
+
|
|
45
|
+
**Questions worth asking** (at most one, with the recommended default; everything else is inferred and stated):
|
|
46
|
+
keep the current lighting exactly (O7 `--keep-gi`, no merging) or allow a re-bake that merging needs — default: keep
|
|
47
|
+
when the lighting was hand-tuned or the user praises the current look, otherwise allow. Never ask about thresholds,
|
|
48
|
+
poses or tools — the defaults above are the answer.
|
|
49
|
+
|
|
50
|
+
**Find these in the project before writing** (never ask): the scene path; whether its export is current
|
|
51
|
+
(`bt_status` → `exportRoot`, `scenes/<scene>.gltf`); which web game code loads the export by name (search the web app
|
|
52
|
+
for the lower-cased scene file name) — the plan's last task points it at the optimized export, a one-line change; an
|
|
53
|
+
earlier run's `.agents/optimize/<Scene>/` (survey, profiles, poses) to reuse; Animators, Timelines and crowds the
|
|
54
|
+
survey names.
|
|
55
|
+
|
|
56
|
+
## The standard task list
|
|
57
|
+
|
|
58
|
+
All Unity tasks share one track (one editor per project). Each phase runs one costly session (export + pinned
|
|
59
|
+
profile) that proves every task in it.
|
|
60
|
+
|
|
61
|
+
### Phase 1 — Baseline and the instancing pass
|
|
62
|
+
|
|
63
|
+
- **T1 — Baseline, draw by draw.** Export the source when stale; bt-optimize Phases 0–2 with `--analyze` and the
|
|
64
|
+
pinned profile run with `--casters true`; copy the pinned poses to `tests/poses-pinned.json`. Write
|
|
65
|
+
`tests/baseline.md`: draws per pass and FPS at each pin, the per-owner table, every repeated shape and what stops it
|
|
66
|
+
instancing, every SkinnedMeshRenderer with its verdict, the shadow casters per cascade. Unity captures of the source
|
|
67
|
+
at every pinned pose (`PoseView`) — the look reference.
|
|
68
|
+
Tests: `mainDraws` = `passes.main` at every pin; every SkinnedMeshRenderer has a verdict. Verify level: live.
|
|
69
|
+
- **T2 — Working copy: unskin, unfreeze, instance, VAT crowds, lights; bake; export; measure.** Phase 3 (`PrepareCopy`,
|
|
70
|
+
`Tune` with the decided options; Analyze / Apply only when O8 says merge), Phase 4 (bake, `BtOptimize.Verify`,
|
|
71
|
+
`BtCombine.Verify` when merged), Phase 5 captures at the pinned poses, Phase 6 export + pinned profile replaying
|
|
72
|
+
`tests/poses-pinned.json`, `compare-profiles` into `tests/compare-T2.md`.
|
|
73
|
+
Tests: `Verify` problems=0. Acceptance: main-pass draws fall at every pin; every repeat one draw or its reason;
|
|
74
|
+
captures match T1's; 0 console errors. Verify level: live.
|
|
75
|
+
|
|
76
|
+
### Phase 2 — Shadow casters, final proof
|
|
77
|
+
|
|
78
|
+
- **T3 — Prune shadow casters.** From T2's per-cascade dump and the survey's candidates write
|
|
79
|
+
`tests/shadow-casters.md` (each caster's draws per cascade, verdict and reason); `PruneShadowCasters` with the prune
|
|
80
|
+
list; captures at every pinned pose — drop any entry whose removal shows, re-run the prune; re-bake; `Verify`.
|
|
81
|
+
Acceptance: shadow-map draws fall at the pins; every shadow visible in T1's captures is still there.
|
|
82
|
+
Verify level: live.
|
|
83
|
+
- **T4 — Final measure, game check, report.** One export; pinned + timeline profiles; `compare-profiles` T1 → final into
|
|
84
|
+
`tests/compare-final.md`; point the web game at the optimized export when it loads the source's; drive the game to
|
|
85
|
+
the pinned views and check the look through the game's own camera (post-processing on), animated props and crowds
|
|
86
|
+
animating, 0 console errors; bt-optimize Phase 8 report with **Export this scene**, **Draws by owner**, **What stayed
|
|
87
|
+
and why** and **Redo after `--reset`**. Verify level: live.
|
|
88
|
+
|
|
89
|
+
Add a task only for real extra work: a merge pass worth its own checkpoint, a project script (O11), a runtime
|
|
90
|
+
follow-up the user asked for (a per-skin VAT array, a camera's post chain). Put a project-wide lever (O10) in the
|
|
91
|
+
follow-ups, not the plan.
|
|
92
|
+
|
|
93
|
+
**Estimate:** Unity rate per task; the first VAT crowd in a project and the game check are outsized (2×). Biggest
|
|
94
|
+
uncertainty to name: whether the crowd's Animators keep their own state in the VAT export, and how long the bake takes.
|
|
95
|
+
|
|
96
|
+
## Executing it (bt-execute)
|
|
97
|
+
|
|
98
|
+
- Builders copy the skill's `scripts/` into `AgentScripts/bt-optimize/` and `scripts/qa/` into
|
|
99
|
+
`.agents/optimize/.qa-tools/` (Phase 0) and run them; the plan's task brief carries the relevant `SKILL.md` phases and
|
|
100
|
+
the Tune JSON. Never hand-edit the working copy outside a script: `--reset` would lose it.
|
|
101
|
+
- The verifier gets **What this skill guarantees** from `SKILL.md`, the `Verify` output and the paired captures. A
|
|
102
|
+
pinned comparison counts only when the paired shots show the same view.
|
|
103
|
+
- Snapshots per visual task: the Unity capture and the browser shot at one pinned pose, before → after.
|
|
104
|
+
- Never commit, and never delete the source, the working copy or an earlier copy; tidying old scenes is the user's call.
|
|
@@ -235,8 +235,14 @@ public static class BtCombine
|
|
|
235
235
|
if (AssetDatabase.IsValidFolder(unskinnedFolder)) AssetDatabase.DeleteAsset(unskinnedFolder);
|
|
236
236
|
string retargetedFolder = RetargetedClipFolderFor(outputScene);
|
|
237
237
|
if (AssetDatabase.IsValidFolder(retargetedFolder)) AssetDatabase.DeleteAsset(retargetedFolder);
|
|
238
|
-
string
|
|
239
|
-
if (
|
|
238
|
+
string vatCrowdFolder = VatCrowdFolderFor(outputScene);
|
|
239
|
+
if (AssetDatabase.IsValidFolder(vatCrowdFolder)) AssetDatabase.DeleteAsset(vatCrowdFolder);
|
|
240
|
+
// The fresh copy casts shadows as the source does, so a previous prune record no longer describes it.
|
|
241
|
+
foreach (string record in new[] { "combine-manifest.json", "pruned-casters.json" })
|
|
242
|
+
{
|
|
243
|
+
string recordPath = Path.Combine(ReportFolderFor(outputScene), record);
|
|
244
|
+
if (File.Exists(recordPath)) File.Delete(recordPath);
|
|
245
|
+
}
|
|
240
246
|
}
|
|
241
247
|
var scene = EditorSceneManager.OpenScene(outputScene, OpenSceneMode.Single);
|
|
242
248
|
Directory.CreateDirectory(ReportFolderFor(outputScene));
|
|
@@ -254,6 +260,7 @@ public static class BtCombine
|
|
|
254
260
|
bool meshesDeleted = AssetDatabase.DeleteAsset(MeshFolderFor(outputScene));
|
|
255
261
|
AssetDatabase.DeleteAsset(UnskinnedMeshFolderFor(outputScene));
|
|
256
262
|
AssetDatabase.DeleteAsset(RetargetedClipFolderFor(outputScene));
|
|
263
|
+
AssetDatabase.DeleteAsset(VatCrowdFolderFor(outputScene));
|
|
257
264
|
bool lightingDeleted = AssetDatabase.DeleteAsset(Path.ChangeExtension(outputScene, null).Replace('\\', '/'));
|
|
258
265
|
string reportFolder = ReportFolderFor(outputScene);
|
|
259
266
|
if (Directory.Exists(reportFolder)) Directory.Delete(reportFolder, true);
|
|
@@ -1632,6 +1639,15 @@ public static class BtCombine
|
|
|
1632
1639
|
return Path.GetDirectoryName(scenePath).Replace('\\', '/') + "/" + Path.GetFileNameWithoutExtension(scenePath) + "_RetargetedClips";
|
|
1633
1640
|
}
|
|
1634
1641
|
|
|
1642
|
+
/// <summary>
|
|
1643
|
+
/// Folder for the vertex-animation material copies BtOptimize.Tune makes for a VAT crowd: <scene folder>/<scene>_VatCrowd.
|
|
1644
|
+
/// Keep the name in step with BtOptimize.VatCrowdFolder.
|
|
1645
|
+
/// </summary>
|
|
1646
|
+
private static string VatCrowdFolderFor(string scenePath)
|
|
1647
|
+
{
|
|
1648
|
+
return Path.GetDirectoryName(scenePath).Replace('\\', '/') + "/" + Path.GetFileNameWithoutExtension(scenePath) + "_VatCrowd";
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1635
1651
|
/// <summary>Folder for a scene's reports: <project>/.agents/optimize/<scene>.</summary>
|
|
1636
1652
|
private static string ReportFolderFor(string scenePath)
|
|
1637
1653
|
{
|