I created a Babylon Scene that uses MeshWriter and this is all working fine when using the Javascript libraries. I then tried to move my scene to Typescript using WebPack. I installed both babylonJS and MeshWriter using npm. BabylonJS is working fine but when I include MeshWriter, I get the following error
bundleName.js:12196 Uncaught Error: Missing method ‘Mesh’
at _ (meshwriter.min.js:2)
at Object.eval (meshwriter.min.js:2)
at Object.eval (meshwriter.min.js:2)
at Object.eval (meshwriter.min.js:2)
at D (meshwriter.min.js:1)
at eval (meshwriter.min.js:1)
at eval (meshwriter.min.js:2)
at Object…/node_modules/meshwriter/dist/meshwriter.min.js (bundleName.js:11896)
at webpack_require (bundleName.js:12193)
at fn (bundleName.js:12404)
I have the following includes in my typescript file
import “@babylonjs/core/Debug/debugLayer”;
import “@babylonjs/inspector”;
import “@babylonjs/loaders/glTF”;
import “@babylonjs/gui”;
import * as BABYLON from “@babylonjs/core”;
import * as $ from ‘jquery’;
import * as MeshWriter from “meshwriter”;
@TheLeftover can answer that the best, as he is the one who wrote the MeshWriter, but from a quick glance at the code, it seems like it expects BABYLON to be in the global namespace.
RaananW, it used to require a global BABYLON object. However, if you check all the way down to the bottom of the READEME (GitHub - briantbutton/meshwriter: Babylon Mesh Writer) under “optimizing memory”, it describes a way to pass the methods into MeshWriter.
I can see that the documentation coulda been clearer on that point . . . wonder who wrote that?
I discovered that if I use the BabylonJS Editor and add MeshWriter into a scene, it is working although you don’t see the results in the editor itself. If you hit Run, you do see them
@TheLeftover , I finally managed to resolve the issue without the use of the BabylonJS Editor. The issue was because I had the MeshWriter import after the BabylonJs inspector import.
When I reversed this so that MeshWriter was before Inspector as below, the issue was resolved
import * as MeshWriter from “meshwriter”;
import “@babylonjs/inspector”;