libigl icon indicating copy to clipboard operation
libigl copied to clipboard

Interest in cross compiling to webassembly

Open bwrsandman opened this issue 5 years ago • 6 comments

I'm very interested in using libigl for interactive simulations and posting them online. Supporting webassembly and webgl through emscripten could make any application linking against this library more accessible.

I've created a branch which can do this with minimal changes. A few #ifdef, extracting the main loop, disabling comiso and embree, disabling popen and disabling wireframe mode.

If there is interest in this, I can contribute my changes as a few PRs.

This is my branch: https://github.com/bwrsandman/libigl/tree/emscripten

Here is the webassembly interactive draw mesh tutorial: https://bwrsandman.github.io/libigl

Screenshot from 2020-02-09 20-22-58

bwrsandman avatar Feb 09 '20 19:02 bwrsandman

That is really cool. We've considered working on a emscripten version a while back (in fact I had a branch myself enabling this), but we never had time to polish it out. Now our new python bindings come with a WebGL viewer as well, so we don't have a strong incentive to work on an emscripten port.

That being said if the changes are minimal I'd be interested in seeing a PR with the list of changes. Not sure if we'd be able to merge them, but I can at least take a look. You'd need to base it off of the dev branch though, since master is now a bit old.

jdumas avatar Feb 09 '20 19:02 jdumas

I rebased to dev. It get compile errors in eigen which I didn't have before. Not sure if its already known.

libigl/include/igl/arap_rhs.h:38:12: error: no template named 'SparseCompressedBase' in namespace 'Eigen'
    Eigen::SparseCompressedBase<DerivedK>& K);
    ~~~~~~~^
libigl/include/igl/arap_dof.cpp:227:3: error: no matching function for call to 'arap_rhs'
  arap_rhs(V,F,V.cols(),data.energy,K);

Here are the changes from dev. https://github.com/libigl/libigl/compare/dev...bwrsandman:emscripten-dev

bwrsandman avatar Feb 09 '20 20:02 bwrsandman

Hi @bwrsandman the version of Eigen used in masterand dev differs. Set the cmake variable LIBIGL_EIGEN_VERSION to 3.3.7 should do the trick.

BruegelN avatar Feb 09 '20 20:02 BruegelN

Thanks. That seems to have fixed it. Is there an option to not use SIMD as webassembly simd is a bit different from emmintrin.h?

bwrsandman avatar Feb 09 '20 21:02 bwrsandman

I forked libigl and have an inline/header-only build in event-horizon-webassembly that builds to desktop and the web with a "dear imgui" menu and the bunny mesh.

set "USE_EMSCRIPTEN = 1" in the makefile for a web build, "USE_EMSCRIPTEN = 0" for a desktop build

It's loosely based on sketchpunk/FunWithWebGL2 I hit a wall getting barycentric wireframe creation - something to do with the number of columns = 4. The shader implementations expect a "w" vertex paramater as well as x,y,z to do it's thing, but I've no idea how to proceed. I hit an eigen assert that I don't understand.

set "USE_BARYCENTRIC = 1" in the makefile for a barycentric wireframe build, "USE_BARYCENTRIC = 0" otherwise

Philius avatar Jan 12 '21 15:01 Philius

bunny I got it working ! Now if somwone who understands uniforms in WebGL can step in to wire up the face and edge colours, no backface culling, probably more that I missed, your feedback is welcome!

Philius avatar Jan 13 '21 15:01 Philius