3D engine that AI agents drive
Compress the port showcase geometry with meshopt (part of #435)
Nguyen Xuan An0ebe5cf71288
diff --git a/public/showcase/port/scene.glb b/public/showcase/port/scene.glbindex 3d6a5275..1959f216 100644Binary files a/public/showcase/port/scene.glb and b/public/showcase/port/scene.glb differdiff --git a/src/showcase.js b/src/showcase.jsindex fb396ebf..983e8db9 100644--- a/src/showcase.js+++ b/src/showcase.js@@ -228,6 +228,12 @@ async function downloadWithProgress(url, onProgress) {return new Blob(chunks, { type: 'model/gltf-binary' });}+// Showcase GLBs may use EXT_meshopt_compression; the decoder is a small chunk fetched beside the model download.+async function loadDecoders() {+ const { MeshoptDecoder } = await import('three/addons/libs/meshopt_decoder.module.js');+ return { meshopt: MeshoptDecoder };+}+function showCredits(credits = []) {creditList.replaceChildren(...credits.map(credit => {const item = document.createElement('li');@@ -257,7 +263,7 @@ async function selectScene(id) {downloadWithProgress(glbUrl.href, fraction => { if (request === loadingRequest) showProgress(id, fraction); }),loadHdri(description.hdri, description.hdriOptions ?? {}),]);- const asset = await loadGltf(model, { baseUrl: new URL('.', glbUrl).href, ...(description.gltfOptions ?? {}) });+ const asset = await loadGltf(model, { baseUrl: new URL('.', glbUrl).href, decoders, ...(description.gltfOptions ?? {}) });if (request !== loadingRequest) return;renderer?.dispose();const rendererOptions = description.renderer ?? {};diff --git a/tests/showcase-port-weight.test.js b/tests/showcase-port-weight.test.jsnew file mode 100644index 00000000..fcdb6d18--- /dev/null+++ b/tests/showcase-port-weight.test.js@@ -0,0 +1,25 @@+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import test from 'node:test';++const PORT_GLB = new URL('../public/showcase/port/scene.glb', import.meta.url);+const SHOWCASE_SOURCE = new URL('../src/showcase.js', import.meta.url);+const PORT_BYTE_BUDGET = 16 * 1024 * 1024;++function readGltfJson(buffer) {+ const jsonLength = buffer.readUInt32LE(12);+ return JSON.parse(buffer.subarray(20, 20 + jsonLength).toString('utf8'));+}++test('the port showcase GLB keeps its vertex data meshopt-compressed', async () => {+ const buffer = await readFile(PORT_GLB);+ const document = readGltfJson(buffer);+ assert.ok(document.extensionsRequired.includes('EXT_meshopt_compression'));+ assert.ok(buffer.length < PORT_BYTE_BUDGET, `port scene.glb is ${buffer.length} bytes, budget ${PORT_BYTE_BUDGET}`);+});++test('the showcase page supplies the meshopt decoder to the glTF loader', async () => {+ const source = await readFile(SHOWCASE_SOURCE, 'utf8');+ assert.match(source, /meshopt_decoder\.module\.js/);+ assert.match(source, /decoders/);+});