Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instructions for running in Node.js? #9

Open
gkjohnson opened this issue Sep 21, 2024 · 3 comments · May be fixed by #12
Open

Instructions for running in Node.js? #9

gkjohnson opened this issue Sep 21, 2024 · 3 comments · May be fixed by #12

Comments

@gkjohnson
Copy link
Contributor

gkjohnson commented Sep 21, 2024

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

@gkjohnson
Copy link
Contributor Author

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.

@repalash
Copy link
Owner

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.

@gkjohnson
Copy link
Contributor Author

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.

@gkjohnson gkjohnson linked a pull request Oct 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants