After using gltf-transform to compress the model, do we have to do this?

I used the gltf-transform plugin to optimize the model, and the command was:

gltf-transform optimize car.glb car_1.glb --compress meshopt --texture-compress webp --texture-size 512

It works fine on a computer, but when embedded in ios as a webview, it gets an error.
the error: “error:https://cdn.babylonjs.com/meshopt_decoder.js

I learned that with the meshopt algorithm, bjs has to load the plugin, so I added this code!!!

 const engine = new Engine(canvas, antialias, engineOptons, adaptToDeviceRatio);

    MeshoptCompression.Configuration = {
      decoder: {
        //  default is the CDN path, I changed it and  use my local files
        url: "javascripts/meshopt_decoder.js"  // the path of my local file
      }
    };
    const scene = new Scene(engine, sceneOptions);

There don’t seem to be too many examples of meshopt, should I do this?
Or is there a better compression than meshopt to optimize the model on the mobile ?

thank you.!!!

This should work, not sure why it would not change the url.

cc @RaananW and @bghgary

This sounds like a WebView problem. I don’t have much experience with using WebView on iOS, but from a quick look at documentation, it really depends on how you loaded the page. For example, if call loadHTMLString, there is a baseURL parameter that determines where the local files are loaded from. If you call loadFileURL, there is an allowingReadAccessTo parameter. How are you loading your WebView?

But I’m sure that if I didn’t optimize the model with gltf-transform, there would be no errors on ios

Right, optimizing with meshopt requires the loader to load the meshopt extension which must load the meshopt library from separate js/wasm files. If you don’t optimize with meshopt or draco then you don’t need the separate files.

After testing and comparison, we found that the optimization result of meshopt is very good. Of course, I do not want to load additional plugins, because I think loading plugins on the mobile terminal will always affect the performance or loading speed. Is there any other better optimization scheme?

And I also learned that android loading external files seems to be not allowed, like this loading external js files, will there be a problem.

From your message I can’t seem to understand if it worked once you used the local file instead of the CDN. Does it work locally? (And sorry if I missed something!)

It depends on what you are doing with the model. A lot of times, simply doing quantization makes a big difference. Quantization does not require additional libraries. Meshopt or Draco will compress more but it may not give a huge difference.

1 Like

Yes, there is an error when using the CDN in the app

So it does work locally - a perfect solution TBH.

would be very interesting to understand why the CDN file didn’t work. I believe @bghgary discussed that in his first answer.