google / draco

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
https://google.github.io/draco/
Apache License 2.0
6.49k stars 963 forks source link

wasm path is not correct in electron environment #740

Open mankeheaven opened 3 years ago

mankeheaven commented 3 years ago

When use draco in my electron app, It fetch http://draco_encoder.wasm/

It's ok when I use it in my react useMount hooks, I can get table.wasm with code It fetch http://localhost:8238/table.wasm

  useMount(()=>{
    var otherTable = new WebAssembly.Table({ element: "anyfunc", initial: 2 });

      WebAssembly.instantiateStreaming(fetch('table.wasm',{credentials:"same-origin"}))
      .then(obj => {
        var tbl = obj.instance.exports.tbl as any;
        console.log(tbl.get(0)());  // 13
        console.log(tbl.get(1)());  // 42

        otherTable.set(0,tbl.get(0));
        otherTable.set(1,tbl.get(1));

        console.log(otherTable.get(0)());
        console.log(otherTable.get(1)());
      });
  })

But when I use gltf-pipeline, it depences on your draco, and ,it fetch http://draco_encoder.wasm/ And error is no such file or directory, open '\draco_encoder.wasm'

image

how does draco change the base url?

mankeheaven commented 3 years ago

I have seen the code in draco_decoder.js, I have no idea how to fix it, can you give me a help? 4JWMCF~CE%R50Z85P(`BEAA

mankeheaven commented 3 years ago

maybe the environment with electron renderer is wrong electron renderer has ENVIRONMENT_IS_NODE and ENVIRONMENT_IS_WEB

image

mankeheaven commented 3 years ago

I've solved this problem

I put the draco code in my electron main process, cause the renderer process has web environment and node environment

But I think your interface should provider a enviroment env to help those environment to define it by their own