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
feat(export): allow the three runtime target without Meshopt (#219) (#233)
Matthew Kissingerc4377eaa55bf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 59e70f94..c8d9ddae 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -87,6 +87,12 @@ does not publish a package.beside the `UNKNOWN_ID` error, which names only the unknown IDs; no substitution is made anda request with no known ID still returns no entries. `pbrMaterial` now ranks first forroughness-map queries (#218).+- Allow the three runtime target without Meshopt ([#219](https://github.com/instruktlabs/kiln/issues/219)).+ `exportAssetGlb`/`deliverThreeRuntimeGlb` accept `compression: 'none'` and the CLI accepts+ `--compression none` with `--target three`: buffers stay plain, so a loader without a+ Meshopt decoder reads the GLB, while `KHR_mesh_quantization`, instancing and every+ preserved feature stay. The sidecar `delivery.compression` records `{ extension: 'none' }`.+ The default output is unchanged.## 1.3.1 (2026-10-17)diff --git a/dist/agent-run.mjs b/dist/agent-run.mjsindex cded262c..9c44c97a 100644--- a/dist/agent-run.mjs+++ b/dist/agent-run.mjs@@ -37848,6 +37848,9 @@ function decomposeDelta(before, after) {};}async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {+ const compression = options.compression ?? "meshopt";+ if (compression !== "meshopt" && compression !== "none")+ throw new Error("Runtime three compression must be meshopt or none");const io = createGltfIO().registerDependencies({"meshopt.encoder": meshoptEncoder});@@ -37870,7 +37873,8 @@ async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {quantizeColor: RUNTIME_THREE_QUANTIZATION.color,quantizeWeight: RUNTIME_THREE_QUANTIZATION.weight}));- doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });+ if (compression === "meshopt")+ doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });const ktx2 = await encodeKtx2(doc, options.ktx2Encoder);for (const node of doc.getRoot().listNodes()) {const mesh = node.getMesh();@@ -37934,7 +37938,7 @@ async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {target: "three",extensionsUsed: [...json.extensionsUsed ?? []].sort(),extensionsRequired: [...json.extensionsRequired ?? []].sort(),- compression: { extension: "EXT_meshopt_compression", method: "quantize" },+ compression: compression === "meshopt" ? { extension: "EXT_meshopt_compression", method: "quantize" } : { extension: "none" },quantization: {extension: "KHR_mesh_quantization",volume: "mesh",@@ -38053,6 +38057,8 @@ async function exportAssetGlb(record, options = {}) {throw new Error("Unknown runtime export target");if (options.target !== undefined && profile !== "runtime")throw new Error("A runtime export target requires the runtime profile");+ if (options.compression !== undefined && options.target !== "three")+ throw new Error("Runtime compression requires the three runtime target");validateRecordShape(record);const bytes = record.files["asset.glb"];if (profile === "editable")@@ -38095,7 +38101,8 @@ async function exportAssetGlb(record, options = {}) {let base = bytes, baseJson = json, baseJsonEnd = jsonEnd;if (options.target === "three") {const derived = await deliverThreeRuntimeGlb(writeGlbJson(bytes, jsonEnd, json), {- ...options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {}+ ...options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {},+ ...options.compression ? { compression: options.compression } : {}});metadata.target = "three";metadata.delivery = derived.delivery;diff --git a/dist/build.json b/dist/build.jsonindex 135ec36e..7f512c67 100644--- a/dist/build.json+++ b/dist/build.json@@ -2,10 +2,10 @@"schemaVersion": 1,"entries": {"worker": {- "identity": "sha256:f1936abb73114537073d9061b79c903987853d21562cbc6cf0496e12ff8acb43",+ "identity": "sha256:fb9b1409ce7a7d5ce24f06828658b013762cecc801aaf70c31fdd41d44d4c8c2","engineVersion": "1.3.1","toolchain": "[email protected]",- "sourceHash": "96210a83ce55f04135f19d0ab051aadbf25f6bac5734cd783ec8e48420fd05b1",+ "sourceHash": "5ee9b6bf3672d303291bb8fe18ddb673dacadb219640d1f1cea82b3f9ac7519b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3","dependencies": {@@ -40,10 +40,10 @@"bundleHash": "sha256:eb4c421782d3d96e7f4ba04072ecdca10af471d17299bc42a1e0e2fc4c54c421"},"agent-run": {- "identity": "sha256:f1936abb73114537073d9061b79c903987853d21562cbc6cf0496e12ff8acb43",+ "identity": "sha256:fb9b1409ce7a7d5ce24f06828658b013762cecc801aaf70c31fdd41d44d4c8c2","engineVersion": "1.3.1","toolchain": "[email protected]",- "sourceHash": "96210a83ce55f04135f19d0ab051aadbf25f6bac5734cd783ec8e48420fd05b1",+ "sourceHash": "5ee9b6bf3672d303291bb8fe18ddb673dacadb219640d1f1cea82b3f9ac7519b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3","dependencies": {@@ -75,13 +75,13 @@},"target": "node","file": "agent-run.mjs",- "bundleHash": "sha256:c12f6fdb2e30e1f8694047341588c3b155ef49986322b71c9df7a9535111ae89"+ "bundleHash": "sha256:74d69033c8ffa36f7b060a54845f71a0d7d4cd5e9ec60237d080ec7f5e374d8f"},"agent-providers": {- "identity": "sha256:f1936abb73114537073d9061b79c903987853d21562cbc6cf0496e12ff8acb43",+ "identity": "sha256:fb9b1409ce7a7d5ce24f06828658b013762cecc801aaf70c31fdd41d44d4c8c2","engineVersion": "1.3.1","toolchain": "[email protected]",- "sourceHash": "96210a83ce55f04135f19d0ab051aadbf25f6bac5734cd783ec8e48420fd05b1",+ "sourceHash": "5ee9b6bf3672d303291bb8fe18ddb673dacadb219640d1f1cea82b3f9ac7519b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3","dependencies": {@@ -116,10 +116,10 @@"bundleHash": "sha256:9d6faf03d307321bc2e3bd5ce5bdee0bbbf61e0ebed8bfebfa1fb072287b83fa"},"mcp": {- "identity": "sha256:f1936abb73114537073d9061b79c903987853d21562cbc6cf0496e12ff8acb43",+ "identity": "sha256:fb9b1409ce7a7d5ce24f06828658b013762cecc801aaf70c31fdd41d44d4c8c2","engineVersion": "1.3.1","toolchain": "[email protected]",- "sourceHash": "96210a83ce55f04135f19d0ab051aadbf25f6bac5734cd783ec8e48420fd05b1",+ "sourceHash": "5ee9b6bf3672d303291bb8fe18ddb673dacadb219640d1f1cea82b3f9ac7519b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3","dependencies": {@@ -154,10 +154,10 @@"bundleHash": "sha256:a246b2c79d629a332cef4430dbe742b0c4a0d2f04f0281e673c3c60ff22706da"},"cli": {- "identity": "sha256:f1936abb73114537073d9061b79c903987853d21562cbc6cf0496e12ff8acb43",+ "identity": "sha256:fb9b1409ce7a7d5ce24f06828658b013762cecc801aaf70c31fdd41d44d4c8c2","engineVersion": "1.3.1","toolchain": "[email protected]",- "sourceHash": "96210a83ce55f04135f19d0ab051aadbf25f6bac5734cd783ec8e48420fd05b1",+ "sourceHash": "5ee9b6bf3672d303291bb8fe18ddb673dacadb219640d1f1cea82b3f9ac7519b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3","dependencies": {@@ -189,13 +189,13 @@},"target": "node","file": "cli.mjs",- "bundleHash": "sha256:9960552936452073bc433f715c4c032a9777a65aa4e02cb92b6ea5c45e2b62d7"+ "bundleHash": "sha256:689fbdd3acf0742745c2e579ac399dccd49363113afd474208136ab26bdda194"},"engine": {- "identity": "sha256:f1936abb73114537073d9061b79c903987853d21562cbc6cf0496e12ff8acb43",+ "identity": "sha256:fb9b1409ce7a7d5ce24f06828658b013762cecc801aaf70c31fdd41d44d4c8c2","engineVersion": "1.3.1","toolchain": "[email protected]",- "sourceHash": "96210a83ce55f04135f19d0ab051aadbf25f6bac5734cd783ec8e48420fd05b1",+ "sourceHash": "5ee9b6bf3672d303291bb8fe18ddb673dacadb219640d1f1cea82b3f9ac7519b","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3","dependencies": {@@ -227,7 +227,7 @@},"target": "node","file": "mcp-engine.mjs",- "bundleHash": "sha256:d80eb0c40aa1e063377c4d1a8e52753af7fb483cc2f9d09129d04bd6a288a379"+ "bundleHash": "sha256:4aa709eeff1d69fd57dfecf6a3f49c9a0a669484ad8ac40caab4ec1fa850f06e"}}}diff --git a/dist/cli.mjs b/dist/cli.mjsindex d67c74b5..ae0e8f01 100644--- a/dist/cli.mjs+++ b/dist/cli.mjs@@ -41961,6 +41961,9 @@ function decomposeDelta(before, after) {};}async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {+ const compression = options.compression ?? "meshopt";+ if (compression !== "meshopt" && compression !== "none")+ throw new Error("Runtime three compression must be meshopt or none");const io = createGltfIO().registerDependencies({"meshopt.encoder": meshoptEncoder});@@ -41983,7 +41986,8 @@ async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {quantizeColor: RUNTIME_THREE_QUANTIZATION.color,quantizeWeight: RUNTIME_THREE_QUANTIZATION.weight}));- doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });+ if (compression === "meshopt")+ doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });const ktx2 = await encodeKtx2(doc, options.ktx2Encoder);for (const node of doc.getRoot().listNodes()) {const mesh = node.getMesh();@@ -42047,7 +42051,7 @@ async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {target: "three",extensionsUsed: [...json.extensionsUsed ?? []].sort(),extensionsRequired: [...json.extensionsRequired ?? []].sort(),- compression: { extension: "EXT_meshopt_compression", method: "quantize" },+ compression: compression === "meshopt" ? { extension: "EXT_meshopt_compression", method: "quantize" } : { extension: "none" },quantization: {extension: "KHR_mesh_quantization",volume: "mesh",@@ -42166,6 +42170,8 @@ async function exportAssetGlb(record, options = {}) {throw new Error("Unknown runtime export target");if (options.target !== undefined && profile !== "runtime")throw new Error("A runtime export target requires the runtime profile");+ if (options.compression !== undefined && options.target !== "three")+ throw new Error("Runtime compression requires the three runtime target");validateRecordShape(record);const bytes = record.files["asset.glb"];if (profile === "editable")@@ -42208,7 +42214,8 @@ async function exportAssetGlb(record, options = {}) {let base = bytes, baseJson = json, baseJsonEnd = jsonEnd;if (options.target === "three") {const derived = await deliverThreeRuntimeGlb(writeGlbJson(bytes, jsonEnd, json), {- ...options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {}+ ...options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {},+ ...options.compression ? { compression: options.compression } : {}});metadata.target = "three";metadata.delivery = derived.delivery;@@ -53656,6 +53663,7 @@ async function assetMain(argv) {"format","profile","target",+ "compression","port","render","backdrop",@@ -53858,6 +53866,11 @@ async function assetMain(argv) {throw new Error("Unknown export target");if (target !== undefined && profile !== "runtime")throw new Error("--target requires --profile runtime");+ const compression = flags.compression;+ if (compression !== undefined && compression !== "meshopt" && compression !== "none")+ throw new Error("--compression must be meshopt or none");+ if (compression !== undefined && target !== "three")+ throw new Error("--compression requires --target three");const format = flags.format ?? (profile === "runtime" ? "glb" : "bundle");if (!["bundle", "glb", "source"].includes(format))throw new Error("Unknown export format");@@ -53872,7 +53885,8 @@ async function assetMain(argv) {const output = await exportAssetGlb(record, {profile,metadataFileName,- ...target ? { target } : {}+ ...target ? { target } : {},+ ...compression ? { compression } : {}});if (output.profile !== "runtime")throw new Error("Expected runtime export");@@ -53901,6 +53915,7 @@ async function assetMain(argv) {revisionId,profile,...target ? { target } : {},+ ...compression ? { compression } : {},format,...format !== "source" ? {drawDiagnostics: await inspectDrawDiagnostics(written.find(({ kind }) => kind === "glb")?.data ?? record.files["asset.glb"])@@ -54023,6 +54038,8 @@ ${SAVE_LINES}[--profile editable|runtime] runtime writes GLB + sibling metadata JSON[--target three] runtime only: meshopt + quantization, repeatInstances GPUinstancing, KTX2 skipped (no encoder); sidecar states node scales+ [--compression meshopt|none] with --target three: none writes plain buffers+ for loaders without a Meshopt decoder (default meshopt)[--json] receipt naming each file with its bytes and sha256export never replaces an existing file: an export hands off one exactsaved revision, while render --out replaces its own working outputdiff --git a/dist/mcp-engine.mjs b/dist/mcp-engine.mjsindex 053cc5c9..4125a899 100644--- a/dist/mcp-engine.mjs+++ b/dist/mcp-engine.mjs@@ -8971,6 +8971,9 @@ function decomposeDelta(before, after) {};}async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {+ const compression = options.compression ?? "meshopt";+ if (compression !== "meshopt" && compression !== "none")+ throw new Error("Runtime three compression must be meshopt or none");const io = createGltfIO().registerDependencies({"meshopt.encoder": meshoptEncoder});@@ -8993,7 +8996,8 @@ async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {quantizeColor: RUNTIME_THREE_QUANTIZATION.color,quantizeWeight: RUNTIME_THREE_QUANTIZATION.weight}));- doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });+ if (compression === "meshopt")+ doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });const ktx2 = await encodeKtx2(doc, options.ktx2Encoder);for (const node of doc.getRoot().listNodes()) {const mesh = node.getMesh();@@ -9057,7 +9061,7 @@ async function deliverRuntimeThreeGlb(bytes, meshoptEncoder, options = {}) {target: "three",extensionsUsed: [...json.extensionsUsed ?? []].sort(),extensionsRequired: [...json.extensionsRequired ?? []].sort(),- compression: { extension: "EXT_meshopt_compression", method: "quantize" },+ compression: compression === "meshopt" ? { extension: "EXT_meshopt_compression", method: "quantize" } : { extension: "none" },quantization: {extension: "KHR_mesh_quantization",volume: "mesh",@@ -9176,6 +9180,8 @@ async function exportAssetGlb(record, options = {}) {throw new Error("Unknown runtime export target");if (options.target !== undefined && profile !== "runtime")throw new Error("A runtime export target requires the runtime profile");+ if (options.compression !== undefined && options.target !== "three")+ throw new Error("Runtime compression requires the three runtime target");validateRecordShape(record);const bytes = record.files["asset.glb"];if (profile === "editable")@@ -9218,7 +9224,8 @@ async function exportAssetGlb(record, options = {}) {let base = bytes, baseJson = json, baseJsonEnd = jsonEnd;if (options.target === "three") {const derived = await deliverThreeRuntimeGlb(writeGlbJson(bytes, jsonEnd, json), {- ...options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {}+ ...options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {},+ ...options.compression ? { compression: options.compression } : {}});metadata.target = "three";metadata.delivery = derived.delivery;diff --git a/docs/export-profiles.md b/docs/export-profiles.mdindex 0621aa57..d22e24c0 100644--- a/docs/export-profiles.md+++ b/docs/export-profiles.md@@ -191,7 +191,9 @@ What it does, in order:3. Vertices are reordered for compression, then quantized with `KHR_mesh_quantization`per mesh: position 14 bits, normal 10, texcoord 12, colour 8, weights 8.Underscore attributes such as `_EDGE` and `_CAVITY` are **not** quantized and stay- FLOAT. Buffers are written with `EXT_meshopt_compression` (required).+ FLOAT. Buffers are written with `EXT_meshopt_compression` (required) unless the+ caller passes `compression: 'none'` (CLI `--compression none`): then buffers stay plain,+ no Meshopt decoder is needed, and quantization, instancing and everything below stay.4. Textures become KTX2 (`KHR_texture_basisu`) only when the library caller passes a`ktx2Encoder`; Kiln ships none, so the CLI reports `ktx2: { status: 'skipped' }` andtextures stay PNG or JPEG.@@ -202,6 +204,7 @@ Roles and kit extras, hidden collider nodes (`KHR_node_visibility`), anchors, po| Field | Meaning || --- | --- || `extensionsUsed`, `extensionsRequired` | The derived GLB's extension sets |+| `compression` | `{ extension: 'EXT_meshopt_compression', method: 'quantize' }`, or `{ extension: 'none' }` || `quantization` | Bits per attribute class; `customAttributes: 'float32'` || `nodeScale` | Every node whose matrix now carries a dequantization `{ scale, offset }`, its `localScale`, and whether the mesh moved to a child (`meshMovedToChild`, `authoredNode`) || `colliderProxies` | Collider node and proxy child paths |@@ -211,8 +214,8 @@ Roles and kit extras, hidden collider nodes (`KHR_node_visibility`), anchors, po| `preserved` | Counts of LOD chains, hidden nodes, colliders, anchors, ports and kit modules |Quantization stores positions as normalized integers and moves the metre scale onto-the node: read geometry through the node's world matrix. A loader needs the meshopt-decoder; with three.js:+the node: read geometry through the node's world matrix. With Meshopt compression (the+default) a loader needs the meshopt decoder; with three.js:```tsimport { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';@@ -222,7 +225,8 @@ await MeshoptDecoder.ready;const gltf = await new GLTFLoader().setMeshoptDecoder(MeshoptDecoder).parseAsync(buffer, '');```-three's `GLTFLoader` keeps unknown node extensions in `userData.gltfExtensions`+With `compression: 'none'`, `new GLTFLoader().parseAsync(buffer, '')` loads it without a+decoder. three's `GLTFLoader` keeps unknown node extensions in `userData.gltfExtensions`(`KHR_node_visibility`, `MSFT_lod`) and lowercases custom attributes (`_edge`).Kiln's tests load the derived GLB from both converters this way. On a very small assetthe extension JSON can outweigh the saved geometry; compare real assets.diff --git a/skills/kiln-author-asset/references/export-profiles.md b/skills/kiln-author-asset/references/export-profiles.mdindex 9fe0018f..0df1335f 100644--- a/skills/kiln-author-asset/references/export-profiles.md+++ b/skills/kiln-author-asset/references/export-profiles.md@@ -55,7 +55,9 @@ instances. Read the current Discovery export capability and the packagedPlain `--profile runtime` keeps the byte-preserving geometry policy described below;the additional target changes geometry encoding and can change hierarchy.-Use this target only for a consumer configured with Meshopt decoding. Preserve+Use this target with Meshopt decoding configured in the consumer, or add+`--compression none` for a loader without a Meshopt decoder: buffers stay plain while+quantization and instancing remain. Preserveloaded node transforms, skeletons and inverse bind matrices: they restore quantizedpositions to the intended dimensions. A loader does not automatically implementKiln's LOD selection, collider behavior, anchors or kit snapping. Test those in thediff --git a/src/__tests__/runtime-three-export.test.ts b/src/__tests__/runtime-three-export.test.tsindex b88299b9..7e6eb517 100644--- a/src/__tests__/runtime-three-export.test.ts+++ b/src/__tests__/runtime-three-export.test.ts@@ -189,6 +189,69 @@ describe('three runtime target', () => {expect(cardBounds.getCenter(new THREE.Vector3()).y).toBeCloseTo(3.1, 3);});+ test('compression none loads without a Meshopt decoder and keeps every other feature', async () => {+ const rendered = await renderGLBInProcess(RUNTIME_PROGRAM);+ const source = new Uint8Array(rendered.glb);+ const derive = (compression?: 'meshopt' | 'none') =>+ exportAssetGlb(assetRecord(source), {+ profile: 'runtime',+ target: 'three',+ ...(compression ? { compression } : {}),+ });+ const [plain, meshopt, defaulted] = await Promise.all([+ derive('none'),+ derive('meshopt'),+ derive(),+ ]);+ if (+ plain.profile !== 'runtime' ||+ meshopt.profile !== 'runtime' ||+ defaulted.profile !== 'runtime'+ )+ throw new Error('expected runtime');+ // The default is the Meshopt output, byte for byte.+ expect(defaulted.glb).toEqual(meshopt.glb);+ expect(defaulted.metadata.bytes).toEqual(meshopt.metadata.bytes);+ const delivery = JSON.parse(new TextDecoder().decode(plain.metadata.bytes)).delivery;+ expect(delivery.compression).toEqual({ extension: 'none' });+ expect(delivery.extensionsUsed).not.toContain('EXT_meshopt_compression');+ expect(delivery.extensionsRequired).not.toContain('EXT_meshopt_compression');+ expect(delivery.extensionsRequired).toEqual(+ expect.arrayContaining(['KHR_mesh_quantization', 'EXT_mesh_gpu_instancing']),+ );+ expect(delivery.customAttributes.map((a: { name: string }) => a.name)).toEqual([+ '_EDGE',+ '_CAVITY',+ ]);+ const meshoptDelivery = JSON.parse(new TextDecoder().decode(meshopt.metadata.bytes)).delivery;+ expect({+ ...delivery,+ compression: undefined,+ extensionsUsed: undefined,+ extensionsRequired: undefined,+ }).toEqual({+ ...meshoptDelivery,+ compression: undefined,+ extensionsUsed: undefined,+ extensionsRequired: undefined,+ });+ // A loader with no Meshopt decoder reads it, instancing included.+ const gltf = await new GLTFLoader().parseAsync(Uint8Array.from(plain.glb).buffer, '');+ const instanced: THREE.InstancedMesh[] = [];+ gltf.scene.traverse((object) => {+ if ((object as THREE.InstancedMesh).isInstancedMesh) instanced.push(object as never);+ });+ expect(instanced.map((mesh) => mesh.count)).toEqual([4]);+ await expect(+ new GLTFLoader().parseAsync(Uint8Array.from(meshopt.glb).buffer, ''),+ ).rejects.toThrow(/meshopt/i);+ await expect(+ exportAssetGlb(assetRecord(source), { profile: 'runtime', compression: 'none' }),+ ).rejects.toThrow('compression requires the three runtime target');+ await expect(deliverThreeRuntimeGlb(source, { compression: 'zstd' as never })).rejects.toThrow(+ 'compression must be meshopt or none',+ );+ });test('KTX2 runs only through an injected encoder and the GLB library helper is equivalent', async () => {const texture = new THREE.DataTexture(new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255]),diff --git a/src/asset-cli.test.ts b/src/asset-cli.test.tsindex 54ebe18c..d2d54ab2 100644--- a/src/asset-cli.test.ts+++ b/src/asset-cli.test.ts@@ -198,9 +198,34 @@ test('CLI saves, exports, imports, and restores a revision across independent stktx2: { status: 'skipped' },},});+ // Without Meshopt for loaders that have no decoder; the sidecar records the choice.+ const plain = join(root, 'plain.glb');+ const plainRun = run('first', [+ 'export',+ asset.assetId,+ asset.revisionId,+ '--out',+ plain,+ '--profile',+ 'runtime',+ '--target',+ 'three',+ '--compression',+ 'none',+ '--json',+ ]);+ expect(plainRun.status).toBe(0);+ expect(JSON.parse(plainRun.stdout)).toMatchObject({ target: 'three', compression: 'none' });+ const plainDelivery = JSON.parse(+ await readFile(join(root, 'plain.kiln-metadata.json'), 'utf8'),+ ).delivery;+ expect(plainDelivery.compression).toEqual({ extension: 'none' });+ expect(plainDelivery.extensionsRequired).not.toContain('EXT_meshopt_compression');for (const flags of [['--profile', 'editable', '--target', 'three'],['--profile', 'runtime', '--target', 'unity'],+ ['--profile', 'runtime', '--compression', 'none'],+ ['--profile', 'runtime', '--target', 'three', '--compression', 'zstd'],['--profile', 'unknown'],['--profile', 'runtime', '--format', 'bundle'],['--profile', 'runtime', '--format', 'source'],diff --git a/src/asset-cli.ts b/src/asset-cli.tsindex 0df1ca4b..303601ce 100644--- a/src/asset-cli.ts+++ b/src/asset-cli.ts@@ -53,6 +53,8 @@ ${SAVE_LINES}[--profile editable|runtime] runtime writes GLB + sibling metadata JSON[--target three] runtime only: meshopt + quantization, repeatInstances GPUinstancing, KTX2 skipped (no encoder); sidecar states node scales+ [--compression meshopt|none] with --target three: none writes plain buffers+ for loaders without a Meshopt decoder (default meshopt)[--json] receipt naming each file with its bytes and sha256export never replaces an existing file: an export hands off one exactsaved revision, while render --out replaces its own working output@@ -91,6 +93,7 @@ export async function assetMain(argv: readonly string[]): Promise<number> {'format','profile','target',+ 'compression','port','render','backdrop',@@ -379,6 +382,11 @@ export async function assetMain(argv: readonly string[]): Promise<number> {if (target !== undefined && target !== 'three') throw new Error('Unknown export target');if (target !== undefined && profile !== 'runtime')throw new Error('--target requires --profile runtime');+ const compression = flags.compression;+ if (compression !== undefined && compression !== 'meshopt' && compression !== 'none')+ throw new Error('--compression must be meshopt or none');+ if (compression !== undefined && target !== 'three')+ throw new Error('--compression requires --target three');const format = flags.format ?? (profile === 'runtime' ? 'glb' : 'bundle');if (!['bundle', 'glb', 'source'].includes(format)) throw new Error('Unknown export format');const written: { kind: string; path: string; data: Uint8Array }[] = [];@@ -393,6 +401,7 @@ export async function assetMain(argv: readonly string[]): Promise<number> {profile,metadataFileName,...(target ? { target } : {}),+ ...(compression ? { compression } : {}),});if (output.profile !== 'runtime') throw new Error('Expected runtime export');const metadataPath = resolve(dirname(destination), output.metadata.name);@@ -425,6 +434,7 @@ export async function assetMain(argv: readonly string[]): Promise<number> {revisionId,profile,...(target ? { target } : {}),+ ...(compression ? { compression } : {}),format,...(format !== 'source'? {diff --git a/src/asset-export.ts b/src/asset-export.tsindex a0982217..81628a73 100644--- a/src/asset-export.ts+++ b/src/asset-export.ts@@ -122,6 +122,8 @@ export async function exportAssetGlb(throw new Error('Unknown runtime export target');if (options.target !== undefined && profile !== 'runtime')throw new Error('A runtime export target requires the runtime profile');+ if (options.compression !== undefined && options.target !== 'three')+ throw new Error('Runtime compression requires the three runtime target');validateRecordShape(record);const bytes = record.files['asset.glb']!;if (profile === 'editable') return { profile, glb: bytes };@@ -177,6 +179,7 @@ export async function exportAssetGlb(if (options.target === 'three') {const derived = await deliverThreeRuntimeGlb(writeGlbJson(bytes, jsonEnd, json), {...(options.ktx2Encoder ? { ktx2Encoder: options.ktx2Encoder } : {}),+ ...(options.compression ? { compression: options.compression } : {}),});metadata.target = 'three';metadata.delivery = derived.delivery;diff --git a/src/runtime-three.ts b/src/runtime-three.tsindex 2e670b16..6c84846d 100644--- a/src/runtime-three.ts+++ b/src/runtime-three.ts@@ -65,7 +65,14 @@ export interface RuntimeThreeOptionsV1 {* none; without one, textures stay PNG/JPEG and the report says `skipped`.*/ktx2Encoder?: (input: RuntimeThreeKtx2InputV1) => Promise<Uint8Array>;+ /**+ * Buffer compression. `meshopt` (default) requires `EXT_meshopt_compression` and a+ * Meshopt decoder in the loader. `none` writes plain buffers for loaders without one;+ * quantization, instancing and every preserved feature stay.+ */+ compression?: RuntimeThreeCompression;}+export type RuntimeThreeCompression = 'meshopt' | 'none';export interface RuntimeThreeNodeScaleV1 {/** Delivery path of the node whose matrix now carries the dequantization. */node: string;@@ -83,7 +90,7 @@ export interface RuntimeThreeDeliveryV1 {target: 'three';extensionsUsed: string[];extensionsRequired: string[];- compression: { extension: 'EXT_meshopt_compression'; method: 'quantize' };+ compression: { extension: 'EXT_meshopt_compression'; method: 'quantize' } | { extension: 'none' };quantization: {extension: 'KHR_mesh_quantization';volume: 'mesh';@@ -301,6 +308,9 @@ export async function deliverRuntimeThreeGlb(meshoptEncoder: unknown,options: RuntimeThreeOptionsV1 = {},): Promise<{ glb: Uint8Array; delivery: RuntimeThreeDeliveryV1 }> {+ const compression = options.compression ?? 'meshopt';+ if (compression !== 'meshopt' && compression !== 'none')+ throw new Error('Runtime three compression must be meshopt or none');const io = createGltfIO().registerDependencies({'meshopt.encoder': meshoptEncoder,});@@ -328,10 +338,11 @@ export async function deliverRuntimeThreeGlb(quantizeWeight: RUNTIME_THREE_QUANTIZATION.weight,}),);- doc- .createExtension(EXTMeshoptCompression)- .setRequired(true)- .setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });+ if (compression === 'meshopt')+ doc+ .createExtension(EXTMeshoptCompression)+ .setRequired(true)+ .setEncoderOptions({ method: EXTMeshoptCompression.EncoderMethod.QUANTIZE });const ktx2 = await encodeKtx2(doc, options.ktx2Encoder);// The quantizer moves a mesh to a new unnamed child when its node has children or is@@ -396,7 +407,10 @@ export async function deliverRuntimeThreeGlb(target: 'three',extensionsUsed: [...(json.extensionsUsed ?? [])].sort(),extensionsRequired: [...(json.extensionsRequired ?? [])].sort(),- compression: { extension: 'EXT_meshopt_compression', method: 'quantize' },+ compression:+ compression === 'meshopt'+ ? { extension: 'EXT_meshopt_compression', method: 'quantize' }+ : { extension: 'none' },quantization: {extension: 'KHR_mesh_quantization',volume: 'mesh',