Skip to content

Commit

Permalink
Add meshopt support to glTF utility classes
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Oct 18, 2023
1 parent be7620c commit 2f42c00
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"draco3dgltf": "^1.5.6",
"gltf-pipeline": "^4.1.0",
"gltfpack": "^0.19.1",
"meshoptimizer": "^0.19.0",
"minimist": "^1.2.7",
"node-stream-zip": "^1.15.0",
"pino": "^8.15.0",
Expand Down
24 changes: 24 additions & 0 deletions specs/contentProcessing/GltfTransformSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from "fs";

import { GltfTransform } from "../../src/contentProcessing/GltfTransform";

describe("GltfTransform::getIO", function () {
it("can read a GLB without compression", async function () {
const glb = fs.readFileSync("./specs/data/gltf/Box.glb");
const io = await GltfTransform.getIO();
const document = await io.readBinary(glb);
expect(document).toBeDefined();
});
it("can read a GLB with Draco compression", async function () {
const glb = fs.readFileSync("./specs/data/gltf/BoxDraco.glb");
const io = await GltfTransform.getIO();
const document = await io.readBinary(glb);
expect(document).toBeDefined();
});
it("can read a GLB with meshopt compression", async function () {
const glb = fs.readFileSync("./specs/data/gltf/BoxMeshopt.glb");
const io = await GltfTransform.getIO();
const document = await io.readBinary(glb);
expect(document).toBeDefined();
});
});
Binary file added specs/data/gltf/Box.glb
Binary file not shown.
Binary file added specs/data/gltf/BoxDraco.glb
Binary file not shown.
Binary file added specs/data/gltf/BoxMeshopt.glb
Binary file not shown.
7 changes: 7 additions & 0 deletions specs/data/gltf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The "Box" glTF sample model, for testing the functionality
of reading GLB data with compression extensions.

- Box.glb is the model from https://github.com/KhronosGroup/glTF-Sample-Models/blob/4ca06672ce15d6a27bfb5cf14459bc52fd9044d1/2.0/Box/
- BoxDraco.glb is the same model with Draco compression
- BoxMeshopt is the same model with meshopt compression

9 changes: 8 additions & 1 deletion src/contentProcessing/GltfTransform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import draco3d from "draco3d";

import { MeshoptDecoder } from "meshoptimizer";
import { MeshoptEncoder } from "meshoptimizer";

import { Transform } from "@gltf-transform/core";
import { NodeIO } from "@gltf-transform/core";

import { ALL_EXTENSIONS } from "@gltf-transform/extensions";

import { EXTStructuralMetadata } from "../gltfExtensions/EXTStructuralMetadata";
Expand All @@ -26,7 +30,8 @@ export class GltfTransform {
*
* (E.g. it will be configured to handle the all extensions that
* are known in glTF-Transform, as well as EXT_mesh_features and
* EXT_structural_metadata, and have a draco encoder/decoder)
* EXT_structural_metadata, and have draco- and meshopt
* encoders/decoders)
*
* @returns - The `NodeIO` instance
*/
Expand All @@ -38,6 +43,8 @@ export class GltfTransform {
io.registerExtensions(ALL_EXTENSIONS).registerDependencies({
"draco3d.decoder": await draco3d.createDecoderModule(),
"draco3d.encoder": await draco3d.createEncoderModule(),
"meshopt.decoder": MeshoptDecoder,
"meshopt.encoder": MeshoptEncoder,
});
// Note: The order of these calls matters. The EXTMeshFeatures and
// EXTInstanceFeatures depend on the EXTStructuralMetadata, because
Expand Down

0 comments on commit 2f42c00

Please sign in to comment.