donmccurdy/glTF-Transform

Set maximum size exceeded

Closed this issue · 1 comments

async meshopt_compress(arrayBuffer: ArrayBuffer) {
    const before = performance.now();
    await MeshoptEncoder.ready;

    const io = new WebIO();
    io.registerExtensions(KHRONOS_EXTENSIONS);
    io.registerDependencies({
      'meshopt.encoder': MeshoptEncoder
    });

    const doc = await io.readBinary(new Uint8Array(arrayBuffer)); // read GLB from ArrayBuffer
    // we have to remove weld and simplify it will throw error with large model
    await doc.transform(
      weld({tolerance: 0.0001}),
      simplify({simplifier: MeshoptSimplifier, ratio: 0.75, error: 0.001}),
      reorder({encoder: MeshoptEncoder}),
      quantize(),
      sequence()
    );

    doc.createExtension(EXTMeshoptCompression).setRequired(true).setEncoderOptions({
      method: EXTMeshoptCompression.EncoderMethod.FILTER // or EXTMeshoptCompression.EncoderMethod.QUANTIZE
    });
    io.registerExtensions([EXTMeshoptCompression]); // read instanced meshes
    const compressedArrayBuffer = await io.writeBinary(doc);
    console.log(`Compression in ${(performance.now() - before) / 1000}s`);
    return compressedArrayBuffer;
  }
  • And then I got this error when I was trying to export a large model
    image

On the v4 alpha release, this has been fixed with a fast path for weld tolerance=0. I'd recommend tolerance=0 for most use cases starting with v4, where it will be the default.

To install the alpha release:

npm install --save @gltf-transform/core@next @gltf-transform/extensions@next @gltf-transform/functions@next

Also note the reorder, quantize, and meshopt steps can all be combined into one:

await doc.transform(
      weld(),
      simplify({simplifier: MeshoptSimplifier, ratio: 0.75, error: 0.001}),
      meshopt({encoder: MeshoptEncoder, level: 'high'}),
      sequence()
);

Then explicitly calling doc.createExtension(EXTMeshoptCompression) is not required.