From d571bd62e0a5ba79e1b7150ee4fd6c8f8e25073f Mon Sep 17 00:00:00 2001 From: Marcus Longmuir Date: Wed, 22 May 2024 15:18:44 +0100 Subject: [PATCH] Use draco from gltf-transform (#56) --- clis/draco-encoder/package.json | 3 ++- clis/draco-encoder/src/index.ts | 28 +++++++--------------------- package-lock.json | 26 ++++++++++++++++++++------ 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/clis/draco-encoder/package.json b/clis/draco-encoder/package.json index 2689ddc..00527ef 100644 --- a/clis/draco-encoder/package.json +++ b/clis/draco-encoder/package.json @@ -19,10 +19,11 @@ }, "dependencies": { "three": "0.163.0", + "@types/draco3dgltf": "1.4.3", + "draco3dgltf": "1.5.7", "@gltf-transform/core": "3.10.1", "@gltf-transform/extensions": "3.10.1", "@gltf-transform/functions": "3.10.1", - "meshoptimizer": "0.20.0", "gltf-avatar-export-lib": "file:../../packages/gltf-avatar-export-lib", "yargs": "17.7.2" }, diff --git a/clis/draco-encoder/src/index.ts b/clis/draco-encoder/src/index.ts index f0666ec..4c9535f 100644 --- a/clis/draco-encoder/src/index.ts +++ b/clis/draco-encoder/src/index.ts @@ -5,13 +5,9 @@ import fs from "fs"; import process from "process"; import { WebIO } from "@gltf-transform/core"; -import { - EXTMeshGPUInstancing, - EXTMeshoptCompression, - KHRONOS_EXTENSIONS, -} from "@gltf-transform/extensions"; -import { quantize, reorder } from "@gltf-transform/functions"; -import { MeshoptEncoder, MeshoptDecoder } from "meshoptimizer"; +import { ALL_EXTENSIONS } from "@gltf-transform/extensions"; +import { draco } from "@gltf-transform/functions"; +import draco3d from "draco3dgltf"; import yargs from "yargs/yargs"; const argv = yargs(process.argv) @@ -30,26 +26,16 @@ fs.readFile(argv.input, function (readFileErr, fileBuffer) { } (async () => { - await MeshoptEncoder.ready; - try { const io = new WebIO(); - - io.registerExtensions(KHRONOS_EXTENSIONS); - io.registerExtensions([EXTMeshGPUInstancing]); // read instanced meshes - io.registerExtensions([EXTMeshoptCompression]); - io.registerDependencies({ - "meshopt.encoder": MeshoptEncoder, - "meshopt.decoder": MeshoptDecoder, + io.registerExtensions(ALL_EXTENSIONS).registerDependencies({ + "draco3d.decoder": await draco3d.createDecoderModule(), // Optional. + "draco3d.encoder": await draco3d.createEncoderModule(), // Optional. }); const doc = await io.readBinary(new Uint8Array(fileBuffer.buffer)); // read GLB from ArrayBuffer - await doc.transform(reorder({ encoder: MeshoptEncoder }), quantize()); - - doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({ - method: EXTMeshoptCompression.EncoderMethod.QUANTIZE, - }); + await doc.transform(draco()); const compressedArrayBuffer = await io.writeBinary(doc); diff --git a/package-lock.json b/package-lock.json index 7230475..3237fe5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,8 +67,9 @@ "@gltf-transform/core": "3.10.1", "@gltf-transform/extensions": "3.10.1", "@gltf-transform/functions": "3.10.1", + "@types/draco3dgltf": "1.4.3", + "draco3dgltf": "1.5.7", "gltf-avatar-export-lib": "file:../../packages/gltf-avatar-export-lib", - "meshoptimizer": "0.20.0", "three": "0.163.0", "yargs": "17.7.2" }, @@ -4248,6 +4249,19 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/draco3d": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/@types/draco3d/-/draco3d-1.4.10.tgz", + "integrity": "sha512-AX22jp8Y7wwaBgAixaSvkoG4M/+PlAcm3Qs4OW8yT9DM4xUpWKeFhLueTAyZF39pviAdcDdeJoACapiAceqNcw==" + }, + "node_modules/@types/draco3dgltf": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@types/draco3dgltf/-/draco3dgltf-1.4.3.tgz", + "integrity": "sha512-JTY574f8xRI9+bOsDajeVSQ/gnIo0q3dt/MAJhNRKWJKdH2TAP3hld+lQ+eQnG9Eb6Ae493EiKi2oDZZpciQgw==", + "dependencies": { + "@types/draco3d": "*" + } + }, "node_modules/@types/graceful-fs": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", @@ -6781,6 +6795,11 @@ "node": ">=12" } }, + "node_modules/draco3dgltf": { + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/draco3dgltf/-/draco3dgltf-1.5.7.tgz", + "integrity": "sha512-LeqcpmoHIyYUi0z70/H3tMkGj8QhqVxq6FJGPjlzR24BNkQ6jyMheMvFKJBI0dzGZrEOUyQEmZ8axM1xRrbRiw==" + }, "node_modules/duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", @@ -12966,11 +12985,6 @@ "node": ">= 8" } }, - "node_modules/meshoptimizer": { - "version": "0.20.0", - "resolved": "https://registry.npmjs.org/meshoptimizer/-/meshoptimizer-0.20.0.tgz", - "integrity": "sha512-olcJ1q+YVnjroRJpCL1Dj5aZxr2JMr2hRutMUwhuHZvpAL7SIZgOT6eMlFF4TbBGSR89tawE/gqB79J/LrW/Nw==" - }, "node_modules/micromatch": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz",