Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjzhao committed Aug 14, 2024
0 parents commit 2410ba9
Show file tree
Hide file tree
Showing 93 changed files with 496,665 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build mujoco_wasm

on:
pull_request:
push:

jobs:
Build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: mymindstorm/setup-emsdk@v11

- name: Verify Emscripten is Installed
run: emcc -v

- name: Linux - Build Base Binary
if: runner.os == 'Linux'
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
80 changes: 80 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Compiled Object files
**/.DS_Store
*.slo
*.lo
*.o
*.pyc

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

**/cmake-build-debug
**/CMakeCache.txt
**/cmake_install.cmake
**/install_manifest.txt
**/CMakeFiles/
**/CTestTestfile.cmake
**/Makefile
**/*.cbp
**/CMakeScripts
**/compile_commands.json

include/divisible/*


## Local

.idea/*.xml

build/**/*

include/*
lib/*
bin/*
test/test_runner
.vscode
.cache
.fiveserverrc

# Dependency directories
node_modules/**/*
jspm_packages/

# Three.js Build
!node_modules/three/
!node_modules/three/*/
!node_modules/three/build/*
# Three.js Controls
!node_modules/three/examples/*/
!node_modules/three/examples/jsm/
!node_modules/three/examples/jsm/*/
!node_modules/three/examples/jsm/controls/
!node_modules/three/examples/jsm/controls/OrbitControls.js
!node_modules/three/examples/jsm/controls/DragControls.js
!node_modules/three/examples/jsm/libs/
!node_modules/three/examples/jsm/libs/lil-gui.module.min.js
#!node_modules/three/examples/jsm/utils/
#!node_modules/three/examples/jsm/utils/*
#!node_modules/three/examples/jsm/loaders/
#!node_modules/three/examples/jsm/loaders/*
Empty file added .nojekyll
Empty file.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.2)
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_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)

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

add_subdirectory(src)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Konstantin Gredeskoul

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<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>

## The Power of MuJoCo in your Browser.

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/)

## Building

**1. Install emscripten**

**2. Build the mujoco_wasm Binary**

On Linux, use:
```bash
mkdir build
cd build
emcmake cmake ..
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
import load_mujoco from "./mujoco_wasm.js";

// Load the MuJoCo Module
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());

// Load in the state from XML
let model = new mujoco.Model("/working/humanoid.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.
12 changes: 12 additions & 0 deletions build_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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 ..
call emmake make
cd ../dist
pause
Loading

0 comments on commit 2410ba9

Please sign in to comment.