Explore JavaScript wrappers for VTK through emscripten
VTK can produce binaries for the wasm32 architecture. In order for web-applications to actually make use of these binaries, they can follow 3 approaches listed in increasing order of difficulty:
- Write application logic in C++ using VTK C++. Key functionality is exposed via emscripten bindings that accept or return POD types or a container of those data types. This design is used in vtkWasmBenchmarks/Cones
- Wrap desirable VTK C++ API by hand and consume it in javascript. Ex: VTK/Examples/Emscripten/Cxx/WrappedMace
- Write webassembly instructions by hand along with javascript to parse the wasm binary and acquire the VTK class and function entry points. For small libraries with <100 functions, this is acceptable. For VTK, it's very tedious to follow this approach.
The purpose of this issue is to flesh out the process of autogenerated javascript wrappers for VTK through embind
- the binding component of emscripten
toolchain. Emscripten is widely used to bring C/C++ projects to JS like hdf5, opencascade, ffmpeg, google earth, autocad, Qt and many more, see Made with WebAssembly. All that needs to be done is a JavaScript front-end for the vtkParse
backend similar to vtkWrapJava
and vtkWrapPython
Alternatives to emscripten
Cheerp has built-in garbage collection of C++ objects due to a different memory model. Looks like it has commercial license and not as good of a community support like emscripten.
nbind uses emscripten. It has a different syntax from embind
. TypeScript definitions are auotmatically generated. However, it seems like nbind
is now inactive. See nbind vs embind for a discussion on the missing features in nbind
.
Cc: @cory.quammen @sebastien.jourdain @matt-mccormick @will.schroeder @jcfr