Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.
JavaScript 3d3d-assets3d-modelingagent-skillsagent-toolsai-agentsasset-pipelinecligame-assetsglbgltfmcpmcp-servermodel-context-protocolprocedural-generationprocedural-modelingtext-to-3dthreejstypescript
Name the DOM-free GLB read path, scope the draw cap, fix the fast loop (#295)
Matthew Kissingerad63b866c3c8
diff --git a/AGENTS.md b/AGENTS.mdindex d1fa8658..7930cc84 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -170,10 +170,10 @@ bun run test:coverage`bun run build` only typechecks. After runtime changes, run `node scripts/build-runtime.mjs all`to rebuild `dist/`, its identity and SDK `lib/` before CLI/MCP dogfood and full gates.-Use `bun run build:runtime` when viewer assets also changed. Fresh checkouts need-`bun run build:sdk` before typechecking or public-entrypoint tests.+Use `bun run build:runtime` when viewer assets also changed.-Fast loop: nearest test file first, then `bun run typecheck && bun run lint && bun run test`.+Fast loop: `bun run build:sdk` (a fresh checkout has no `lib/`: a missing build step, not+a broken tree), nearest test file, then `bun run typecheck && bun run lint && bun run test`.The full offline gate adds `bun run test:coverage`, which emits `coverage/lcov.info` andenforces the line/function ratchet in `bunfig.toml`. Raise thresholds when practical; neverlower them without a measured rationale. Live model tests are opt-in via `bun run test:live`.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8f450c58..9fade8c8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -47,6 +47,23 @@ does not publish a package.saving. Reproduced from a reported clean pass on a 2 mm detached part; the checks behavedas specified and the tolerance, not welding, is what admitted it. No check changesbehaviour ([#289](https://github.com/instruktlabs/kiln/issues/289)).+- The delivery contract states how to read a Kiln GLB without a DOM. three's `GLTFLoader`+ reads `self.URL` for every image, so `parseAsync` on a textured GLB throws+ `ReferenceError: self is not defined` under Node, and under Bun, which defines `self`, it+ binds a null map instead. An untextured GLB parses either way, so test scaffolding written+ against one passes and the same pattern fails on the first textured asset. The supported+ DOM-free path is `loadGlbReviewScene` from `@instruktlabs/kiln/views`, already public and+ already what the CPU view path uses; a reader assembled from `gltf-transform` directly+ drops the `MSFT_lod` chain unless the extension is registered. A new test loads a textured+ GLB through the reader with `self` deleted, so the documented guarantee cannot regress.+ Engine behaviour, exported bytes and browser loading are unchanged+ ([#292](https://github.com/instruktlabs/kiln/issues/292)).+- The `draws` cap in `defineBudget` states its pass scope. Discovery and the delivery+ contract already said the figure is what the GLB stores before any consumer batching; both+ now also say it counts the main pass only, because shadow, reflection and depth passes+ belong to the destination, where a shadow-casting part can cost a further draw in each.+ Wording only: no measured value, receipt field or tier status changes+ ([#291](https://github.com/instruktlabs/kiln/issues/291)).## 1.5.0 (2026-10-25)diff --git a/dist/agent-run.mjs b/dist/agent-run.mjsindex d00d4b36..6995bdc8 100644--- a/dist/agent-run.mjs+++ b/dist/agent-run.mjs@@ -43456,7 +43456,7 @@ define2("defineBudget", {coordinates: "Not a placement operation.",parameters: ["triangles: a positive integer for LOD0, or a record of tiers named LOD0, LOD1, ... with positive integers.",- "draws: optional positive integer, the LOD0 draw-call cap.",+ "draws: optional positive integer, the LOD0 draw-call cap. It counts the main pass only, as the GLB stores it and before any consumer batching: shadow, reflection and depth passes belong to the destination, so a shadow-casting part can cost a further draw in each of them.","target: optional scene node, normally the root."],topology: [noMesh],diff --git a/dist/build.json b/dist/build.jsonindex 2b72d28c..19f593a4 100644--- a/dist/build.json+++ b/dist/build.json@@ -2,10 +2,10 @@"schemaVersion": 1,"entries": {"worker": {- "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",+ "identity": "sha256:2bff9c95fd0652f2d244d339f2c82b1dd34766198236933cada9ae382e8a3a5f","engineVersion": "1.5.0","toolchain": "[email protected]",- "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",+ "sourceHash": "63773ab08b47dc0156580336a7143d5327d44c5d18ac9b23ff21326cb9f49b3b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -40,10 +40,10 @@"bundleHash": "sha256:4c5521b27238d6848a39c552d2844507d7bd2f92df3ce5e4e2b91d15ca521706"},"agent-run": {- "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",+ "identity": "sha256:2bff9c95fd0652f2d244d339f2c82b1dd34766198236933cada9ae382e8a3a5f","engineVersion": "1.5.0","toolchain": "[email protected]",- "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",+ "sourceHash": "63773ab08b47dc0156580336a7143d5327d44c5d18ac9b23ff21326cb9f49b3b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -75,13 +75,13 @@},"target": "node","file": "agent-run.mjs",- "bundleHash": "sha256:632042c1d9d6a4d6ea6209718d54b0cbd99863782ab51e6e0f3f6a65bd5cf0a5"+ "bundleHash": "sha256:33747e032418f3bf976da377d5335ff7edc10db2bd8f8dc11fb4a65af2443273"},"agent-providers": {- "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",+ "identity": "sha256:2bff9c95fd0652f2d244d339f2c82b1dd34766198236933cada9ae382e8a3a5f","engineVersion": "1.5.0","toolchain": "[email protected]",- "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",+ "sourceHash": "63773ab08b47dc0156580336a7143d5327d44c5d18ac9b23ff21326cb9f49b3b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -116,10 +116,10 @@"bundleHash": "sha256:9d6faf03d307321bc2e3bd5ce5bdee0bbbf61e0ebed8bfebfa1fb072287b83fa"},"mcp": {- "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",+ "identity": "sha256:2bff9c95fd0652f2d244d339f2c82b1dd34766198236933cada9ae382e8a3a5f","engineVersion": "1.5.0","toolchain": "[email protected]",- "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",+ "sourceHash": "63773ab08b47dc0156580336a7143d5327d44c5d18ac9b23ff21326cb9f49b3b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -154,10 +154,10 @@"bundleHash": "sha256:deeb947091b693e92337a2081678ed06cd0a2d23f813a375001c31dbf529a815"},"cli": {- "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",+ "identity": "sha256:2bff9c95fd0652f2d244d339f2c82b1dd34766198236933cada9ae382e8a3a5f","engineVersion": "1.5.0","toolchain": "[email protected]",- "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",+ "sourceHash": "63773ab08b47dc0156580336a7143d5327d44c5d18ac9b23ff21326cb9f49b3b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -189,13 +189,13 @@},"target": "node","file": "cli.mjs",- "bundleHash": "sha256:47ae66667a40f15555369996d039e58dd90a11fd661ebb9a3965819b1ce44568"+ "bundleHash": "sha256:6399e324ae81df586ab6ec6cca3c9a03e60fcc879d23a0bfe9ccbfb76f934e9e"},"engine": {- "identity": "sha256:b817cd61ecee540bb6f68f5ac4c9f8f2c1860d4f307acdd5efd6c2da1cc11171",+ "identity": "sha256:2bff9c95fd0652f2d244d339f2c82b1dd34766198236933cada9ae382e8a3a5f","engineVersion": "1.5.0","toolchain": "[email protected]",- "sourceHash": "f53a7b8fe566fbcc1756dd50decf7329d38fc853cc88ed2bf05c34f3e44aca03",+ "sourceHash": "63773ab08b47dc0156580336a7143d5327d44c5d18ac9b23ff21326cb9f49b3b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -227,7 +227,7 @@},"target": "node","file": "mcp-engine.mjs",- "bundleHash": "sha256:c3b19ac35fba13051365f1346876c695d965372ed75a52f9d416fd6ceafd77bf"+ "bundleHash": "sha256:e84cf4c11c00d00d83252bad2c7e0ea2de14a84fef2507015670dbcf619cc3ab"}}}diff --git a/dist/cli.mjs b/dist/cli.mjsindex 1b5256e0..9e4f2171 100644--- a/dist/cli.mjs+++ b/dist/cli.mjs@@ -47388,7 +47388,7 @@ var init_helper_contracts = __esm(() => {coordinates: "Not a placement operation.",parameters: ["triangles: a positive integer for LOD0, or a record of tiers named LOD0, LOD1, ... with positive integers.",- "draws: optional positive integer, the LOD0 draw-call cap.",+ "draws: optional positive integer, the LOD0 draw-call cap. It counts the main pass only, as the GLB stores it and before any consumer batching: shadow, reflection and depth passes belong to the destination, so a shadow-casting part can cost a further draw in each of them.","target: optional scene node, normally the root."],topology: [noMesh],diff --git a/dist/mcp-engine.mjs b/dist/mcp-engine.mjsindex df432498..46355544 100644--- a/dist/mcp-engine.mjs+++ b/dist/mcp-engine.mjs@@ -47742,7 +47742,7 @@ define2("defineBudget", {coordinates: "Not a placement operation.",parameters: ["triangles: a positive integer for LOD0, or a record of tiers named LOD0, LOD1, ... with positive integers.",- "draws: optional positive integer, the LOD0 draw-call cap.",+ "draws: optional positive integer, the LOD0 draw-call cap. It counts the main pass only, as the GLB stores it and before any consumer batching: shadow, reflection and depth passes belong to the destination, so a shadow-casting part can cost a further draw in each of them.","target: optional scene node, normally the root."],topology: [noMesh],diff --git a/docs/delivery-contract.md b/docs/delivery-contract.mdindex 26761edd..0ff0e8ab 100644--- a/docs/delivery-contract.md+++ b/docs/delivery-contract.md@@ -59,7 +59,10 @@ attribute names, so shaders read `_edge` and `_cavity`.`kilnBudgetV1`. Tier n is measured as level `min(n, last)` of every `MSFT_lod`chain plus everything outside the chains; `draws` caps LOD0 draw calls as the GLBstores them, before any consumer batching, so each child of a `repeatInstances` group- counts. Beside the measured `draws`, the LOD0 tier reports `instancedDraws`: the draws+ counts. It is a main-pass count: shadow, reflection and depth passes belong to the+ destination, so a shadow-casting part can cost a further draw in each of them, and a+ dense vegetation view can spend nearly as many draws again on shadow alone.+ Beside the measured `draws`, the LOD0 tier reports `instancedDraws`: the drawsthe three runtime target leaves after batching each group into one instanced draw.It is informational and never changes the tier's status. Optionalmaterial limits are `images`, `decodedBytes` (RGBA8, before mips) and `materialTier`,@@ -186,6 +189,17 @@ Consumer rules that follow from it:Do not show all levels together. A final impostor marker does not implementbillboarding or distance-based switching. A consumer that draws LOD0 only can exportwith `--max-lod 0` so the lower levels are not shipped at all.+- **Read a GLB without a DOM through `loadGlbReviewScene`, not `GLTFLoader`.** three's+ `GLTFLoader` reads `self.URL` for every image, so `parseAsync` on a textured GLB throws+ `ReferenceError: self is not defined` under Node; under a runtime that defines `self`,+ such as Bun, it instead reports `Couldn't load texture` and binds a null map. An+ untextured GLB parses either way, so test scaffolding written against one passes and the+ same pattern fails on the first textured asset. `loadGlbReviewScene(bytes)` from+ `@instruktlabs/kiln/views` reads the same chunks through `gltf-transform` with no DOM+ global: it returns `root` and `clips`, binds each map with its encoded bytes on+ `userData.encoded`, and attaches LOD0 as a browser consumer sees it. A reader assembled+ from `gltf-transform` directly drops the `MSFT_lod` chain unless the extension is+ registered. Loading in a browser is unaffected.`src/__tests__/runtime-three-export.test.ts` qualifies static geometry, role data,instancing, explicit lower-tier selection and a quantized skin through Three'sdiff --git a/src/discovery/helper-contracts.ts b/src/discovery/helper-contracts.tsindex 65e21d64..56274fbe 100644--- a/src/discovery/helper-contracts.ts+++ b/src/discovery/helper-contracts.ts@@ -1087,7 +1087,7 @@ define(coordinates: 'Not a placement operation.',parameters: ['triangles: a positive integer for LOD0, or a record of tiers named LOD0, LOD1, ... with positive integers.',- 'draws: optional positive integer, the LOD0 draw-call cap.',+ 'draws: optional positive integer, the LOD0 draw-call cap. It counts the main pass only, as the GLB stores it and before any consumer batching: shadow, reflection and depth passes belong to the destination, so a shadow-casting part can cost a further draw in each of them.','target: optional scene node, normally the root.',],topology: [noMesh],diff --git a/src/views/__tests__/glb.test.ts b/src/views/__tests__/glb.test.tsindex 2272a416..b0bd15f0 100644--- a/src/views/__tests__/glb.test.ts+++ b/src/views/__tests__/glb.test.ts@@ -293,6 +293,34 @@ describe('GLB-native geometry-flat view input', () => {expect(encoded).toEqual(expected);});+ // The delivery contract tells consumers to read a GLB headlessly through this+ // reader because three's GLTFLoader reads `self.URL` for every image: `parseAsync`+ // on a textured GLB throws `ReferenceError: self is not defined` under Node and+ // binds a null map under Bun, which defines `self` (#292). Deleting the global is+ // what makes this a guard rather than a restatement -- GLTFLoader throws here.+ test('review scene binds an embedded texture with no DOM global defined', async () => {+ const source = triangleDocument({ texture: true });+ const expected = source.getRoot().listTextures()[0]!.getImage()!;+ const bytes = await io().writeBinary(source);+ const scope = globalThis as { self?: unknown };+ const had = 'self' in scope;+ const previous = scope.self;+ delete scope.self;+ try {+ const loaded = await loadGlbReviewScene(bytes);+ const bound: Uint8Array[] = [];+ loaded.root.traverse((node) => {+ const map = (node as { material?: { map?: { userData?: Record<string, unknown> } } })+ .material?.map;+ const record = map?.userData?.encoded as { bytes?: Uint8Array } | undefined;+ if (record?.bytes) bound.push(record.bytes);+ });+ expect(bound).toEqual([expected]);+ } finally {+ if (had) scope.self = previous;+ }+ });+test('review scene retains normal and uv attributes from primitive', async () => {const doc = triangleDocument();const buffer = doc.getRoot().listBuffers()[0]!;