Skip to content

Commit

Permalink
Update to MuJoCo 3.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanma committed Jan 17, 2025
1 parent 4759515 commit 968f873
Show file tree
Hide file tree
Showing 109 changed files with 1,240 additions and 496,419 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build mujoco_wasm
name: Build mujoco_wasm3

on:
pull_request:
Expand All @@ -16,20 +16,9 @@ jobs:
- name: Verify Emscripten is Installed
run: emcc -v

- name: Linux - Build Base Binary
if: runner.os == 'Linux'
- name: Compilation
run: |
mkdir build
cd build
emcmake cmake ..
make
- name: Linux - Upload Build
uses: actions/upload-artifact@v3
if: runner.os == 'Linux'
with:
name: mujoco_wasm
path: |
./README.md
./build
./dist
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.15)
option(JS_ONLY "Compiles to native JS (No WASM)" OFF)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/dist")

project(mujoco_wasm)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")

set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})

set(MUJOCO_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(MUJOCO_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin)
set(MUJOCO_INSTALL_LIB_DIR ${PROJECT_SOURCE_DIR}/lib)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include_directories(${MUJOCO_INSTALL_INCLUDE_DIR})
link_directories(${MUJOCO_INSTALL_LIB_DIR})
include(dependencies)


include_directories("${FETCHCONTENT_BASE_DIR}/mujoco-src/include")

add_subdirectory(src)
40 changes: 5 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
<p align="center">
<a href="https://zalo.github.io/mujoco_wasm/"><img src="./examples/MuJoCoWasmLogo.png" href></a>
</p>
<p align="left">
<a href="https://github.com/zalo/mujoco_wasm/deployments/activity_log?environment=github-pages">
<img src="https://img.shields.io/github/deployments/zalo/mujoco_wasm/github-pages?label=Github%20Pages%20Deployment" title="Github Pages Deployment"></a>
<!--<a href="https://github.com/zalo/mujoco_wasm/deployments/activity_log?environment=Production">
<img src="https://img.shields.io/github/deployments/zalo/mujoco_wasm/Production?label=Vercel%20Deployment" title="Vercel Deployment"></a> -->
<!--<a href="https://lgtm.com/projects/g/zalo/mujoco_wasm/context:javascript">
<img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/zalo/mujoco_wasm.svg?logo=lgtm&logoWidth=18"/></a> -->
<a href="https://github.com/zalo/mujoco_wasm/commits/main">
<img src="https://img.shields.io/github/last-commit/zalo/mujoco_wasm" title="Last Commit Date"></a>
<a href="https://github.com/zalo/mujoco_wasm/blob/main/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-brightgreen" title="License: MIT"></a>
</p>
## MuJoCo-wasm3

## The Power of MuJoCo in your Browser.
Load and Run MuJoCo 3.2.6 Models using JavaScript and WebAssembly.

Load and Run MuJoCo 2.3.1 Models using JavaScript and WebAssembly.

This repo is a fork of @stillonearth 's starter repository, adding tons of functionality and a comprehensive example scene.

### [See the Live Demo Here](https://zalo.github.io/mujoco_wasm/)

### [See a more Advanced Example Here](https://kzakka.com/robopianist/)
This repo is a fork of [@zalo 's repository](https://github.com/zalo/mujoco_wasm), updated to MuJoCo 3.2.6.

## Building

Expand All @@ -40,10 +20,6 @@ make

On Windows, run `build_windows.bat`.

*3. (Optional) Update MuJoCo libs*

Build MuJoCo libs with wasm target and place to lib. Currently v2.3.1 included.

## JavaScript API

```javascript
Expand All @@ -55,18 +31,12 @@ const mujoco = await load_mujoco();
// Set up Emscripten's Virtual File System
mujoco.FS.mkdir('/working');
mujoco.FS.mount(mujoco.MEMFS, { root: '.' }, '/working');
mujoco.FS.writeFile("/working/humanoid.xml", await (await fetch("./examples/scenes/humanoid.xml")).text());
mujoco.FS.writeFile("/working/scene.xml", await (await fetch("url/to/your/mujoco/scene.xml")).text());

// Load in the state from XML
let model = new mujoco.Model("/working/humanoid.xml");
let model = new mujoco.Model("/working/scene.xml");
let state = new mujoco.State(model);
let simulation = new mujoco.Simulation(model, state);
```

Typescript definitions are available.

## Work In Progress Disclaimer

So far, most mjModel and mjData state variables and functions (that do not require custom structs) are exposed.

At some point, I'd like to de-opinionate the binding and make it match the original MuJoCo API better.
4 changes: 3 additions & 1 deletion build_windows.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
rem This script requires that the Emscripten SDK has been set up in the directory above this one.
rem Follow the instructions here: https://emscripten.org/docs/getting_started/downloads.html

call python src/parse_mjxmacro.py
rmdir /s /q build
call ../emsdk/emsdk activate latest
mkdir build
cd build
call emcmake cmake ..
cd ..
call python src/parse_mjxmacro.py build/_deps/mujoco-src
cd build
call emmake make
cd ../dist
pause
38 changes: 38 additions & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
include(FetchContent)


#################################################
# libccd

set(ENABLE_DOUBLE_PRECISION ON)
set(CCD_HIDE_ALL_SYMBOLS ON)

set(LIBCCD_CMAKE_PATCH git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patches/libccd.patch)

# Fetch the repositories
FetchContent_Declare(
ccd
GIT_REPOSITORY https://github.com/danfis/libccd.git
GIT_TAG "7931e764a19ef6b21b443376c699bbc9c6d4fba8" # aka "v2.1"
PATCH_COMMAND ${LIBCCD_CMAKE_PATCH}
UPDATE_DISCONNECTED 1
)

FetchContent_MakeAvailable(ccd)


#################################################
# Mujoco

set(MUJOCO_CMAKE_PATCH git apply ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patches/mujoco.patch)

# Fetch the repositories
FetchContent_Declare(
mujoco
GIT_REPOSITORY https://github.com/google-deepmind/mujoco.git
GIT_TAG "0f64959e279e63b62a7610c23e0396c000f28c06" # aka "3.2.6"
PATCH_COMMAND ${MUJOCO_CMAKE_PATCH}
UPDATE_DISCONNECTED 1
)

FetchContent_MakeAvailable(mujoco)
42 changes: 42 additions & 0 deletions cmake/patches/libccd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35bf430..1a35bb8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.11)
+cmake_minimum_required(VERSION 3.15)

if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1407080..3ecb3f9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -39,7 +39,7 @@ set(CCD_SOURCES
support.h
vec3.c)

-add_library(ccd ${CCD_INCLUDES} ${CCD_SOURCES})
+add_library(ccd STATIC ${CCD_INCLUDES} ${CCD_SOURCES})
set_target_properties(ccd PROPERTIES
PUBLIC_HEADER "${CCD_INCLUDES}"
SOVERSION ${CCD_SOVERSION}
@@ -48,7 +48,7 @@ target_include_directories(ccd PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

-if(NOT WIN32)
+if(NOT WIN32 AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
find_library(LIBM_LIBRARY NAMES m)
if(NOT LIBM_LIBRARY)
message(FATAL_ERROR "Could NOT find required library LibM")
@@ -83,6 +83,6 @@ if(UNIX)
endif()
endif()

-if(NOT WIN32 AND BUILD_TESTING AND NOT CCD_HIDE_ALL_SYMBOLS)
- add_subdirectory(testsuites)
-endif()
+# if(NOT WIN32 AND BUILD_TESTING AND NOT CCD_HIDE_ALL_SYMBOLS)
+# add_subdirectory(testsuites)
+# endif()
Loading

0 comments on commit 968f873

Please sign in to comment.