@babylonjs-toolkit/agent 1.2.11 → 1.2.12
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 +2 -2
- package/package.json +1 -1
- package/skills/bt-optimize/SKILL.md +81 -45
- package/skills/bt-optimize/planning.md +104 -0
- package/skills/bt-optimize/scripts/BtCombine.cs +18 -2
- package/skills/bt-optimize/scripts/BtOptimize.cs +739 -15
- package/skills/bt-optimize/scripts/qa/profile-browser.mjs +50 -1
- package/skills/bt-plan/SKILL.md +4 -1
- package/skills/bt-spec/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Babylon Toolkit Desktop Agent (1.2.
|
|
1
|
+
# Babylon Toolkit Desktop Agent (1.2.12)
|
|
2
2
|
|
|
3
3
|
The desktop agent owns the entire pipeline end to end — frontend and UI design, gameplay code, shaders, generated art and audio, 3D models in headless Blender, whole game levels and prefabs in a terminal-driven Unity Editor, the interactive glTF export, the web build, the dev server, and visual QA by screenshotting both Unity and the running browser.
|
|
4
4
|
|
|
@@ -283,7 +283,7 @@ pair or schedule the bridge.
|
|
|
283
283
|
| [`bt-hero`](skills/bt-hero/SKILL.md) | `/bt-hero` | Create smooth cinematic 3D scrolling hero sections. |
|
|
284
284
|
| [`bt-atlas`](skills/bt-atlas/SKILL.md) | `/bt-atlas` | Generate texture atlas skin variations. |
|
|
285
285
|
| [`bt-unwrap`](skills/bt-unwrap/SKILL.md) | `/bt-unwrap` | Turn a rough AI-generated (or any) 3D model into a clean, web-ready game asset in one headless Blender run: repair the geometry, decimate to a face budget (lost shape re-baked as a normal map), orient it to glTF / BabylonJS forward at real-world scale, give it a new UV layout of large islands (less space for surfaces nobody sees), bake the source textures onto it, and paint the sharp reference images back on — straight and three-quarter views, each camera solved from the silhouette, one view per face, seams kept off logos, and the model's own texture kept where images and geometry disagree (engines, cockpits) — so a melted, fragmented texture comes out crisp instead of smeared. GLB / glTF / FBX / OBJ / USD / PLY / STL / Alembic / .blend in; GLB / glTF / FBX / OBJ / USD / .blend out with 2048 WebP textures (4096 on request), a single-sided PBR material, optional Draco and LODs, before/after renders, coverage and clutter maps, the UV island map for `bt-atlas`, and a JSON report with acceptance checks for plans. `--refs`, `--faces`, `--length`, `--texture-size`, `--unwrap views\|smart\|keep`, `--analyze`. |
|
|
286
|
-
| [`bt-optimize`](skills/bt-optimize/SKILL.md) | `/bt-optimize` | Make an exported Unity scene run fast in the browser: profile the BabylonJS frame (draw calls per pass,
|
|
286
|
+
| [`bt-optimize`](skills/bt-optimize/SKILL.md) | `/bt-optimize` | Make an exported Unity scene run fast in the browser: profile the BabylonJS frame (draw calls per pass, every main-pass draw by the object that owns it, shadow casters per cascade, lights, post-processing), then fix the causes on a copy of the scene — the one scene to export afterwards: rigid skinned meshes turned into plain meshes, repeated props instanced (off lightmaps and light probes), static objects that animate unfrozen, repeated deforming characters made an instanced VAT crowd, practical lights baked, point / spot shadows removed, shadow casters that shadow nothing visible pruned, static / lightmap unlocks, and static meshes and LOD groups merged when that saves draws; then re-bake, verify the copy against its source, export, and prove frame rate and look against the original in Unity, the browser and the game. Its `planning.md` is the playbook bt-spec and bt-plan follow to spec or Quick Plan the same work ("create a quick plan to optimize Level01.unity"). `--no-combine`, `--combine-only`, `--keep-gi`, `--instance-from:2`. |
|
|
287
287
|
| [`bt-profile`](skills/bt-profile/SKILL.md) | `/bt-profile` | Find what makes a web app slow and list the fixes (spec them with `/bt-spec`, or apply them with `--auto-fix`) — built for BabylonJS / Babylon Toolkit games, usable on any front end (give it a URL and the project folder): drive the running game in Chrome through a repeatable scenario (a cold load, a level start, a countdown), record the CPU profile, allocations, every frame and every GPU pipeline compile (with `--gpu-cold`, as on a first visit), map each millisecond to its source line and owner (your code, the toolkit runtime, BabylonJS, Havok, React), then list the fixes, or with `--auto-fix` apply them one at a time and re-measure each. Writes `.agents/profile/<slug>/dashboard.html` (live progress, Print / Download PDF) and a spec-ready `findings.md`. `--auto-fix`, `--snapshots`, `--watch`, `--gpu-cold`, `--stop`, `--resume`, `--restart`, `--project`, `--slug`. |
|
|
288
288
|
|
|
289
289
|
Every tool derives the slash-command from the **folder name** (`bt-spec/` → `/bt-spec`) and reads
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: bt-optimize
|
|
3
|
-
description: "The Babylon Toolkit Optimize Skill makes an exported Unity scene run fast as BabylonJS web content. It measures the exported scene in the browser first (frame rate, draw calls per pass — shadow maps, depth / velocity buffers, main pass, post — CPU hot spots, light binding), accounts for every draw by the object that owns it, surveys the Unity scene for the causes, then fixes them on a copy of the scene: skinned meshes that need no skinning (one-bone DAE / FBX imports — coins, item boxes, trees, signs) turned into plain meshes so repeated props share one instanced draw, runtime practical lights baked, realtime point / spot shadows removed, non-moving props marked static, probe-lit props with lightmap UVs lightmapped, no-op post effects removed, and static meshes and LOD groups merged with the Babylon Toolkit MeshCombiner (packed source lightmap UVs, mirrored pieces, LOD clusters with corrected switch distances). It re-bakes, exports, and proves the result — frame rate and draw calls before → after at the same pinned views, and the same look in Unity and in the
|
|
3
|
+
description: "The Babylon Toolkit Optimize Skill makes an exported Unity scene run fast as BabylonJS web content. It measures the exported scene in the browser first (frame rate, draw calls per pass — shadow maps, depth / velocity buffers, main pass, post — CPU hot spots, light binding), accounts for every draw by the object that owns it, surveys the Unity scene for the causes, then fixes them on a copy of the scene — the one scene to export afterwards: skinned meshes that need no skinning (one-bone DAE / FBX imports — coins, item boxes, trees, signs) turned into plain meshes so repeated props share one instanced draw, repeated props kept off lightmaps and light probes so they instance, static objects that animate made non-static, repeated deforming characters turned into an instanced vertex-animation (VAT) crowd, runtime practical lights baked, realtime point / spot shadows removed, shadow casters whose shadow lands on nothing visible pruned, non-moving props marked static, probe-lit props with lightmap UVs lightmapped, no-op post effects removed, and static meshes and LOD groups merged with the Babylon Toolkit MeshCombiner when that saves draws (packed source lightmap UVs, mirrored pieces, LOD clusters with corrected switch distances). It re-bakes, verifies the copy against its source, exports, and proves the result — frame rate and draw calls before → after at the same pinned views, and the same look in Unity, in the browser and in the game. Every decision is written down with its reason. Its `planning.md` is the playbook bt-spec and bt-plan follow to spec or plan the same work (\"create a quick plan to optimize Level01.unity\"). Use when the user wants a Unity scene to run faster or lighter in the browser, or wants static meshes / LOD groups combined (e.g. `/bt-optimize Assets/Scenes/Level01.unity`, `/bt-optimize --combine-only`)."
|
|
4
4
|
allowed-tools: Read, Grep, Glob, Edit, Write, Bash, WebFetch(domain:raw.githubusercontent.com)
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -8,13 +8,19 @@ You are an EXPERT Babylon Toolkit, BabylonJS and Unity technical artist and web-
|
|
|
8
8
|
|
|
9
9
|
Use the user's message after the skill name as the `arguments`.
|
|
10
10
|
|
|
11
|
+
**Spec or plan instead of a direct run?** When the user asks to spec, plan or Quick Plan an optimization ("create a
|
|
12
|
+
quick plan to optimize `Level01.unity`"), bt-spec / bt-plan run and read this skill's [`planning.md`](planning.md): the
|
|
13
|
+
standard decisions (O1–O11) and task list built on the phases below. bt-execute's builders then run this skill's
|
|
14
|
+
scripts task by task. The work and its proof are the same either way.
|
|
15
|
+
|
|
11
16
|
---
|
|
12
17
|
|
|
13
18
|
# Invocation
|
|
14
19
|
|
|
15
20
|
```
|
|
16
21
|
/bt-optimize [<scene asset path>] [--out:<asset path>] [--analyze] [--reset]
|
|
17
|
-
[--no-combine | --combine-only] [--no-tune:unskin,lights,static,lightmaps,post] [--instance-from:4] [--keep-gi]
|
|
22
|
+
[--no-combine | --combine-only] [--no-tune:unskin,unfreeze,lights,static,lightmaps,post,vat] [--instance-from:4] [--vat-from:4] [--keep-gi]
|
|
23
|
+
[--no-prune-casters]
|
|
18
24
|
[--keep-lights:Name1,Prefix*] [--bake-shadowed-lights] [--exclude:Name1,Prefix*] [--only:Path/A,Path/B]
|
|
19
25
|
[--cell:15] [--spread:3] [--atlas-share:0.45] [--no-shadergraphs] [--no-lods] [--shaders:Name1,Name2]
|
|
20
26
|
[--textures:ktx2] [--resolution:css] [--no-bake] [--no-export] [--no-browser] [--pins:40,60] [--times:10,20,30,45,60,90]
|
|
@@ -26,8 +32,10 @@ Use the user's message after the skill name as the `arguments`.
|
|
|
26
32
|
- **`--reset`** — start again from the source (re-copies it over the working copy, deletes the previous merged meshes and reports).
|
|
27
33
|
- **`--no-combine`** — every optimization except merging meshes.
|
|
28
34
|
- **`--combine-only`** — only merge static meshes and LOD groups (no light, static, lightmap or post changes).
|
|
29
|
-
- **`--no-tune:`** — skip individual tune steps: `unskin` (rigid skinned meshes → plain meshes), `lights` (bake practical lights / drop point-spot shadows), `static` (mark non-moving props static), `lightmaps` (probe-lit → lightmapped), `post` (no-op post effects).
|
|
30
|
-
- **`--instance-from:`** — a mesh drawn this many times or more (same mesh and materials) is never lightmapped, and its copies get Light Probes Off so they share one instanced draw instead of each getting its own mesh (default `4`; `0` turns it off).
|
|
35
|
+
- **`--no-tune:`** — skip individual tune steps: `unskin` (rigid skinned meshes → plain meshes), `unfreeze` (clear static flags on objects that animate), `lights` (bake practical lights / drop point-spot shadows), `static` (mark non-moving props static), `lightmaps` (probe-lit → lightmapped), `post` (no-op post effects), `vat` (deforming crowds → VAT).
|
|
36
|
+
- **`--instance-from:`** — a mesh drawn this many times or more (same mesh and materials) is never lightmapped, and its copies get Light Probes Off so they share one instanced draw instead of each getting its own mesh (default `4`; `2` = instance wherever possible; `0` turns it off).
|
|
37
|
+
- **`--vat-from:`** — a really deforming character with this many copies or more becomes an instanced vertex-animation crowd (default `4`; `0` turns it off).
|
|
38
|
+
- **`--no-prune-casters`** — skip Phase 3's shadow-caster prune.
|
|
31
39
|
- **`--keep-gi`** — keep Contribute GI exactly as the source has it: no tune step adds it to an object that did not contribute GI in the source, so the re-bake keeps the source's indirect light (default off: merging needs the newly lightmapped props).
|
|
32
40
|
- **`--keep-lights:`** — light names (or prefixes ending in `*`) that stay realtime / Mixed.
|
|
33
41
|
- **`--bake-shadowed-lights`** — also bake point / spot lights that cast realtime shadows (default: they stay realtime with their shadows turned off).
|
|
@@ -47,7 +55,10 @@ Use the user's message after the skill name as the `arguments`.
|
|
|
47
55
|
4. **It looks the same.** Re-baked, then compared in Unity (LOD0 and LOD1) and in the browser at matching views. Expected, stated differences: baked practical lights lose their specular highlights and their realtime shadows on moving objects (they never had flicker or distance culling in the browser — those were Unity-only scripts).
|
|
48
56
|
5. **No vertex bloat.** Merges use the toolkit's `UnityMeshSimplifier.MeshCombiner` in *Pack Source Lightmap UVs* mode — each source keeps its own lightmap UVs, packed at its original texel density.
|
|
49
57
|
6. **Every draw is accounted for — ENFORCED.** Per-pass totals say *where* the frame goes; they never say *what* to fix. At every pinned view the profiler's `drawOwners` splits the main-pass draws by the scene object that owns them and lists every shape drawn more than once with why its copies do not share one draw. The plan and the report carry that table. **Every owner group of 5% or more of the main-pass draws is either fixed or has a written, measured reason it cannot be** — "it has an Animator", "it is skinned" or "a rule kept it" is not a reason on its own (see 7). The skill is not done while a large group is unexamined: a run that cut shadow draws but left 129 of 202 main-pass draws to copies of 8 props, all one-bone skinned meshes nobody looked at, was a failed optimization.
|
|
50
|
-
7. **An Animator or a SkinnedMeshRenderer is evidence to check, never a reason to skip.** Look at what the clip actually animates (`survey.md` → Skinned meshes): a spawn pop that scales the object, a spin, a collider toggle all work on a plain mesh. Only real deformation (animated bones, blend shapes, cloth) needs skinning. Repeated props are the largest draw group in most levels after the level geometry — always check them.
|
|
58
|
+
7. **An Animator or a SkinnedMeshRenderer is evidence to check, never a reason to skip.** Look at what the clip actually animates (`survey.md` → Skinned meshes): a spawn pop that scales the object, a spin, a collider toggle all work on a plain mesh. Only real deformation (animated bones, blend shapes, cloth) needs skinning — and repeated deforming characters still instance as a VAT crowd. Repeated props are the largest draw group in most levels after the level geometry — always check them.
|
|
59
|
+
8. **One scene to export, named.** The working copy is the result. The report and the final message open with **Export this scene**: its path, its export file name, the source kept as the untouched baseline, and the folders beside the copy that belong to it (never delete them while it is in use). Nobody should have to ask which of the scenes is the optimized one.
|
|
60
|
+
9. **Verified against its source before export.** `BtOptimize.Verify` (and `BtCombine.Verify` after a merge) ends with problems=0: scene saved, no capture camera left, every camera enabled as in the source, lighting settings as in the source, no rigid skinned mesh left, no repeat lightmapped or probe-lit, no static object that moves, crowds and pruned casters set as recorded.
|
|
61
|
+
10. **Everything is re-runnable.** A step the engine cannot do goes in one project script with entry points run after Tune — never a hand edit of the working copy, which `--reset` would lose. The report's **Redo after `--reset`** lists the whole sequence.
|
|
51
62
|
|
|
52
63
|
# Talk to the user while you work
|
|
53
64
|
|
|
@@ -57,18 +68,23 @@ Long runs lose people. At every phase change post one short plain-language updat
|
|
|
57
68
|
|
|
58
69
|
# How a BabylonJS frame spends its time — what to look for
|
|
59
70
|
|
|
60
|
-
Learned on a 2,400-renderer URP
|
|
71
|
+
Learned on measured levels — a 2,400-renderer URP scene that ran 8–26 FPS (1–5 FPS in hitches) after export, and a racing level built from DAE imports:
|
|
61
72
|
|
|
62
73
|
- **Draw calls are the currency.** WebGPU / WebGL in the browser is CPU-bound long before it is GPU-bound: each draw costs JavaScript time (`bindForSubMesh`, `_draw`, render-pipeline lookup, uniform writes). Halving render resolution changed nothing; halving draws nearly doubled the frame rate. Every extra **pass** multiplies the draws of everything it renders.
|
|
63
74
|
- **Realtime shadows on point / spot lights are full scene passes.** Each shadowed spot light re-draws every caster in its frustum every frame (a point light: six times). The toolkit adds every shadow-casting mesh to every shadow-generating light. Six 5 m lantern spot lights = ~690 draws per frame — half the frame.
|
|
64
75
|
- **Runtime lights that the browser never animates are pure cost.** Unity sample scenes drive lights with MonoBehaviours (`LightFlicker`, `DynamicLightController` distance culling). Without a toolkit TypeScript port those scripts **do not run in the browser**: the lights neither flicker nor cull — they just cost. Baked, their light lives in the lightmaps (static objects) and light probes (moving objects) at zero runtime cost.
|
|
65
|
-
- **A depth pass appears when anything samples scene depth**: soft particles (`TOOLKIT.ShurikenParticles.SoftParticleDepth`, on by default) and Shader Graph Scene Depth nodes (`ShaderGraphPass.SceneDepth`) create a `DepthRenderer` that re-draws every visible opaque mesh each frame (20–25% of draws in
|
|
76
|
+
- **A depth pass appears when anything samples scene depth**: soft particles (`TOOLKIT.ShurikenParticles.SoftParticleDepth`, on by default) and Shader Graph Scene Depth nodes (`ShaderGraphPass.SceneDepth`) create a `DepthRenderer` that re-draws every visible opaque mesh each frame (20–25% of draws in one measured scene). Report it; merging reduces it; the runtime fix (take depth from the prepass renderer) belongs to the toolkit.
|
|
66
77
|
- **Zero-intensity post effects may still run.** URP's pipeline-default Volume Profile ships Motion Blur at intensity 0 (off in Unity); older toolkit runtimes still built a motion-blur pass for it.
|
|
67
|
-
- **Light binding is NOT range-aware.** BabylonJS's `Light.canAffectMesh` checks only include / exclude lists and layer masks, so every mesh binds up to its cap of runtime lights wherever they are (
|
|
68
|
-
- **Skinned meshes never instance.** Copies of a skinned mesh that animate separately each cost their own draw in every pass, and are skinned every frame. DAE and FBX imports routinely make rigid props one-bone skinned meshes: on
|
|
69
|
-
- **
|
|
78
|
+
- **Light binding is NOT range-aware.** BabylonJS's `Light.canAffectMesh` checks only include / exclude lists and layer masks, so every mesh binds up to its cap of runtime lights wherever they are (measured: 5 × 5 m props bound 8 lights, 7 of them out of range). Tighter mesh bounds never lower the bindings — only baking the lights does. The profiler's `lightAudit` clamps each light into the mesh's box, so scene-sized bounds (skinned or track-wide meshes) hide the waste: a low out-of-range share on such a scene is understated.
|
|
79
|
+
- **Skinned meshes never instance.** Copies of a skinned mesh that animate separately each cost their own draw in every pass, and are skinned every frame. DAE and FBX imports routinely make rigid props one-bone skinned meshes: on one measured level, 118 of 135 skinned renderers (coins, item-box parts, trees, track pieces) had one bone moving with the object and 129 of 202 main-pass draws came from 8 such repeated shapes. As plain meshes the exporter writes the copies as glTF instances (`ExportMeshInstances`, default on) — one draw per shape. Copies of a character that really deforms (a waving crowd) instance too once they are a VAT crowd: 13 skinned draws became one per material in view, and off-screen they cull.
|
|
80
|
+
- **Static means frozen.** The exporter freezes a static object's world matrix. A spinning item box or an animated bone that came from the source marked static stands still in the browser — Tune clears the flags (`unfreezeAnimated`).
|
|
81
|
+
- **Lightmapping a repeated prop costs its instancing — and so does light-probe lighting.** A lightmapped renderer never shares a cached mesh (each copy gets its own lightmap UVs), and the toolkit also loads every light-probe-lit node as its own mesh (`SceneManager.DeinstanceProbeLitNodes`, default on): copies instance only with Light Probes **Off**. Measured: trees, item boxes and coins went from 14 / 18 / 6 draws to 3 / 3 / 1 once their probes were off. Repeated props get neither (`instanceRepeatsFrom`); unique geometry gets the lightmaps.
|
|
70
82
|
- **Materials are cloned per renderer** for each reflection probe / lightmap combination and per LOD cross-fade level. Fewer renderers → fewer clones → fewer first-view shader compiles (hitches).
|
|
71
83
|
- **Lightmapped renderers never share a cached mesh** (reference §4): repeated lightmapped props are one draw each — merging is the only way to cut them. Probe-lit repeated props stay glTF instances.
|
|
84
|
+
- **Once repeats instance, the shadow maps are often the biggest pass.** A directional light with cascades draws each caster again in every cascade it touches (4 cascades → up to 4 draws per caster). Roads, ground, markings, water and grass planes and far backdrops cast shadows that land on nothing the camera sees: pruning 13 of them cut 46 shadow draws a frame on one level. An overhanging lip or a deck above other geometry does cast a visible shadow — every prune is proven by capture. Cascade count and shadow distance live on the project's pipeline asset, so they change every scene: propose them, never change them unasked.
|
|
85
|
+
- **Merging only pays when draws are scattered.** A level imported as one renderer per material has nothing to merge: one merge plan saved 0 draws and cost a cascade draw. Read `combine-plan.md`'s draws saved before merging, and use `--no-combine` when it is ~0.
|
|
86
|
+
- **Every camera with post-processing builds its own post chain.** Two enabled cameras with post doubled one level's post passes and cost 17% at a pinned view. The survey counts them; turn post off on a camera the player does not see.
|
|
87
|
+
- **Judge the look in the game, through its camera.** The export viewer's default camera renders without the scene's post-processing; a capture step that disabled the scene's main camera and was saved once shipped a level with no post at all. PoseView now never touches the scene's cameras, Verify compares every camera's state with the source, and the final check drives the game itself.
|
|
72
88
|
|
|
73
89
|
# The tune rules — and why each exists
|
|
74
90
|
|
|
@@ -76,22 +92,32 @@ Enforced by `scripts/BtOptimize.cs` (`Tune`). A **browser driver** is anything t
|
|
|
76
92
|
|
|
77
93
|
| Step | Rule | Why |
|
|
78
94
|
|---|---|---|
|
|
79
|
-
| Unskin rigid meshes | A SkinnedMeshRenderer with **one weighted bone** that moves with the object (no clip, Timeline, script, constraint or physics body moves the bone apart from the object), no blend shapes, no cloth, and no curve or reference aimed at the SkinnedMeshRenderer component becomes a MeshFilter + MeshRenderer on the same mesh and materials. Animators stay. When the bind pose offsets the mesh, a plain leaf object is moved onto it (the mesh stays shared — verified vertex by vertex); otherwise the offset is baked into one mesh asset shared by every copy with the same offset (`<Out>_UnskinnedMeshes/`). Three more rigid cases convert too: a **script host** (the only separate motion is a toolkit script on the renderer's own object) is baked as it is drawn now; a **renderer curve** (a clip animates the SkinnedMeshRenderer itself) converts as above, and each Animator playing it gets a copied controller whose copied clips aim those curves at MeshRenderer, same path and property (`<Out>_RetargetedClips/`); a **frozen pose** (several weighted bones, none moved apart from the object) is baked once, copies whose baked vertices match (4 decimals) sharing one mesh asset so they still instance. The swap keeps materials, shadow casting and receiving, occlusion, both probe usages, the probe anchor, motion vectors and rendering layers. Runs first, so the later steps see the new renderers | Babylon skins a skinned mesh every frame and can never instance its copies. A one-bone import of a rigid prop bought nothing —
|
|
95
|
+
| Unskin rigid meshes | A SkinnedMeshRenderer with **one weighted bone** that moves with the object (no clip, Timeline, script, constraint or physics body moves the bone apart from the object), no blend shapes, no cloth, and no curve or reference aimed at the SkinnedMeshRenderer component becomes a MeshFilter + MeshRenderer on the same mesh and materials. Animators stay. When the bind pose offsets the mesh, a plain leaf object is moved onto it (the mesh stays shared — verified vertex by vertex); otherwise the offset is baked into one mesh asset shared by every copy with the same offset (`<Out>_UnskinnedMeshes/`). Three more rigid cases convert too: a **script host** (the only separate motion is a toolkit script on the renderer's own object) is baked as it is drawn now; a **renderer curve** (a clip animates the SkinnedMeshRenderer itself) converts as above, and each Animator playing it gets a copied controller whose copied clips aim those curves at MeshRenderer, same path and property (`<Out>_RetargetedClips/`); a **frozen pose** (several weighted bones, none moved apart from the object) is baked once, copies whose baked vertices match (4 decimals) sharing one mesh asset so they still instance. The swap keeps materials, shadow casting and receiving, occlusion, both probe usages, the probe anchor, motion vectors and rendering layers. Runs first, so the later steps see the new renderers | Babylon skins a skinned mesh every frame and can never instance its copies. A one-bone import of a rigid prop bought nothing — on one level, coins, item boxes and trees were 112 draws at one view that became instances; its grass (a script host), guardrail arrows (a renderer curve) and flag ropes (frozen poses) had to be converted by hand before Tune learned them |
|
|
96
|
+
| Unfreeze what moves | Any object with static flags that a clip or Timeline moves (on it or an ancestor), or a Rigidbody, CharacterController or NavMeshAgent moves, loses every static flag; its renderer goes Receive GI Light Probes (`Static cleared (moves in the browser)` in `tune.md`). Narrower than a browser driver on purpose: an Animator on a level root that only animates one light does not unfreeze the level | The exporter freezes static world matrices: spinning item boxes and animated bones that arrived marked static stood still, and a lightmap baked in one place is wrong once the object moves |
|
|
80
97
|
| Repeated props instance | A mesh + materials drawn `instanceRepeatsFrom` (4) times or more is not lightmapped when marked static (still Contribute GI for bounce) and is skipped by the lightmap step. Last of the renderer steps, every copy that is still unlightmapped gets **Light Probe Usage Off** and Receive GI Light Probes (`Light probes off (instancing)` in `tune.md`); Reflection Probe Usage and Contribute GI stay. **Look trade-off:** the copies light from the scene's ambient instead of the nearest light probe — Phase 5's captures are the proof; `--exclude` a group whose probe lighting matters | The exporter gives every lightmapped copy its own mesh, and the toolkit gives every probe-lit node its own mesh (`SceneManager.DeinstanceProbeLitNodes`): only copies with probes off share one instanced draw |
|
|
81
|
-
| Keep the source's GI (`--keep-gi`) | Tune reads the source scene named in `working-copy.txt` (opened additively, closed unsaved) and collects the renderers with Contribute GI. Mark static then marks an object outside that set static without Contribute GI, the lightmap step leaves it probe-lit (`keep-gi: not a GI contributor in the source` in Left alone), and an unskinned object that carried the flag loses it. `tune.md` always shows `GI contributors: source N → copy N` | Every new contributor is an occluder in the re-bake: unskinned props pulled 62 objects into
|
|
98
|
+
| Keep the source's GI (`--keep-gi`) | Tune reads the source scene named in `working-copy.txt` (opened additively, closed unsaved) and collects the renderers with Contribute GI. Mark static then marks an object outside that set static without Contribute GI, the lightmap step leaves it probe-lit (`keep-gi: not a GI contributor in the source` in Left alone), and an unskinned object that carried the flag loses it. `tune.md` always shows `GI contributors: source N → copy N` | Every new contributor is an occluder in the re-bake: unskinned props pulled 62 objects into one level's bake and a light probe at its start fell 0.79 → 0.66. Off by default, because merging needs the newly lightmapped props |
|
|
82
99
|
| Lights → Baked | Active Realtime / Mixed **point and spot** lights with no browser driver and **no realtime shadows** become Baked. Directional lights (the sun) and `--keep-lights` stay | Practical fill lights cost per-pixel lighting every frame; baked, they cost nothing and still light moving objects through probes |
|
|
83
|
-
| Shadowed key lights stay runtime, shadows off | A point / spot light that casts realtime shadows (or that a browser driver animates) stays Realtime / Mixed and loses only its realtime shadows. `--bake-shadowed-lights` bakes them too | Each shadowed light re-draws the scene every frame (×6 for a point light) — the shadows are the cost, not the light. Keeping the light realtime keeps its exact look (direct light, specular highlights, light on moving objects) with no bake risk;
|
|
100
|
+
| Shadowed key lights stay runtime, shadows off | A point / spot light that casts realtime shadows (or that a browser driver animates) stays Realtime / Mixed and loses only its realtime shadows. `--bake-shadowed-lights` bakes them too | Each shadowed light re-draws the scene every frame (×6 for a point light) — the shadows are the cost, not the light. Keeping the light realtime keeps its exact look (direct light, specular highlights, light on moving objects) with no bake risk; in one measured scene, six such lights cost little once their shadow maps were gone. Use `--bake-shadowed-lights` when a scene has many of them and Phase 5 verifies the bake |
|
|
84
101
|
| Fixture shells stop casting shadows | When a light is baked, the shadow-casting renderers of its own fixture prefab whose bounds hold the light get Cast Shadows Off | A lantern shell around the bulb is clipped by the realtime shadow map's near plane, but the lightmapper traces from the bulb: a shadow-casting shell traps a baked light (lit floor under each lantern, dark walls) |
|
|
85
102
|
| Mark static | A non-static MeshRenderer with no browser driver, not pointed at by any script, not part of a particle system, and **a visible surface** (every material's shader has a lightmapper Meta pass) becomes static (Batching, Occluder, Occludee, Reflection Probe; **Contribute GI** only with lightmap UVs, no vertex animation and opaque) | The exporter freezes static world matrices, and static objects can be lightmapped and merged. The Meta-pass check exists because an invisible stencil mesh (`Custom/StencilOnly`) wrapping a room, once marked Contribute GI, became a solid box in the bake and the room went dark |
|
|
86
103
|
| Probe-lit → lightmapped | A static LOD0 / non-LOD visible surface that is probe-lit although it has UV2, no vertex animation and is opaque gets Contribute GI + Receive GI Lightmaps; its lower LOD levels with UV2 receive lightmaps (they borrow LOD0's region) | Lightmapped meshes can merge; a merged probe-lit mesh would get one probe sample for its whole area |
|
|
104
|
+
| VAT crowds | Animators whose skinned renderers draw the same meshes, `vatCrowdsFrom` (4) copies or more, that really deform: each gets the toolkit's `AnimatorControlRig` in `UseVertexAnimations` mode over its renderers; their materials are copied onto `Babylon/Custom/Vertex Animation Shader` (`<Out>_VatCrowd/<material>_VAT.mat`, one per source material, shared); each renderer gets world scale 1 and Light Probes Off. Each copy keeps its Animator, controller and clips. Skipped and reported: blend shapes, cloth, transparent materials, a renderer that is also a bone or parent, a renderer under a non-uniform scale, a material with no base colour texture property | Skinned copies never instance. The exporter bakes each controller's clips to vertex animation textures and the browser draws the copies as instances, one draw per material in view, each in its own Animator state. World scale 1 because the baker writes world-size positions and the browser applies the renderer node's scale again (a 0.386-scaled crowd drew at 0.386 of its size); a skinned mesh draws from its bones, so Unity looks the same. The Editor draws the VAT shader magenta under URP / HDRP: judge crowds in the browser |
|
|
87
105
|
| No-op post | Motion blur overrides with intensity 0 in the profiles the scene uses are deactivated | Off in Unity, but older toolkit runtimes still built the pass |
|
|
88
106
|
|
|
89
107
|
Kept as they are, by design: wind / vertex-animated vegetation (probe-lit by intent, and unmergeable), props without lightmap UVs (probe-lit), anything a script points at, stencil / depth / VFX utility meshes (no Meta pass), inactive objects.
|
|
90
108
|
|
|
91
109
|
Reported, never converted automatically — each with its next step in `survey.md` and `tune.md`:
|
|
92
110
|
- **Rigid, convert by hand:** a bone that a clip, Timeline, constraint or physics body moves apart from its object (parent a plain mesh under the bone), a component that references the SkinnedMeshRenderer, a clip Tune cannot retarget (a legacy Animation, an override controller) that animates the SkinnedMeshRenderer.
|
|
93
|
-
- **Deforming:** blend shapes and
|
|
94
|
-
- **
|
|
111
|
+
- **Deforming, not a crowd:** blend shapes, cloth, and a deforming character with fewer copies than `--vat-from`.
|
|
112
|
+
- **A crowd Tune could not convert** (the reasons in the VAT row): set up the `AnimatorControlRig` VAT mode by hand (`unity-authoring-recipes.md` §13), in the project script. A multi-colour crowd costs one draw per colour material; one draw for all needs the runtime per-skin texture array (`shader-materials.md`, web-game code) — report it as a follow-up.
|
|
113
|
+
|
|
114
|
+
# Shadow casters — pruned per object, proven by capture
|
|
115
|
+
|
|
116
|
+
Run in Phase 3 (skip with `--no-prune-casters`). `BtOptimize.PruneShadowCasters '{"paths":[…]}'` sets Cast Shadows Off on exactly the renderers listed (names, `Prefix*`, or hierarchy paths; Receive Shadows unchanged) and gives every renderer an earlier run pruned that the list no longer names its original mode back — the list is the whole truth, so edit it and re-run. `pruned-casters.json` records it; `Verify` checks it.
|
|
117
|
+
|
|
118
|
+
1. **Candidates:** `survey.md` → *Shadow casters — flat surfaces to prune* (unique casters whose surface is ≥ 90% horizontal — ground, roads, markings, water, grass planes, undersides), plus the browser's per-cascade dump (`before-pinned.json` → `pins[].shadowCasters`: every caster's draws per cascade) for far backdrops and anything else whose shadow falls outside the view. Write each with its draws and a keep / prune verdict and reason into `$REPORT/shadow-casters.md`.
|
|
119
|
+
2. **Keep** anything above other geometry: bridge decks, jumps, overhanging lips, roofs, props, buildings, trees, rails.
|
|
120
|
+
3. **Prove it:** after the bake, Phase 5's captures at every pinned pose must show every shadow the source shows. An entry whose removal shows (a lip loses its self-shadow) comes off the list; re-run the prune and re-bake. Cast Shadows also drives the lightmapper's occlusion, so the prune always comes before the bake.
|
|
95
121
|
|
|
96
122
|
**Every tune rule above came from a regression found by comparing Unity captures at the browser's poses** — run Phase 5 every time; a rule that changes what the lightmapper sees can change a whole room.
|
|
97
123
|
|
|
@@ -141,7 +167,8 @@ OUT=Assets/.../Scene_Optimized.unity # --out, or <source folder>/<SceneNa
|
|
|
141
167
|
NAME=$(basename "$OUT" .unity); SRC_NAME=$(basename "$SOURCE" .unity)
|
|
142
168
|
REPORT="$PROJ/.agents/optimize/$NAME"; QA="$PROJ/.agents/optimize/.qa-tools"
|
|
143
169
|
MERGE='{"cellSize":15,"maxSpread":3,"maxAtlasShare":0.45,"includeShaderGraphs":true,"combineLods":true,"exclude":[],"only":[],"extraShaders":[]}'
|
|
144
|
-
TUNE='{"unskinRigid":true,"instanceRepeatsFrom":4,"keepSourceGI":false,"bakeLights":true,"bakeShadowedLights":false,"keepLights":[],"pointSpotShadowsOff":true,"markStatic":true,"lightmapProbeLit":true,"fixZeroMotionBlur":true,"exclude":[]}'
|
|
170
|
+
TUNE='{"unskinRigid":true,"unfreezeAnimated":true,"instanceRepeatsFrom":4,"vatCrowdsFrom":4,"keepSourceGI":false,"bakeLights":true,"bakeShadowedLights":false,"keepLights":[],"pointSpotShadowsOff":true,"markStatic":true,"lightmapProbeLit":true,"fixZeroMotionBlur":true,"exclude":[]}'
|
|
171
|
+
WAIT=https://raw.githubusercontent.com/babylontoolkit/agent/main/references/scripts/wait.mjs # the installed copy; run in place
|
|
145
172
|
|
|
146
173
|
bt_run() { # bt_run <File: BtOptimize|BtCombine> <Method> '<json args array>'
|
|
147
174
|
unity command run_script --file "AgentScripts/bt-optimize/$1.cs" --entry "$1.$2" --args "$3" \
|
|
@@ -151,7 +178,7 @@ bt_run() { # bt_run <File: BtOptimize|BtCombine> <Method> '<json args array>'
|
|
|
151
178
|
arg() { python3 -c "import json,sys; print(json.dumps([sys.argv[1]]))" "$1"; } # wraps one JSON options string as a run_script args array
|
|
152
179
|
```
|
|
153
180
|
|
|
154
|
-
Map flags into `MERGE` / `TUNE` (`--no-tune:unskin` → `"unskinRigid":false`, `--instance-from:N` → `"instanceRepeatsFrom":N`, `--keep-gi` → `"keepSourceGI":true`, `--exclude:A,B*` → both `"exclude":["A","B*"]`, `--keep-lights:` → `keepLights`, `--no-shadergraphs` → `"includeShaderGraphs":false`, `--no-lods` → `"combineLods":false`, `--no-tune:lights` → `"bakeLights":false,"pointSpotShadowsOff":false`, `--no-tune:static` → `"markStatic":false`, `--no-tune:lightmaps` → `"lightmapProbeLit":false`, `--no-tune:post` → `"fixZeroMotionBlur":false`, `--bake-shadowed-lights` → `"bakeShadowedLights":true`).
|
|
181
|
+
Map flags into `MERGE` / `TUNE` (`--no-tune:unskin` → `"unskinRigid":false`, `--no-tune:unfreeze` → `"unfreezeAnimated":false`, `--no-tune:vat` → `"vatCrowdsFrom":0`, `--vat-from:N` → `"vatCrowdsFrom":N`, `--instance-from:N` → `"instanceRepeatsFrom":N`, `--keep-gi` → `"keepSourceGI":true`, `--exclude:A,B*` → both `"exclude":["A","B*"]`, `--keep-lights:` → `keepLights`, `--no-shadergraphs` → `"includeShaderGraphs":false`, `--no-lods` → `"combineLods":false`, `--no-tune:lights` → `"bakeLights":false,"pointSpotShadowsOff":false`, `--no-tune:static` → `"markStatic":false`, `--no-tune:lightmaps` → `"lightmapProbeLit":false`, `--no-tune:post` → `"fixZeroMotionBlur":false`, `--bake-shadowed-lights` → `"bakeShadowedLights":true`).
|
|
155
182
|
|
|
156
183
|
## Phase 0 — Preflight
|
|
157
184
|
|
|
@@ -174,13 +201,15 @@ The exported source scene must be current: find `<exportRoot>/scenes/<source>.gl
|
|
|
174
201
|
mkdir -p "$PROJ/.agents/optimize/$SRC_NAME/profile"
|
|
175
202
|
node "$QA/profile-browser.mjs" --scene <source>.gltf --times 10,20,30,45,60,75,90 --window 4 \
|
|
176
203
|
--out "$PROJ/.agents/optimize/$SRC_NAME/profile/before-timeline.json"
|
|
177
|
-
node "$QA/profile-browser.mjs" --scene <source>.gltf --pin 40,60,75 --toggles none --window 5 --settle 8 --cpuprofile true \
|
|
204
|
+
node "$QA/profile-browser.mjs" --scene <source>.gltf --pin 40,60,75 --toggles none --window 5 --settle 8 --cpuprofile true --casters true \
|
|
178
205
|
--shots "$PROJ/.agents/optimize/$SRC_NAME/profile/shots" --out "$PROJ/.agents/optimize/$SRC_NAME/profile/before-pinned.json"
|
|
179
206
|
```
|
|
180
207
|
|
|
208
|
+
When an earlier run (or a plan's `tests/poses-pinned.json`) already pinned this scene, replay those poses with `--poses <file>` instead of `--pin`, so every run of the scene is measured from the same views.
|
|
209
|
+
|
|
181
210
|
`--pin` waits the given seconds after the scene is ready, then detaches the camera from its rig and **records its exact pose** (position, rotation and lens — field of view and clip planes, because Timeline / Cinemachine tracks animate the lens too; the lens fields are made read-only while pinned, because a lens track keeps writing them and TAA builds its projection from them before any observer runs). Every later run replays those poses with `--poses before-pinned.json`, so before and after are measured from the same views — pinning by time alone lands on different views, because a lighter scene loads sooner and its tour runs ahead.
|
|
182
211
|
|
|
183
|
-
Read the JSON: `census` (engine, render size, meshes, materials, lights, shadow generators and their casters, post passes, prepass), `samples` (FPS, p95 / worst frame, draws, active meshes), and per pin `baseline.passes` / `baseline.byTarget` (draws per frame in shadow maps, `DepthRenderer`, main pass, post), **`drawOwners`** (main-pass draws by owning object, measured per render call in one recorded frame — `mainDraws` equals that frame's main-phase counter `frameMainDraws` by construction and should match `baseline.passes.main`; draws no object owns appear as an `(unowned)` owner whose `sources` name the class that drew them — with each owner's skinned / instanced / lightmapped meshes and shadow casters, plus `repeats`: every shape drawn more than once and what stops its copies sharing one draw), `lightAudit`, and `cpu.top`. **Pin inside the scene's own motion** (a flythrough, a spawn view after compile): the first seconds after load are still compiling shaders and are not comparable. To confirm a suspected cost, re-run with `--toggles shadows,lights,motionblur,taa,bloom,dpr` (each switched off alone and settled on `whenReadyAsync` — never compare a window that follows a toggle without that wait: thousands of materials recompile).
|
|
212
|
+
Read the JSON: `census` (engine, render size, meshes, materials, lights, shadow generators and their casters, post passes, prepass), `samples` (FPS, p95 / worst frame, draws, active meshes), and per pin `baseline.passes` / `baseline.byTarget` (draws per frame in shadow maps, `DepthRenderer`, main pass, post), **`drawOwners`** (main-pass draws by owning object, measured per render call in one recorded frame — `mainDraws` equals that frame's main-phase counter `frameMainDraws` by construction and should match `baseline.passes.main`; draws no object owns appear as an `(unowned)` owner whose `sources` name the class that drew them — with each owner's skinned / instanced / lightmapped meshes and shadow casters, plus `repeats`: every shape drawn more than once and what stops its copies sharing one draw), **`shadowCasters`** (`--casters true`: every shadow generator's casters with their draws per cascade), `lightAudit`, and `cpu.top`. **Pin inside the scene's own motion** (a flythrough, a spawn view after compile): the first seconds after load are still compiling shaders and are not comparable. To confirm a suspected cost, re-run with `--toggles shadows,lights,motionblur,taa,bloom,dpr` (each switched off alone and settled on `whenReadyAsync` — never compare a window that follows a toggle without that wait: thousands of materials recompile).
|
|
184
213
|
|
|
185
214
|
## Phase 2 — Survey and plan
|
|
186
215
|
|
|
@@ -191,17 +220,19 @@ bt_run BtOptimize Tune "$(arg "$(echo "$TUNE" | sed 's/}$/,"dryRun":true}/')")"
|
|
|
191
220
|
bt_run BtCombine Analyze "$(arg "$MERGE")" # combine-plan.md (on the source: merges before tune unlocks)
|
|
192
221
|
```
|
|
193
222
|
|
|
194
|
-
**Account for every draw before planning — ENFORCED.** From `before-pinned.json` → `pins[].drawOwners`, write the main-pass draws by owner at each pin into the plan (`node "$QA/compare-profiles.mjs"` prints it), then put each owner group of 5% or more beside its Unity cause and its fix: `survey.md` → *Skinned meshes* (every skinned renderer's verdict — rigid, frozen pose, deforms — with the evidence), *Repeated meshes* (copies, draws now, draws if instanced, what stops sharing), *Renderers*, *Lights
|
|
223
|
+
**Account for every draw before planning — ENFORCED.** From `before-pinned.json` → `pins[].drawOwners`, write the main-pass draws by owner at each pin into the plan (`node "$QA/compare-profiles.mjs"` prints it), then put each owner group of 5% or more beside its Unity cause and its fix: `survey.md` → *Skinned meshes* (every skinned renderer's verdict — rigid, frozen pose, deforms — with the evidence), *Repeated meshes* (copies, draws now, draws if instanced, what stops sharing), *Shadow casters* (flat prune candidates), *Renderers*, *Lights*, *Post-processing and cameras* (cameras building their own post chain). Do the same for the shadow maps when they are a large share of the frame: `pins[].shadowCasters` names every caster and its draws per cascade. A group with no fix gets a measured reason. Do not start Phase 3 with a large group unexplained. Read `combine-plan.md`'s draws saved: when merging saves ~0 draws (a level already drawn as one renderer per material), run with `--no-combine` and say why.
|
|
195
224
|
|
|
196
|
-
Tell the user in a few lines: the measured frame (FPS, draws per pass, **the draw owners and the top repeated shapes**, the top costs), and the plan with numbers (rigid skinned meshes to convert, repeated props that will instance, lights to bake, props to mark static, renderers to lightmap, merges). Recommend `--keep-gi` whenever the user wants the current lighting kept or the run is `--no-combine` (with no merge, newly lightmapped props buy no draws, only a different bake). `--analyze` stops here. Otherwise continue — do not wait for approval; the source is safe.
|
|
225
|
+
Tell the user in a few lines: the measured frame (FPS, draws per pass, **the draw owners and the top repeated shapes**, the top costs), and the plan with numbers (rigid skinned meshes to convert, static movers to unfreeze, repeated props that will instance, crowds that become VAT, lights to bake, shadow casters to prune, props to mark static, renderers to lightmap, merges). Recommend `--keep-gi` whenever the user wants the current lighting kept or the run is `--no-combine` (with no merge, newly lightmapped props buy no draws, only a different bake). `--analyze` stops here. Otherwise continue — do not wait for approval; the source is safe.
|
|
197
226
|
|
|
198
227
|
## Phase 3 — Working copy, tune, merge
|
|
199
228
|
|
|
200
229
|
```bash
|
|
201
230
|
bt_run BtCombine PrepareCopy "[\"$SOURCE\",\"$OUT\",<true if --reset else false>]"
|
|
202
231
|
bt_run BtOptimize Tune "$(arg "$TUNE")" # skip with --combine-only
|
|
232
|
+
bt_run BtOptimize PruneShadowCasters "$(arg '{"paths":["<prune list from shadow-casters.md>"]}')" # skip with --no-prune-casters / --combine-only
|
|
203
233
|
bt_run BtCombine Analyze "$(arg "$MERGE")" # skip with --no-combine; plan after the unlocks
|
|
204
234
|
bt_run BtCombine Apply "$(arg "$MERGE")" # skip with --no-combine
|
|
235
|
+
# a project script's entry points (planning.md O11), in order, when the run needs one
|
|
205
236
|
```
|
|
206
237
|
|
|
207
238
|
Read the Apply output: every group's `verts a -> b` must be equal. A `WARNING … re-unwrapped` on a few small groups means a lightmapped source had no usable lightmap UVs (no UV2 and UV0 outside 0..1) and was unwrapped on its own — report the count; many or large ones mean the toolkit build lacks packing — stop and report. If Apply refuses ("already combined"), continue from Phase 4 with the existing result or rerun with `--reset`.
|
|
@@ -211,31 +242,23 @@ Read the Apply output: every group's `verts a -> b` must be equal. A `WARNING
|
|
|
211
242
|
Light-mode changes, GI-flag changes and merged lightmap UVs all need one bake; a copied scene still points at the source's LightingData.
|
|
212
243
|
|
|
213
244
|
```bash
|
|
214
|
-
bake() {
|
|
245
|
+
bake() { # never trust lighting_bake_status alone: it can say "completed" before the bake starts
|
|
246
|
+
local started; started=$(date +%s)
|
|
215
247
|
unity command bake_lighting --confirm true --project-path "$PROJ"
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
s=$(unity command lighting_bake_status --project-path "$PROJ" --result-only 2>/dev/null)
|
|
219
|
-
case "$s" in
|
|
220
|
-
*completed*) break;;
|
|
221
|
-
*failed*) echo "bake failed: $s"; return 1;;
|
|
222
|
-
*baking*|*running*|*in_progress*) seen=1;;
|
|
223
|
-
*idle*) [ -n "$seen" ] && { echo "bake stopped without completing"; return 1; };;
|
|
224
|
-
esac
|
|
225
|
-
[ $SECONDS -ge $deadline ] && { echo "bake timed out"; return 1; }
|
|
226
|
-
sleep 15
|
|
227
|
-
done
|
|
248
|
+
node "$WAIT" cmd "unity command run_script --file AgentScripts/bt-optimize/BtOptimize.cs --entry BtOptimize.BakeState --args '[\"$started\"]' --project-path '$PROJ' --format json" \
|
|
249
|
+
--match '"result": *"done"' --fail '"result": *"stopped"' --interval 15 --timeout 5400 || return 1
|
|
228
250
|
unity command save_all --project-path "$PROJ" # the bake assigns new LightingData; exports refuse a dirty scene
|
|
229
251
|
}
|
|
230
252
|
bake
|
|
231
|
-
bt_run BtCombine CorrectDensity '[]' # merged meshes get ~84-89% of their sources' texels; raise Scale In Lightmap
|
|
253
|
+
bt_run BtCombine CorrectDensity '[]' # after a merge: merged meshes get ~84-89% of their sources' texels; raise Scale In Lightmap
|
|
232
254
|
# corrected=N with N > 0 → bake once more
|
|
233
|
-
bt_run BtCombine Verify '[]' # must end with problems=0
|
|
255
|
+
bt_run BtCombine Verify '[]' # after a merge: must end with problems=0
|
|
256
|
+
bt_run BtOptimize Verify "$(arg "$TUNE")" # always: must end with problems=0 (verify.md lists each problem)
|
|
234
257
|
```
|
|
235
258
|
|
|
236
259
|
## Phase 5 — Unity side-by-side (browser poses, then LOD0 **and** LOD1)
|
|
237
260
|
|
|
238
|
-
**First, the browser's pinned poses in Unity**, source and working copy. `PoseView` puts a capture camera named `BtOptimizePoseCamera` at a pose recorded by the profiler (position, rotation, vertical FOV; toolkit scenes keep Unity's coordinates), copying the main camera's URP data so post-processing matches. It never
|
|
261
|
+
**First, the browser's pinned poses in Unity**, source and working copy. `PoseView` puts a capture camera named `BtOptimizePoseCamera` at a pose recorded by the profiler (position, rotation, vertical FOV; toolkit scenes keep Unity's coordinates), copying the main camera's URP data so post-processing matches. It renders above the scene's cameras by depth and never touches them, and it is never saved (DontSaveInEditor) — but it lives in the open scene until the scene is reopened, so **reopen the scene before exporting** (the last line below does). VAT crowd members draw magenta in URP / HDRP Unity captures — compare them in the browser. Comparing these with the browser shots of the same poses tells you which side of the export a difference is on:
|
|
239
262
|
|
|
240
263
|
```bash
|
|
241
264
|
python3 -c "import json; [print(p['atSeconds'],*p['pinned']['position'],*p['pinned']['rotation'],p['pinned']['fov']) for p in json.load(open('$PROJ/.agents/optimize/$SRC_NAME/profile/before-pinned.json'))['pins']]" > /tmp/poses.txt
|
|
@@ -289,6 +312,8 @@ unity command run_script --file AgentScripts/bt-optimize/BtOptimize.cs --entry B
|
|
|
289
312
|
Recommend `--resolution:css` only when the profile is GPU-bound (FPS rises with `--toggles dpr`); on a CPU-bound scene it costs sharpness and buys nothing.
|
|
290
313
|
|
|
291
314
|
```bash
|
|
315
|
+
unity command open_scene --path "$OUT" --project-path "$PROJ" # drops any pose / QA camera
|
|
316
|
+
bt_run BtOptimize Verify "$(arg "$TUNE")" # problems=0 before every export
|
|
292
317
|
unity command bt_export_level --scene "$OUT" --project-path "$PROJ" --timeout 3600 # record the duration
|
|
293
318
|
unity command bt_devserver_start --project-path "$PROJ"
|
|
294
319
|
node "$QA/gltf-stats.mjs" <source.gltf> <optimized.gltf>
|
|
@@ -300,16 +325,18 @@ node "$QA/compare-profiles.mjs" --label Original,Optimized "$PROJ/.agents/optimi
|
|
|
300
325
|
node "$QA/compare-browser.mjs" --scenes <source>.gltf,<optimized>.gltf --times 20,25,30,40,50,60 --out "$REPORT/captures"
|
|
301
326
|
```
|
|
302
327
|
|
|
303
|
-
`compare-profiles` prints the report tables. **Before trusting a pinned comparison, look at the paired `--shots` images: the same pose must show the same view** (a lens or camera the pin did not hold shows up there first). The pinned views are the same poses in both runs; compare FPS, p50 / p95 frame time, draws per pass and the CPU top list. In `compare-browser`'s `sheet.png`, pair frames by **view, not timestamp** — a lighter scene finishes loading sooner and its flythrough runs ahead (5–10 s
|
|
328
|
+
`compare-profiles` prints the report tables. **Before trusting a pinned comparison, look at the paired `--shots` images: the same pose must show the same view** (a lens or camera the pin did not hold shows up there first). The pinned views are the same poses in both runs; compare FPS, p50 / p95 frame time, draws per pass and the CPU top list. In `compare-browser`'s `sheet.png`, pair frames by **view, not timestamp** — a lighter scene finishes loading sooner and its flythrough runs ahead (5–10 s in one measured scene). Both scenes must be free of console errors.
|
|
329
|
+
|
|
330
|
+
**In the game.** When a web game loads this scene (search its code for the source's lower-cased export name), point it at the optimized export — the one-line scene URL / catalog change — and play to the pinned views through the game's own camera: post-processing on, animated props and crowds animating, 0 console errors. The export viewer's default camera has no post-processing, so a lost post chain only shows here. Never copy exported files into the web project (reference: *Scenes Are Served, Never Copied*).
|
|
304
331
|
|
|
305
332
|
## Phase 7 — Regression loop (at most 3 rounds)
|
|
306
333
|
|
|
307
334
|
**Find the side first.** Unity original vs Unity working copy at the same pose: different → the scene changes (tune or merge) did it; same → the export / runtime did it (compare the census and console).
|
|
308
335
|
|
|
309
|
-
**Then bisect, never guess.** Two plausible stories about
|
|
336
|
+
**Then bisect, never guess.** Two plausible stories about one scene's dark room were both wrong; one bake per variant found the truth in about 30 minutes:
|
|
310
337
|
1. Control copies: `PrepareCopy` to `<Scene>_TuneOnly.unity` (reset each time), run `Tune` with steps switched off (`{"bakeLights":false,"pointSpotShadowsOff":false}` = static/lightmap steps only; `{"markStatic":false,"lightmapProbeLit":false}` = light steps only; then single steps), bake once, `PoseView` + capture the bad pose.
|
|
311
338
|
2. The step that reproduces it → diff renderer state near the spot between source and copy (static flags, Contribute GI, receive GI, shadow casting) to name the object, fix the **rule** in `BtOptimize.cs`, `RemoveCopy` the control, rerun with `--reset`.
|
|
312
|
-
3. Unity-side runtime experiments (disabling lights in the Editor) are unreliable when the scene has `[ExecuteAlways]` scripts —
|
|
339
|
+
3. Unity-side runtime experiments (disabling lights in the Editor) are unreliable when the scene has `[ExecuteAlways]` scripts — one scene's light controller script re-enabled every light each frame. Change only what such scripts do not touch, or bake a control copy.
|
|
313
340
|
|
|
314
341
|
If a region looks different (darker, flatter, wrong reflections, LOD popping) or a pinned view got slower:
|
|
315
342
|
1. Identify the cause: a merge (`combine-manifest.json` → `combinedPaths`, `sources`, probes), a baked light (`tune.md`), a lightmap switch.
|
|
@@ -318,15 +345,17 @@ If a region looks different (darker, flatter, wrong reflections, LOD popping) or
|
|
|
318
345
|
|
|
319
346
|
## Phase 8 — Report
|
|
320
347
|
|
|
321
|
-
Reply in plain language with images, and write `$REPORT/report.md
|
|
348
|
+
Reply in plain language with images, and write `$REPORT/report.md`. Both open with **Export this scene** — the first thing the user reads:
|
|
322
349
|
|
|
350
|
+
- **Export this scene:** the working copy's path and its export file (`scenes/<out, lower-cased>.gltf`), whether the game now loads it, and a short table of what sits beside it: the source (untouched — the baseline; keep it to re-run or compare), `<Out>/` (its baked lighting), `<Out>_UnskinnedMeshes/`, `<Out>_RetargetedClips/`, `<Out>_VatCrowd/`, `<Out>_CombinedMeshes/` (each only when made) — "used by the optimized scene; do not delete". Name any other copies of the scene in the folder (older backups, control copies) as not part of the result, and offer — never do unasked — to tidy them once the user is happy.
|
|
323
351
|
- **Result:** FPS and frame time (p50 / p95 / worst) before → after at each pinned view and over the timeline; draws per frame by pass; meshes, primitives, materials, vertices and export size (`gltf-stats`); export time.
|
|
324
|
-
- **What changed and why:** lights baked (count, which), shadows removed, props marked static, renderers lightmapped, post fixes, merges (static groups, LOD clusters, the biggest by name).
|
|
352
|
+
- **What changed and why:** skinned meshes unskinned, static movers unfrozen, repeats instanced, VAT crowds, lights baked (count, which), shadows removed, shadow casters pruned (with the capture proof), props marked static, renderers lightmapped, post fixes, merges (static groups, LOD clusters, the biggest by name).
|
|
325
353
|
- **Draws by owner, before → after, at each pin** (`compare-profiles` prints it): every group of 5% or more of the main-pass draws, with what changed it or the measured reason it could not change. The repeated shapes that still cost one draw per copy, and why.
|
|
326
354
|
- **What stayed and why:** top kept reasons with counts, and what the user could change (UV2 on props, scripts that point at objects, vegetation by design, skinned meshes to convert by hand, repeated deforming crowds for the VAT mode).
|
|
327
355
|
- **Toolkit findings:** costs the scene cannot fix (for example a `DepthRenderer` pass owned by soft particles or a Scene Depth node), with the runtime fix to ask for.
|
|
328
|
-
- **Checks:** Verify
|
|
329
|
-
- **
|
|
356
|
+
- **Checks:** `BtOptimize.Verify` and `BtCombine.Verify` results, Unity captures, browser frames, the in-game look, console errors; anything skipped or unverified, stated as such.
|
|
357
|
+
- **Redo after `--reset`:** the exact sequence — Tune JSON, the prune list, any project script's entry points in order, bake, Verify, export — so the result can be rebuilt from the source at any time.
|
|
358
|
+
- **How to undo:** `--reset`, or delete the working copy, `<Out>_CombinedMeshes/`, `<Out>_UnskinnedMeshes/`, `<Out>_RetargetedClips/`, `<Out>_VatCrowd/`, `<Out>/` (baked lighting) and `.agents/optimize/<Out>/`, and point the game back at the source's export; re-tick any Volume Profile override listed in `tune.md`.
|
|
330
359
|
|
|
331
360
|
---
|
|
332
361
|
|
|
@@ -338,9 +367,10 @@ Reply in plain language with images, and write `$REPORT/report.md`:
|
|
|
338
367
|
| `<out scene folder>/<Out>_CombinedMeshes/*.asset` | merged meshes |
|
|
339
368
|
| `<out scene folder>/<Out>_UnskinnedMeshes/*.asset` | plain meshes baked from skinned meshes: rigid ones whose bind pose was offset and whose object could not be moved, script hosts, and frozen poses (one asset per distinct pose) |
|
|
340
369
|
| `<out scene folder>/<Out>_RetargetedClips/` | copied clips (`<clip>_MeshRenderer.anim`) and controllers (`<controller>_MeshRenderer.controller`) whose SkinnedMeshRenderer curves now target the MeshRenderer that replaced it |
|
|
370
|
+
| `<out scene folder>/<Out>_VatCrowd/` | the VAT crowds' material copies (`<material>_VAT.mat`) on the toolkit's vertex-animation shader |
|
|
341
371
|
| `<out scene folder>/<Out>/` | the copy's baked lighting |
|
|
342
372
|
| `.agents/optimize/<Source>/` | survey, tune plan, merge plan and "before" profiles of the source |
|
|
343
|
-
| `.agents/optimize/<Out>/` | `working-copy.txt`, `tune.md/json`, `combine-plan.*`, `combine-manifest.json`, `combine-verify.md`, `profile/`, `captures/`, `report.md` |
|
|
373
|
+
| `.agents/optimize/<Out>/` | `working-copy.txt`, `tune.md/json`, `pruned-casters.json`, `shadow-casters.md`, `combine-plan.*`, `combine-manifest.json`, `combine-verify.md`, `verify.md/json`, `profile/`, `captures/`, `report.md` |
|
|
344
374
|
| `AgentScripts/bt-optimize/*.cs`, `.agents/optimize/.qa-tools/` | the engines and QA tools (outside `Assets/`, no recompiles) |
|
|
345
375
|
|
|
346
376
|
# Troubleshooting
|
|
@@ -355,3 +385,9 @@ Reply in plain language with images, and write `$REPORT/report.md`:
|
|
|
355
385
|
| Browser: connection refused | The dev server stops on every domain reload — `bt_devserver_start` again |
|
|
356
386
|
| Profile numbers jump between windows | The view was still compiling (pin later) or a toggle was measured before `whenReadyAsync` settled |
|
|
357
387
|
| Faster, but a merged area is darker in the browser only | Probe or light choice: lower `--spread` / `--cell`, or `--exclude` that container; then the control test |
|
|
388
|
+
| A spinning or animated prop stands still in the browser | It is static: `Verify` lists it under "static but moves" — Tune's `unfreezeAnimated` clears it; re-export |
|
|
389
|
+
| VAT crowd draws tiny (or huge) in the browser | Its renderers are not at world scale 1 (`Verify` names them): re-run Tune, or set the scale by hand |
|
|
390
|
+
| VAT crowd is magenta in Unity captures | Expected: the toolkit's VAT shader has no URP / HDRP pass in the Editor — judge it in the browser |
|
|
391
|
+
| The game lost its post-processing / looks flat after the run | A camera was saved disabled: `Verify` compares every camera with the source; re-enable it, reopen, re-export |
|
|
392
|
+
| A pruned caster's shadow is missing in a capture | Take it off the prune list, re-run `PruneShadowCasters` (it restores the original mode), re-bake |
|
|
393
|
+
| `BakeState` keeps returning `stopped` | The bake never started or failed: `console --level error`, then `bake_lighting` again |
|
|
@@ -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
|
{
|