VTK C++ Emscripten Binding Config
I want to create a VTK
C++ Emscripten wasm file because vtk.js
is missing in its unstructured data handling capabilities.
I follow the README.md
of Example WrappedMace to create an Emscipten wasm file, and it's ok to build this example and get js and wasm file. But when i want to include more C++
module to Javascript
like
#include "vtkUnstructuredGridReader.h"
vtkAddDestructor(vtkUnstructuredGridReader);
then I need to EMSCRIPTEN_BINDINGS
some function to export for js use. Something like this code
// vtkActor ---------------------------------------------------------
emscripten::class_<vtkActor, emscripten::base<vtkProp>>("vtkActor")
.constructor(&vtkActor::New, emscripten::allow_raw_pointers())
.function("SetMapper", &vtkActor::SetMapper, emscripten::allow_raw_pointers());
// vtkAlgorithm -----------------------------------------------------
emscripten::class_<vtkAlgorithm>("vtkAlgorithm")
.function("GetOutputPort",
emscripten::select_overload<vtkAlgorithmOutput*(vtkAlgorithm&)>(
[](vtkAlgorithm& self) { return self.vtkAlgorithm::GetOutputPort(); }),
emscripten::allow_raw_pointers())
.function("SetInputConnection",
emscripten::select_overload<void(vtkAlgorithm&, vtkAlgorithmOutput*)>(
[](vtkAlgorithm& self, vtkAlgorithmOutput* ptr) {
self.vtkAlgorithm::SetInputConnection(ptr);
}),
emscripten::allow_raw_pointers());
But this conversion from C++ functions to JS functions is very difficult for me as a front-end engineer because I am not familiar with C++ language.
I have used another project called Opencascade.js whose function is to convert Opencascade C++ to opencascade.js also using the Emscriten method. But they have a much easier tutorial that allows people who are not familiar with C++ to quickly customize the C++ part of the functions introduced by customizing a yaml file.
See this pyton file Binding, they automatic binding all function of a module.
Maybe you could develop a similar project that would make it easier to compile wasm files. Thanks.