repalash/xatlas-three

Instructions for running in Node.js?

gkjohnson opened this issue · 3 comments

I'm taking a look at what's required now but I figured I'd ask in case you already have a straight forward answer. It looks like it will require a special build that doesn't require Workers, at least.

edit: it seems like the no-worker build path isn't working, as well, unless I'm missing something

After creating and importing this no workers build it looks like a separate "node" build of xatlas js is needed (see the build script, emscripten Environment docs). I'm not set up for emscripten development but if a node js bundle was made available I could look into getting xatlas-three running in node. Otherwise I may look at puppeteer for the moment.

It required some changes in xatlas.js for node.js. I have tried those and now it seems to work.
I have published the build in version 0.2.0 on npm. The node build is in dist/node and is separate from web.

To use it directly, check the script - https://github.com/repalash/xatlas.js/blob/v2/source/test/test.mjs
This is using worker_threads with comlink node adapter. I followed this to get it working - https://gist.github.com/CatsMiaow/cc07796aee448b391970798d972302e0

For xatlas-three, the api wrapper had to be created with different imports and now we should be able to use it by just passing the path to the node worker and wasm file locally - https://github.com/repalash/xatlas-three/blob/master/test/node-worker.ts
This is in typescript, you can run it with npx tsx ./test/node-worker.ts. For javascript, the typescript files in src have to be bundled. I wasn't able to do it with webpack yet, will check it later.

So this runs, but I haven't done any testing to see if the outputs are correct or if there are any other bugs. Will have to write some proper tests to check if it's working.

Amazing! I'm using regular JS so I won't be able to easily test this for my use case until a JS entry point is added - but the simple solution would be to expose two entry points from the package.json. Eg one for "xatlas-three/web" and "xatlas-three/node" and just produce two separate bundles. Three.js is doing this for webgpu exports in the package.json.