kovacsv / occt-import-js

The emscripten interface for OpenCascade import functionalities.
GNU Lesser General Public License v2.1
141 stars 23 forks source link

import iges #22

Closed qyc010702 closed 1 year ago

qyc010702 commented 1 year ago

LinkError: WebAssembly.instantiate(): Import #390 module="a" function="ng" error: function import requires a callable When I use occt-import-js to import an igs file, I met this error, could you please give me some help?

 let fs = require ('fs');
const occtimportjs = require ('occt-import-js')();

occtimportjs.then ((occt) => {
    let fileContent = fs.readFileSync (fileUrl);
    let result = occt.ReadIgesFile (fileContent, null);
    console.log (result);
});
123Wampir commented 1 year ago

Possibly wrong path to wasm. You can try changing it like this:

let occtimportjs = require("occt-import-js.js");
occt: any = undefined;
/*If you are using a local server, for example five-server, you should specify the path to wasm through it: 
http://localhost:5050/myPath/occt-import-js/occt-import-js.wasm*/
wasmUrl = 'https://cdn.jsdelivr.net/npm/occt-import-js@0.0.15/dist/occt-import-js.wasm';
async InitOCCT() {
  console.log(this.occt);
  if (this.occt == undefined)
    this.occt = await occtimportjs({
      locateFile: (name: any) => {
        return this.wasmUrl;
      }
    })
}

After that you can load the model as in the example

await this.InitOCCT();
let response = await fetch(url);
let buffer = await response.arrayBuffer();
let fileBuffer = new Uint8Array(buffer);
let result = this.occt.ReadIgesFile(fileBuffer, null);