-
Notifications
You must be signed in to change notification settings - Fork 96
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
Feature request: JS interface + WASM module #73
Comments
Here here! Contributions welcome! |
Compile directly into wasm interface and publish npm package |
Agreed; would you like to give it a shot? |
@pca006132 Now that you got the emscripten build working for the tests, do you know how to make a build that's callable as a library? I'd love to make an example of calling this WASM blob from a simple three.js project, a la #75. Probably best to skip |
I am not familiar with emscripten, but it seems that you have to export the symbols as C symbols to avoid name mangling and use their tool to generate the binding: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-binding-cpp |
I'm having a look at this, but it seems that the API exposed to JS will not be very convenient to use as you will need to call delete everywhere: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management , or you will leak memory pretty quickly. Writing the entire thing in C++ and compile to WASM is already possible for now. |
OK it seems that three.js also require calling dispose explicitly, so this should not be a problem. Wondering if it will be better to just create a C FFI, so binding to other languages will be easier (if we want to do that in the future). |
three.js requires |
perhaps this comment should have been made here. TL;DR right now emmake produces a bunch of .a files that can be put through embind if someone writes that edit: sorry, cpp file not js file, the one with EMSCRIPTEN_BINDINGS |
Indeed the structure looks like the one in pybind11. I guess we should do something similar to https://github.com/elalish/manifold/blob/master/tools/pymanifold.cpp |
Agreed, but let's leave out |
@makc Would you be interested in making these changes? I see now you're a user of this, which puts you in a good position to test it and ensure ergonomics are good. I totally agree about wanting our WASM to be independent of other libraries like three.js, and without bloat like assimp and gtest. I'd also like to separately build a bit of JS to connect that WASM to three.js, but just as an example. |
unfortunately I am total noob when it comes to c++ tools like cmake 😅 for example, for my build I have manually removed CMakeLists sections related to assimp and gtest, when ideally they would be made conditional on EMSCRIPTEN - and I just did not know how to do it. |
what I could try to do is to create bindings file stub and make sure the whole process works, but then someone else would need to properly add this to the project. |
That sounds great, we can help! Honestly we're all noobs at CMake too, but we're working through it together. |
Yes we are all noobs at CMake, I wasn't using CMake (modifying CMake files) before this project. I can help to review the changes and clean it up if needed. Sorry I am a bit busy recently so at best I can only do review and some tiny changes. |
(I will just mention #151 to ping who ever was subscribed to this) |
Yeah, I suppose we could close this, but maybe better to leave it till we have the whole API exposed in WASM. |
I plan to improve the js example by:
Any other thoughts? |
@pca006132 Spectacular! This is exactly where I was hoping to go next with the project. I actually like the simplicity of the existing example, so let's build this JS editor separately from that. I'm planning to make another slightly more complicated example that shows how multi-material objects can be handled with three.js as well. Those will serve better as examples for others that want to integrate this library. I'll make us a landing page that links to all of them. Regarding orbit controls, for our JS editor I'd actually like to integrate with Do you have any ideas for a good library to handle the live code editing? Ideally we'd want syntax highlighting and other goodies and we shouldn't reinvent the wheel. Things like JSbin and StackBlitz must use some underlying libraries that would be good for this. We might also want to think about TS types for our WASM binding. |
So For code editing, I think the most popular option is code mirror. I'm not sure if we can have decent autocomplete with it though. Another option would be monaco which is the editor powering vscode, even though it says that it doesn't support mobile browsers, it seems pretty usable on my android tablet. |
Looking at codemirror and monaco, I'm leaning toward codemirror. It looks like they do have autocompletion, though I'm not sure how much work is needed beyond their example. I also saw this comparison, and I especially note the difference in bundle size, which is big for page performance. |
@pca006132 Do you have a sense of how you'd like to break up this work into manageable chunks? It might be good to file separate issues for these chunks so we can show dependencies and have a place to discuss each. I figure for now you can just copy the non-interactive three.js example to get started and once I've built #196 you can switch to that. Sound good? |
Yes, I can work on writing the API. |
Great. A page integrating codemirror would also be great as a first step; then we have a platform on which to incrementally add features and test them. |
This looks completed as of #224 🎉 |
This is a very interesting endeavor. Congratulations @elalish !
This is a wishlist item:
The text was updated successfully, but these errors were encountered: