@babylonjs-toolkit/agent 1.2.9 → 1.2.11
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 +1 -1
- package/package.json +1 -1
- package/skills/bt-optimize/SKILL.md +29 -10
- package/skills/bt-optimize/scripts/BtCombine.cs +25 -1
- package/skills/bt-optimize/scripts/BtOptimize.cs +1102 -8
- package/skills/bt-optimize/scripts/qa/compare-profiles.mjs +95 -0
- package/skills/bt-optimize/scripts/qa/profile-browser.mjs +386 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Babylon Toolkit Desktop Agent (1.2.
|
|
1
|
+
# Babylon Toolkit Desktop Agent (1.2.11)
|
|
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
|
|
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), surveys the Unity scene for the causes, then fixes them on a copy of the scene: 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 browser. Every decision is written down with its reason. 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/Garden/GardenScene.unity`, `/bt-optimize --combine-only`)."
|
|
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 browser. Every decision is written down with its reason. 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/Garden/GardenScene.unity`, `/bt-optimize --combine-only`)."
|
|
4
4
|
allowed-tools: Read, Grep, Glob, Edit, Write, Bash, WebFetch(domain:raw.githubusercontent.com)
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ Use the user's message after the skill name as the `arguments`.
|
|
|
14
14
|
|
|
15
15
|
```
|
|
16
16
|
/bt-optimize [<scene asset path>] [--out:<asset path>] [--analyze] [--reset]
|
|
17
|
-
[--no-combine | --combine-only] [--no-tune:lights,static,lightmaps,post]
|
|
17
|
+
[--no-combine | --combine-only] [--no-tune:unskin,lights,static,lightmaps,post] [--instance-from:4] [--keep-gi]
|
|
18
18
|
[--keep-lights:Name1,Prefix*] [--bake-shadowed-lights] [--exclude:Name1,Prefix*] [--only:Path/A,Path/B]
|
|
19
19
|
[--cell:15] [--spread:3] [--atlas-share:0.45] [--no-shadergraphs] [--no-lods] [--shaders:Name1,Name2]
|
|
20
20
|
[--textures:ktx2] [--resolution:css] [--no-bake] [--no-export] [--no-browser] [--pins:40,60] [--times:10,20,30,45,60,90]
|
|
@@ -26,7 +26,9 @@ Use the user's message after the skill name as the `arguments`.
|
|
|
26
26
|
- **`--reset`** — start again from the source (re-copies it over the working copy, deletes the previous merged meshes and reports).
|
|
27
27
|
- **`--no-combine`** — every optimization except merging meshes.
|
|
28
28
|
- **`--combine-only`** — only merge static meshes and LOD groups (no light, static, lightmap or post changes).
|
|
29
|
-
- **`--no-tune:`** — skip individual tune steps: `lights` (bake practical lights / drop point-spot shadows), `static` (mark non-moving props static), `lightmaps` (probe-lit → lightmapped), `post` (no-op post effects).
|
|
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).
|
|
31
|
+
- **`--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).
|
|
30
32
|
- **`--keep-lights:`** — light names (or prefixes ending in `*`) that stay realtime / Mixed.
|
|
31
33
|
- **`--bake-shadowed-lights`** — also bake point / spot lights that cast realtime shadows (default: they stay realtime with their shadows turned off).
|
|
32
34
|
- **`--exclude:`** — object names (or prefixes) whose subtrees are never tuned or merged. **`--only:`** limits merging to these hierarchy paths.
|
|
@@ -44,6 +46,8 @@ Use the user's message after the skill name as the `arguments`.
|
|
|
44
46
|
3. **Every decision has a written reason.** `.agents/optimize/<Out>/` holds the survey, the tune plan and log, the merge plan and manifest, verify results, profiles, captures and the report.
|
|
45
47
|
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).
|
|
46
48
|
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
|
+
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.
|
|
47
51
|
|
|
48
52
|
# Talk to the user while you work
|
|
49
53
|
|
|
@@ -60,7 +64,9 @@ Learned on a 2,400-renderer URP garden that ran 8–26 FPS (1–5 FPS in hitches
|
|
|
60
64
|
- **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.
|
|
61
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 the garden). Report it; merging reduces it; the runtime fix (take depth from the prepass renderer) belongs to the toolkit.
|
|
62
66
|
- **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.
|
|
63
|
-
- **Light binding is range-aware
|
|
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 (verified on Mario Circuit: 5 × 5 m item boxes bound 8 lights, 7 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.
|
|
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 Mario Circuit, 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.
|
|
69
|
+
- **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**. On Mario Circuit, 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.
|
|
64
70
|
- **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).
|
|
65
71
|
- **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.
|
|
66
72
|
|
|
@@ -70,6 +76,9 @@ Enforced by `scripts/BtOptimize.cs` (`Tune`). A **browser driver** is anything t
|
|
|
70
76
|
|
|
71
77
|
| Step | Rule | Why |
|
|
72
78
|
|---|---|---|
|
|
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 — Mario Circuit's coins, item boxes and trees were 112 draws at the start gate that become 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 |
|
|
80
|
+
| 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 Mario Circuit's bake and its start-gate light probe fell 0.79 → 0.66. Off by default, because merging needs the newly lightmapped props |
|
|
73
82
|
| 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 |
|
|
74
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; on Garden, 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 |
|
|
75
84
|
| 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) |
|
|
@@ -79,6 +88,11 @@ Enforced by `scripts/BtOptimize.cs` (`Tune`). A **browser driver** is anything t
|
|
|
79
88
|
|
|
80
89
|
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.
|
|
81
90
|
|
|
91
|
+
Reported, never converted automatically — each with its next step in `survey.md` and `tune.md`:
|
|
92
|
+
- **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 cloth.
|
|
94
|
+
- **Really deforming and repeated** (a waving crowd): the toolkit's `AnimatorControlRig` VAT (crowd) mode draws the copies instanced (`unity-authoring-recipes.md` §13). Name the group, its copies and its draws in the report.
|
|
95
|
+
|
|
82
96
|
**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.
|
|
83
97
|
|
|
84
98
|
# The merge rules — and why each exists
|
|
@@ -127,7 +141,7 @@ OUT=Assets/.../Scene_Optimized.unity # --out, or <source folder>/<SceneNa
|
|
|
127
141
|
NAME=$(basename "$OUT" .unity); SRC_NAME=$(basename "$SOURCE" .unity)
|
|
128
142
|
REPORT="$PROJ/.agents/optimize/$NAME"; QA="$PROJ/.agents/optimize/.qa-tools"
|
|
129
143
|
MERGE='{"cellSize":15,"maxSpread":3,"maxAtlasShare":0.45,"includeShaderGraphs":true,"combineLods":true,"exclude":[],"only":[],"extraShaders":[]}'
|
|
130
|
-
TUNE='{"bakeLights":true,"bakeShadowedLights":false,"keepLights":[],"pointSpotShadowsOff":true,"markStatic":true,"lightmapProbeLit":true,"fixZeroMotionBlur":true,"exclude":[]}'
|
|
144
|
+
TUNE='{"unskinRigid":true,"instanceRepeatsFrom":4,"keepSourceGI":false,"bakeLights":true,"bakeShadowedLights":false,"keepLights":[],"pointSpotShadowsOff":true,"markStatic":true,"lightmapProbeLit":true,"fixZeroMotionBlur":true,"exclude":[]}'
|
|
131
145
|
|
|
132
146
|
bt_run() { # bt_run <File: BtOptimize|BtCombine> <Method> '<json args array>'
|
|
133
147
|
unity command run_script --file "AgentScripts/bt-optimize/$1.cs" --entry "$1.$2" --args "$3" \
|
|
@@ -137,7 +151,7 @@ bt_run() { # bt_run <File: BtOptimize|BtCombine> <Method> '<json args array>'
|
|
|
137
151
|
arg() { python3 -c "import json,sys; print(json.dumps([sys.argv[1]]))" "$1"; } # wraps one JSON options string as a run_script args array
|
|
138
152
|
```
|
|
139
153
|
|
|
140
|
-
Map flags into `MERGE` / `TUNE` (`--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`).
|
|
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`).
|
|
141
155
|
|
|
142
156
|
## Phase 0 — Preflight
|
|
143
157
|
|
|
@@ -166,7 +180,7 @@ node "$QA/profile-browser.mjs" --scene <source>.gltf --pin 40,60,75 --toggles no
|
|
|
166
180
|
|
|
167
181
|
`--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.
|
|
168
182
|
|
|
169
|
-
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), `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).
|
|
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).
|
|
170
184
|
|
|
171
185
|
## Phase 2 — Survey and plan
|
|
172
186
|
|
|
@@ -177,7 +191,9 @@ bt_run BtOptimize Tune "$(arg "$(echo "$TUNE" | sed 's/}$/,"dryRun":true}/')")"
|
|
|
177
191
|
bt_run BtCombine Analyze "$(arg "$MERGE")" # combine-plan.md (on the source: merges before tune unlocks)
|
|
178
192
|
```
|
|
179
193
|
|
|
180
|
-
|
|
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*. A group with no fix gets a measured reason. Do not start Phase 3 with a large group unexplained.
|
|
195
|
+
|
|
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.
|
|
181
197
|
|
|
182
198
|
## Phase 3 — Working copy, tune, merge
|
|
183
199
|
|
|
@@ -306,10 +322,11 @@ Reply in plain language with images, and write `$REPORT/report.md`:
|
|
|
306
322
|
|
|
307
323
|
- **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.
|
|
308
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).
|
|
309
|
-
- **
|
|
325
|
+
- **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
|
+
- **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).
|
|
310
327
|
- **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.
|
|
311
328
|
- **Checks:** Verify result, Unity captures, browser frames, console errors; anything skipped or unverified, stated as such.
|
|
312
|
-
- **How to undo:** `--reset`, or delete the working copy, `<Out>_CombinedMeshes/`, `<Out>/` (baked lighting) and `.agents/optimize/<Out>/`; re-tick any Volume Profile override listed in `tune.md`.
|
|
329
|
+
- **How to undo:** `--reset`, or delete the working copy, `<Out>_CombinedMeshes/`, `<Out>_UnskinnedMeshes/`, `<Out>_RetargetedClips/`, `<Out>/` (baked lighting) and `.agents/optimize/<Out>/`; re-tick any Volume Profile override listed in `tune.md`.
|
|
313
330
|
|
|
314
331
|
---
|
|
315
332
|
|
|
@@ -319,6 +336,8 @@ Reply in plain language with images, and write `$REPORT/report.md`:
|
|
|
319
336
|
|---|---|
|
|
320
337
|
| `<out scene>` | the working copy (tuned and merged) |
|
|
321
338
|
| `<out scene folder>/<Out>_CombinedMeshes/*.asset` | merged meshes |
|
|
339
|
+
| `<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
|
+
| `<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 |
|
|
322
341
|
| `<out scene folder>/<Out>/` | the copy's baked lighting |
|
|
323
342
|
| `.agents/optimize/<Source>/` | survey, tune plan, merge plan and "before" profiles of the source |
|
|
324
343
|
| `.agents/optimize/<Out>/` | `working-copy.txt`, `tune.md/json`, `combine-plan.*`, `combine-manifest.json`, `combine-verify.md`, `profile/`, `captures/`, `report.md` |
|
|
@@ -231,6 +231,10 @@ public static class BtCombine
|
|
|
231
231
|
AssetDatabase.ImportAsset(outputScene, ImportAssetOptions.ForceUpdate);
|
|
232
232
|
string meshFolder = MeshFolderFor(outputScene);
|
|
233
233
|
if (AssetDatabase.IsValidFolder(meshFolder)) AssetDatabase.DeleteAsset(meshFolder);
|
|
234
|
+
string unskinnedFolder = UnskinnedMeshFolderFor(outputScene);
|
|
235
|
+
if (AssetDatabase.IsValidFolder(unskinnedFolder)) AssetDatabase.DeleteAsset(unskinnedFolder);
|
|
236
|
+
string retargetedFolder = RetargetedClipFolderFor(outputScene);
|
|
237
|
+
if (AssetDatabase.IsValidFolder(retargetedFolder)) AssetDatabase.DeleteAsset(retargetedFolder);
|
|
234
238
|
string manifest = Path.Combine(ReportFolderFor(outputScene), "combine-manifest.json");
|
|
235
239
|
if (File.Exists(manifest)) File.Delete(manifest);
|
|
236
240
|
}
|
|
@@ -240,7 +244,7 @@ public static class BtCombine
|
|
|
240
244
|
return "opened=" + scene.path + " created=" + !existed + " reset=" + (existed && reset);
|
|
241
245
|
}
|
|
242
246
|
|
|
243
|
-
/// <summary>Deletes a working copy, its merged meshes, its baked lighting folder and its report folder.</summary>
|
|
247
|
+
/// <summary>Deletes a working copy, its merged and unskinned meshes, its retargeted clips, its baked lighting folder and its report folder.</summary>
|
|
244
248
|
public static string RemoveCopy(string outputScene, string reopenScene)
|
|
245
249
|
{
|
|
246
250
|
if (!File.Exists(WorkingCopyMarker(outputScene))) throw new InvalidOperationException(outputScene + " is not a bt-optimize working copy; refusing to delete it.");
|
|
@@ -248,6 +252,8 @@ public static class BtCombine
|
|
|
248
252
|
EditorSceneManager.OpenScene(reopenScene, OpenSceneMode.Single);
|
|
249
253
|
bool sceneDeleted = AssetDatabase.DeleteAsset(outputScene);
|
|
250
254
|
bool meshesDeleted = AssetDatabase.DeleteAsset(MeshFolderFor(outputScene));
|
|
255
|
+
AssetDatabase.DeleteAsset(UnskinnedMeshFolderFor(outputScene));
|
|
256
|
+
AssetDatabase.DeleteAsset(RetargetedClipFolderFor(outputScene));
|
|
251
257
|
bool lightingDeleted = AssetDatabase.DeleteAsset(Path.ChangeExtension(outputScene, null).Replace('\\', '/'));
|
|
252
258
|
string reportFolder = ReportFolderFor(outputScene);
|
|
253
259
|
if (Directory.Exists(reportFolder)) Directory.Delete(reportFolder, true);
|
|
@@ -1608,6 +1614,24 @@ public static class BtCombine
|
|
|
1608
1614
|
return Path.GetDirectoryName(scenePath).Replace('\\', '/') + "/" + Path.GetFileNameWithoutExtension(scenePath) + "_CombinedMeshes";
|
|
1609
1615
|
}
|
|
1610
1616
|
|
|
1617
|
+
/// <summary>
|
|
1618
|
+
/// Folder for the plain meshes BtOptimize.Tune bakes from rigid skinned meshes whose bind pose is offset from their
|
|
1619
|
+
/// object: <scene folder>/<scene>_UnskinnedMeshes. Keep the name in step with BtOptimize.UnskinnedMeshFolder.
|
|
1620
|
+
/// </summary>
|
|
1621
|
+
private static string UnskinnedMeshFolderFor(string scenePath)
|
|
1622
|
+
{
|
|
1623
|
+
return Path.GetDirectoryName(scenePath).Replace('\\', '/') + "/" + Path.GetFileNameWithoutExtension(scenePath) + "_UnskinnedMeshes";
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
/// <summary>
|
|
1627
|
+
/// Folder for the clips and controllers BtOptimize.Tune copies with their SkinnedMeshRenderer curves retargeted to
|
|
1628
|
+
/// MeshRenderer: <scene folder>/<scene>_RetargetedClips. Keep the name in step with BtOptimize.RetargetedClipFolder.
|
|
1629
|
+
/// </summary>
|
|
1630
|
+
private static string RetargetedClipFolderFor(string scenePath)
|
|
1631
|
+
{
|
|
1632
|
+
return Path.GetDirectoryName(scenePath).Replace('\\', '/') + "/" + Path.GetFileNameWithoutExtension(scenePath) + "_RetargetedClips";
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1611
1635
|
/// <summary>Folder for a scene's reports: <project>/.agents/optimize/<scene>.</summary>
|
|
1612
1636
|
private static string ReportFolderFor(string scenePath)
|
|
1613
1637
|
{
|