stillonearth / MuJoCo-WASM

Emscripten builds of MuJoCo
MIT License
17 stars 18 forks source link

Instructions steps to build libraries in `lib`? #1

Closed traversaro closed 1 year ago

traversaro commented 1 year ago

Hello @stillonearth, thanks a lot for great work! I was wondering if somewhere you have the instructions that you used to build the libraries in https://github.com/zalo/mujoco_wasm/tree/main/lib. Thanks a lot in advance!

stillonearth commented 1 year ago

I used emscripten to build wasm targets: https://emscripten.org/docs/compiling/Building-Projects.html

I didn't include recipe to reproduce the result, so some tinkering was required to make it work. As far as I can remember it require some monkey patching

traversaro commented 1 year ago

As far as I can remember it require some monkey patching

Yes, I was expecting that, that is why I asked if by chance you something of those patches still around. Anyhow, thanks a lot for the info.

stillonearth commented 1 year ago

I demonstrated that MuJoCo simulations are possible in a browser using a proof of concept. While developing Rust Mujoco bindings and a Bevy plugin, I aimed to target wasm for my Rust project. However, the Rust wasm target and the emscripten wasm target were incompatible. To work around this, I used a separate wasm runtime to communicate with the Rust renderer. Currently, one can compile simulate.c with emscripten to have Mujoco running in a browser. What is your specific use case for this technology?

saran-t commented 1 year ago

@stillonearth Can you elaborate on the compilation of simulate? I'm surprised that this can work given that we're using legacy OpenGL rather than OpenGL ES 2.

stillonearth commented 1 year ago

@saran-t I may be mistaken but there's limited support for legacy opengl in emscripten https://emscripten.org/docs/porting/multimedia_and_graphics/OpenGL-support.html#opengl-support-legacy-and-mobile

Here's emscripten headers for glfw https://github.com/emscripten-core/emscripten/blob/main/system/include/GL/glfw.h

saran-t commented 1 year ago

This is new and exciting, I'm reasonably sure last time I looked this wasn't a thing :)

Do you have a screenshot/video capture of what it looks like when simulate is running in the browser?

traversaro commented 1 year ago

What is your specific use case for this technology?

I work in a research instution, so long term it would be cool to have demos like https://kevinzakka.github.io/robopianist-demo/ . However, tipically our demos have several non-trivial C++ dependencies, a bit like the one of mujoco that you have in https://github.com/stillonearth/MuJoCo-WASM/tree/main/lib . That is why I was curious if there was some script ready to use to compile more libraries and put them in https://github.com/stillonearth/MuJoCo-WASM/tree/main/lib, but if the process was done manually I completely get why there is no such script.

stillonearth commented 1 year ago

@saran-t no, in fact I didn't compile simulate.c, but I was under impression that it's doable @traversaro I could try to make a CI script for MuJoCo to reproduce the binaries early next week.

stillonearth commented 1 year ago

Here's a MuJoCo commit enabeling WASM build: https://github.com/deepmind/mujoco/compare/main...stillonearth:mujoco:main

Here's instruction to reproduce results:

  1. Apply @traversaro PR from 2020 for libccd: https://github.com/danfis/libccd/pull/70
  2. Disable MUJOCO_BUILD_EXAMPLES, MUJOCO_BUILD_SIMULATE, MUJOCO_BUILD_TESTS build targets
  3. Remove warning option -Wno-int-in-bool-context as incompatible with emscripten (I'm still unsure why)
  4. Remove static check in src/engine/engine_collision_driver.c
  5. Add a qsort implementation that will satisfy emscripten https://github.com/deepmind/mujoco/compare/main...stillonearth:mujoco:main#diff-5ae9fa0fdfa5ae7f0eece63a8d575b39b05f441f22329f29391efefeb0374bdfR43
  6. Disable lodepng and ability to load PNG textures https://github.com/deepmind/mujoco/compare/main...stillonearth:mujoco:main#diff-b2f485c04e8d05263f6dd913ffc1e1f120af813240a61d302ebf98d9ebd857e5R2062
traversaro commented 1 year ago

Thanks @stillonearth !

Apply @traversaro PR from 2022 for libccd: https://github.com/danfis/libccd/pull/70

Cool, I had completely forgot that PR. :D