Skip to content

Commit

Permalink
Use draco from gltf-transform (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir authored May 22, 2024
1 parent acd1070 commit d571bd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
3 changes: 2 additions & 1 deletion clis/draco-encoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
28 changes: 7 additions & 21 deletions clis/draco-encoder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
26 changes: 20 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d571bd6

Please sign in to comment.