Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to 2.3.3 #10

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

## The Power of MuJoCo in your Browser.

Load and Run MuJoCo 2.3.1 Models using JavaScript and WebAssembly.
MuJoCo built with emscripten for use in JavaScript and WebAssembly. This includes `MuJoCo v2.3.3` built as static library and a simple example application.

This repo is a fork of @stillonearth 's starter repository, adding tons of functionality and a comprehensive example scene.
This repo is a fork of @stillonearth 's emscripten compilation 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

**0. (Optional) Build MuJoCo libs with WASM targets**

This repo includes built MuJoCo libs for `v2.3.3`. If you want to build your own, follow the [instructions](https://github.com/stillonearth/MuJoCo-WASM/issues/1#issuecomment-1495814568).

**1. Install emscripten**

**2. Build the mujoco_wasm Binary**
Expand All @@ -42,7 +46,7 @@ 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.
Build MuJoCo libs with wasm target and place to lib. Currently v2.3.3 included.

## JavaScript API

Expand Down
206 changes: 126 additions & 80 deletions dist/mujoco_wasm.d.ts

Large diffs are not rendered by default.

377 changes: 192 additions & 185 deletions include/mujoco/mjdata.h

Large diffs are not rendered by default.

47 changes: 33 additions & 14 deletions include/mujoco/mjmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
#define mjNSOLVER 1000 // size of mjData.solver_XXX arrays


//---------------------------------- primitive types (mjt) -----------------------------------------

typedef unsigned char mjtByte; // used for true/false

//---------------------------------- enum types (mjt) ----------------------------------------------

typedef enum mjtDisableBit_ { // disable default feature bitflags
mjDSBL_CONSTRAINT = 1<<0, // entire constraint solver
Expand All @@ -59,8 +56,9 @@ typedef enum mjtDisableBit_ { // disable default feature bitflags
mjDSBL_ACTUATION = 1<<10, // apply actuation forces
mjDSBL_REFSAFE = 1<<11, // integrator safety: make ref[0]>=2*timestep
mjDSBL_SENSOR = 1<<12, // sensors
mjDSBL_MIDPHASE = 1<<13, // mid-phase collision filtering

mjNDISABLE = 13 // number of disable flags
mjNDISABLE = 14 // number of disable flags
} mjtDisableBit;


Expand Down Expand Up @@ -128,7 +126,8 @@ typedef enum mjtTexture_ { // type of texture
typedef enum mjtIntegrator_ { // integrator mode
mjINT_EULER = 0, // semi-implicit Euler
mjINT_RK4, // 4th-order Runge Kutta
mjINT_IMPLICIT // implicit in velocity
mjINT_IMPLICIT, // implicit in velocity
mjINT_IMPLICITFAST // implicit in velocity, no rne derivative
} mjtIntegrator;


Expand Down Expand Up @@ -362,7 +361,7 @@ struct mjLROpt_ { // options for mj_setLengthRange()
mjtNum timeconst; // time constant for velocity reduction; min 0.01
mjtNum timestep; // simulation timestep; 0: use mjOption.timestep
mjtNum inttotal; // total simulation time interval
mjtNum inteval; // evaluation time interval (at the end)
mjtNum interval; // evaluation time interval (at the end)
mjtNum tolrange; // convergence tolerance (relative to range)
};
typedef struct mjLROpt_ mjLROpt;
Expand All @@ -372,7 +371,7 @@ typedef struct mjLROpt_ mjLROpt;

struct mjVFS_ { // virtual file system for loading from memory
int nfile; // number of files present
char filename[mjMAXVFS][mjMAXVFSNAME]; // file name without path
char filename[mjMAXVFS][mjMAXVFSNAME]; // file name without path
int filesize[mjMAXVFS]; // file size in bytes
void* filedata[mjMAXVFS]; // buffer with file data
};
Expand Down Expand Up @@ -432,6 +431,7 @@ struct mjVisual_ { // visualization options
float realtime; // initial real-time factor (1: real time)
int offwidth; // width of offscreen buffer
int offheight; // height of offscreen buffer
int treedepth; // depth of the bounding volume hierarchy
} global;

struct { // rendering quality
Expand Down Expand Up @@ -535,14 +535,16 @@ struct mjModel_ {
int nu; // number of actuators/controls = dim(ctrl)
int na; // number of activation states = dim(act)
int nbody; // number of bodies
int nbvh; // number of total bounding volumes in all bodies
int njnt; // number of joints
int ngeom; // number of geoms
int nsite; // number of sites
int ncam; // number of cameras
int nlight; // number of lights
int nmesh; // number of meshes
int nmeshvert; // number of vertices in all meshes
int nmeshtexvert; // number of vertices with texcoords in all meshes
int nmeshnormal; // number of normals in all meshes
int nmeshtexcoord; // number of texcoords in all meshes
int nmeshface; // number of triangular faces in all meshes
int nmeshgraph; // number of ints in mesh auxiliary data
int nskin; // number of skins
Expand Down Expand Up @@ -581,10 +583,12 @@ struct mjModel_ {
int nuser_actuator; // number of mjtNums in actuator_user
int nuser_sensor; // number of mjtNums in sensor_user
int nnames; // number of chars in all names
int nnames_map; // number of slots in the names hash map

// sizes set after mjModel construction (only affect mjData)
int nM; // number of non-zeros in sparse inertia matrix
int nD; // number of non-zeros in sparse derivative matrix
int nD; // number of non-zeros in sparse dof-dof matrix
int nB; // number of non-zeros in sparse body-dof matrix
int nemax; // number of potential equality-constraint rows
int njmax; // number of available rows in constraint Jacobian
int nconmax; // number of potential contacts in contact list
Expand Down Expand Up @@ -634,6 +638,14 @@ struct mjModel_ {
mjtNum* body_gravcomp; // antigravity force, units of body weight (nbody x 1)
mjtNum* body_user; // user data (nbody x nuser_body)
int* body_plugin; // plugin instance id (-1 if not in use) (nbody x 1)
int* body_bvhadr; // address of bvh root (nbody x 1)
int* body_bvhnum; // number of bounding volumes (nbody x 1)

// bounding volume hierarchy
int* bvh_depth; // depth in the bounding volume hierarchy (nbvh x 1)
int* bvh_child; // left and right children in tree (nbvh x 2)
int* bvh_geomid; // geom id of the node (non-leaf: -1) (nbvh x 1)
mjtNum* bvh_aabb; // bounding box of node (center, size) (nbvh x 6)

// joints
int* jnt_type; // type of joint (mjtJoint) (njnt x 1)
Expand Down Expand Up @@ -680,6 +692,7 @@ struct mjModel_ {
mjtNum* geom_solref; // constraint solver reference: contact (ngeom x mjNREF)
mjtNum* geom_solimp; // constraint solver impedance: contact (ngeom x mjNIMP)
mjtNum* geom_size; // geom-specific size parameters (ngeom x 3)
mjtNum* geom_aabb; // bounding box, (center, size) (ngeom x 6)
mjtNum* geom_rbound; // radius of bounding sphere (ngeom x 1)
mjtNum* geom_pos; // local position offset rel. to body (ngeom x 3)
mjtNum* geom_quat; // local orientation offset rel. to body (ngeom x 4)
Expand Down Expand Up @@ -737,14 +750,19 @@ struct mjModel_ {
// meshes
int* mesh_vertadr; // first vertex address (nmesh x 1)
int* mesh_vertnum; // number of vertices (nmesh x 1)
int* mesh_texcoordadr; // texcoord data address; -1: no texcoord (nmesh x 1)
int* mesh_faceadr; // first face address (nmesh x 1)
int* mesh_facenum; // number of faces (nmesh x 1)
int* mesh_normaladr; // first normal address (nmesh x 1)
int* mesh_normalnum; // number of normals (nmesh x 1)
int* mesh_texcoordadr; // texcoord data address; -1: no texcoord (nmesh x 1)
int* mesh_texcoordnum; // number of texcoord (nmesh x 1)
int* mesh_graphadr; // graph data address; -1: no graph (nmesh x 1)
float* mesh_vert; // vertex positions for all meshes (nmeshvert x 3)
float* mesh_normal; // vertex normals for all meshes (nmeshvert x 3)
float* mesh_texcoord; // vertex texcoords for all meshes (nmeshtexvert x 2)
int* mesh_face; // triangle face data (nmeshface x 3)
float* mesh_normal; // normals for all meshes (nmeshnormal x 3)
float* mesh_texcoord; // vertex texcoords for all meshes (nmeshtexcoord x 2)
int* mesh_face; // vertex face data (nmeshface x 3)
int* mesh_facenormal; // normal face data (nmeshface x 3)
int* mesh_facetexcoord; // texture face data (nmeshface x 3)
int* mesh_graph; // convex graph data (nmeshgraph x 1)

// skins
Expand Down Expand Up @@ -942,6 +960,7 @@ struct mjModel_ {
int* name_keyadr; // keyframe name pointers (nkey x 1)
int* name_pluginadr; // plugin instance name pointers (nplugin x 1)
char* names; // names of all objects, 0-terminated (nnames x 1)
int* names_map; // internal hash map of names (nnames_map x 1)
};
typedef struct mjModel_ mjModel;

Expand Down
14 changes: 7 additions & 7 deletions include/mujoco/mjplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
#include <mujoco/mjvisualize.h>


typedef enum mjtPluginTypeBit_ {
typedef enum mjtPluginCapabilityBit_ {
mjPLUGIN_ACTUATOR = 1<<0,
mjPLUGIN_SENSOR = 1<<1,
mjPLUGIN_PASSIVE = 1<<2,
} mjtPluginTypeBit;
} mjtPluginCapabilityBit;

struct mjpPlugin_ {
const char* name; // globally unique name identifying the plugin
const char* name; // globally unique name identifying the plugin

int nattribute; // number of configuration attributes
const char* const* attributes; // name of configuration attributes

int type; // bitfield of mjtPluginTypeBits specifying the plugin type
int needstage; // an mjtStage enum value specifying the sensor computation stage
int capabilityflags; // bitfield of mjtPluginCapabilityBit specifying plugin capabilities
int needstage; // an mjtStage enum value specifying the sensor computation stage

// number of mjtNums needed to store the state of a plugin instance (required)
int (*nstate)(const mjModel* m, int instance);
Expand All @@ -51,10 +51,10 @@ struct mjpPlugin_ {
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);

// called when an mjData is being reset (required)
void (*reset)(const mjModel* m, mjData* d, int instance);
void (*reset)(const mjModel* m, double* plugin_state, void* plugin_data, int instance);

// called when the plugin needs to update its outputs (required)
void (*compute)(const mjModel* m, mjData* d, int instance, int type);
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);

// called when time integration occurs (optional)
void (*advance)(const mjModel* m, mjData* d, int instance);
Expand Down
3 changes: 3 additions & 0 deletions include/mujoco/mjrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ struct mjrContext_ { // custom OpenGL context

// framebuffer
int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN

// pixel output format
int readPixelFormat; // default color pixel format for mjr_readPixels
};
typedef struct mjrContext_ mjrContext;

Expand Down
9 changes: 8 additions & 1 deletion include/mujoco/mjtnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef MUJOCO_INCLUDE_MJTNUM_H_
#define MUJOCO_INCLUDE_MJTNUM_H_

//---------------------------------- floating-point definitions ------------------------------------
//---------------------------------- floating-point definition -------------------------------------

// compile-time configuration options
#define mjUSEDOUBLE // single or double precision for mjtNum
Expand All @@ -31,4 +31,11 @@
#endif



//-------------------------------------- byte definition -------------------------------------------

typedef unsigned char mjtByte; // used for true/false



#endif // MUJOCO_INCLUDE_MJTNUM_H_
8 changes: 7 additions & 1 deletion include/mujoco/mjui.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ typedef enum mjtEvent_ { // mouse and keyboard event type
mjEVENT_RELEASE, // mouse button release
mjEVENT_SCROLL, // scroll
mjEVENT_KEY, // key press
mjEVENT_RESIZE // resize
mjEVENT_RESIZE, // resize
mjEVENT_REDRAW, // redraw
mjEVENT_FILESDROP // files drop
} mjtEvent;


Expand Down Expand Up @@ -143,6 +145,10 @@ struct mjuiState_ { // mouse and keyboard state
int mouserect; // which rectangle contains mouse
int dragrect; // which rectangle is dragged with mouse
int dragbutton; // which button started drag (mjtButton)

// files dropping (only valid when type == mjEVENT_FILESDROP)
int dropcount; // number of files dropped
const char** droppaths; // paths to files dropped
};
typedef struct mjuiState_ mjuiState;

Expand Down
8 changes: 6 additions & 2 deletions include/mujoco/mjvisualize.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef enum mjtLabel_ { // object labeling
mjLABEL_SKIN, // skin labels
mjLABEL_SELECTION, // selected object
mjLABEL_SELPNT, // coordinates of selection point
mjLABEL_CONTACTPOINT, // contact information
mjLABEL_CONTACTFORCE, // magnitude of contact force

mjNLABEL // number of label types
Expand Down Expand Up @@ -119,6 +120,7 @@ typedef enum mjtVisFlag_ { // flags enabling model element visualization
mjVIS_SELECT, // selection point
mjVIS_STATIC, // static bodies
mjVIS_SKIN, // skin
mjVIS_MIDPHASE, // mid-phase bounding volume hierarchy

mjNVISFLAG // number of visualization flags
} mjtVisFlag;
Expand Down Expand Up @@ -154,9 +156,11 @@ struct mjvPerturb_ { // object selection and perturbation
int skinselect; // selected skin id; negative: none
int active; // perturbation bitmask (mjtPertBit)
int active2; // secondary perturbation bitmask (mjtPertBit)
mjtNum refpos[3]; // desired position for selected object
mjtNum refquat[4]; // desired orientation for selected object
mjtNum refpos[3]; // reference position for selected object
mjtNum refquat[4]; // reference orientation for selected object
mjtNum refselpos[3]; // reference position for selection point
mjtNum localpos[3]; // selection point in object coordinates
mjtNum localmass; // spatial inertia at selection point
mjtNum scale; // relative mouse motion-to-space scaling (set by initPerturb)
};
typedef struct mjvPerturb_ mjvPerturb;
Expand Down
Loading