Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge remote-tracking branch 'origin/main' into merged/perf-package-room-2

Nguyen Xuan An5f55f4e06617
diff --cc CHANGELOG.md
index 5c0ecbf7,b8a23b8e..fe612ad3
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -2,8 -2,7 +2,9 @@@
## Unreleased
+- Make room in the npm package without adding a dependency (part of issue #36). The archive fell from 802,581 to 695,041 bytes (353,535 free under 1 MiB; the target was 300,000), and every library and MCP install stays as light as before. Two causes: (1) every one of the 80 built files began with the full `LICENSE` and `THIRD-PARTY-NOTICES.md` text, about 4 KB each; they now carry a one-line notice and the complete texts stay once at the package root, about 61,000 bytes saved; (2) the MCP SDK's Node shim pulls in Ajv (the validator for elicitation answers, about 270 KB before minification) that this server never uses, so `build/mcp/server.mjs` now bundles `scripts/mcp-sdk-shims.mjs` instead, which fails with a clear message if elicitation is ever requested: `server.mjs` fell from 677,484 to 484,111 bytes and the archive by about 47,000 bytes. `build/mcp/LICENSES.md` no longer lists the Ajv family because that code is gone, and its unused copies left `licenses/mcp/`. Measured, and not worth doing: `zod/mini` (zod's classic layer is 30 KB of the server before gzip), source maps (none are shipped), standalone core copies (none in the archive), and docs (every packaged page is linked from the README, `llms.txt`, the MCP guide or the skills). `npm run smoke:package` now loads every `exports` entry in a clean consumer. Film and site code were already outside the archive. Separate lazy-loaded packages were not built: the lazy addons together are about 157 KB gzip, so splitting them out could return at most that much, for the cost of a package, a release pipeline and a version matrix each. `archiveBytes` budget 815,000 to 705,500. Module load of the server is no slower (minimum of 25 runs, 217 and 188 ms against 231 and 209 ms).
+
+ - Run the heavy scene kernels on a worker in the MCP preview (part of issue #38; edits after creation still run on the main thread). The light bake, the cloth solver, `uv_unwrap` and pattern textures are pure functions of their input, so `runKernel` in the new `src/kernel-offload.js` computes them inline as before, or, inside `buildWithKernels`, throws `KernelDeferred`, lets a module worker (`kernel-worker.js`, a package entry like the path tracer's) compute the result, caches it by a hash of the input bytes and runs the synchronous build again. The preview builds `scene_create` that way when the page has `Worker`; Node and every other caller keep the synchronous path and the same bytes (a test builds one scene cold in a separate process both ways and compares a digest of geometry, textures and the bake report). A worker error comes back with its class and message, a worker that cannot start or dies leaves the job to the inline path, and an `AbortSignal` ends the build and the worker. Measured in Node on the demo recipe: the `uv_unwrap` stack takes 3.6 s, the draft light bake 7.5 s and the standard bake passes the 20 s limit on this machine, cloth at the 10 s limit takes 3.4 s, a 1024 pattern takes 1 to 7 s, a boolean 0.12 s. Measured in headless Chrome on the GPU backend with the demo room recipe (`tests/fixtures/demo-room.recipe.json`, 9 kernels): the longest stretch the page was unresponsive during `scene_create` fell from 11.8 and 11.9 s to 1.6 s with workers (two runs each), while the build took 12.3 and 12.5 s instead of 10.9 and 11.0 s, because the kernels run one after another and the build reruns after each. `scene_inspect` now reports `kernels`: how many kernels a worker served and how many ran inline, each fallback with its reason (also a `67js kernel fallback` line on stderr when a page that has `Worker` falls back), the build time and the longest block; `npm run smoke:kernel-workers` installs the package, runs the demo room and fails unless kernels ran on the worker with no fallback. The `longtask` observer saw nothing in either mode because the browser does not count work run by a remote-debugging call, so the block is measured with a 20 ms timer. `scene_apply` edits still run on the main thread. Core did not grow (`entry:core`, `lit-box` unchanged); the lazy entries rose by about 900 bytes gzip.
- Fix three gaps a demo film found in the recipe light bake (part of issue #55). A baked scene with `cloth` failed at render time for every frame after t=0 with "A light map needs lightUvs on rigid geometry, with no skin or morph", because the cloth simulation replaces the sheet's geometry each frame; cloth sheet nodes are now skipped and listed in `report.skipped`. The bake now lights with spot lights (the renderer's cone and soft edge) and area lights (front side only, one deterministic shadow ray to a point of the rectangle per hit), where it ignored both; a scene without them bakes the same bytes. The presets could not finish a normal scene (`standard` passed its 20 s limit on a 56 part room, `fine` hit the 30 s preview limit): a recipe bake now has a ray work budget of 10 million units (texels x samples x bounces x rays per hit), estimated from the unwrap before any ray is traced with no clock involved. A preset is scaled down to fit and `scene_inspect` `bake` reports `used` and `reduced`; explicit `samples`, `bounces` or `texelsPerUnit` are never reduced and fail with a message naming the number that fits. `bakeLightmaps` is now `planLightmaps`, `estimateBake` and `traceLightmaps` (still exported as one call). `entry:core` did not change; `entry:light-bake` grew by 1,033 bytes gzip (budget 25,900 to 26,900) and the lazy agent entries by about 1,580; the schema stayed within its total budget (the capability notes were shortened to fit).
- Add `sculpt` and `shrinkwrap` mesh edits (part of issue #47; surface patches and a stack form are not built). `sculpt` applies up to 32 inflate, displace and smooth strokes to the vertices of the selected faces; `shrinkwrap` moves them onto a primitive, to the nearest point or projected along a direction, with an offset. Both are in `scene_capabilities` (`meshSculpt`) and in the `mesh_edit` schema, with the tool schema total unchanged (the face rule and tag prefix descriptions were shortened to pay for them). The stroke maths moved to `src/sculpt-strokes.js` and serves `sculptGeometry` too. Four Blender golden cases (two Shrinkwrap modifier comparisons; the sculpt reference runs the same brush formula on Blender's mesh), hostile input tests, and the suite task `ball-badge`, which needs a plate bent onto a ball.