How to use MeshWriter in Node using import?

Does anyone have an example of how to import MeshWriter in node? I am importing BABLYON and Earcut like so…

  import * as BABYLON from 'babylonjs'
  import * as Earcut from 'earcut'

I was able to create an Polygon correctly with the following line by passing Earcut as the last parameter.

let polygon = BABYLON.MeshBuilder.ExtrudePolygon("Polygon", {shape:shape, holes:holes, depth: 0.1, sideOrientation: BABYLON.Mesh.DOUBLESIDE }, scene, Earcut)

But, I am not sure how to import MeshWriter and use that correctly. Does anyone have an example? I have been reading over these pages but still can’t seem to figure it out.

Pinging @theleftover

Technically as it is a pure JS library, I would recommend something like:

var meshWriter = require('path to the module')

If you have loaded it through NPM, then, if you do: “require(“meshwriter”)” will put it in global.MeshWriter. This is almost at the bottom of the readme in github. (Sadly the readme in NPM is one revision back and does not say this.)

If MeshWriter can find BABYLON in the global address space it, will also attach itself to BABYLON.MeshWriter. This approach had been my main target and should work in all environments and with all loading tools.

I did not test the syntax and result using ‘import’. I should. I will.

If you have further problems, you can find me on this channel.

If you feel like giving back, you can give me a critique of the section “Loading MeshWriter” on GitHub. I am sure it can be improved.