├── lib
├── libccd.a
├── liblodepng.a
├── libmujoco.a
├── libelasticity.a
├── libtinyxml2.a
├── libqhullstatic_r.a
└── libtinyobjloader.a
├── public
├── mujoco_wasm.wasm
├── simple.xml
└── example.html
├── index.js
├── src
├── CMakeLists.txt
└── main.cc
├── CMakeLists.txt
├── package.json
├── .gitignore
├── LICENSE
├── include
└── mujoco
│ ├── mjtnum.h
│ ├── mjexport.h
│ ├── mjplugin.h
│ ├── mjrender.h
│ ├── mjui.h
│ ├── mjdata.h
│ ├── mjvisualize.h
│ ├── mjxmacro.h
│ └── mujoco.h
└── README.md
/lib/libccd.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/libccd.a
--------------------------------------------------------------------------------
/lib/liblodepng.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/liblodepng.a
--------------------------------------------------------------------------------
/lib/libmujoco.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/libmujoco.a
--------------------------------------------------------------------------------
/lib/libelasticity.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/libelasticity.a
--------------------------------------------------------------------------------
/lib/libtinyxml2.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/libtinyxml2.a
--------------------------------------------------------------------------------
/lib/libqhullstatic_r.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/libqhullstatic_r.a
--------------------------------------------------------------------------------
/lib/libtinyobjloader.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/lib/libtinyobjloader.a
--------------------------------------------------------------------------------
/public/mujoco_wasm.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stillonearth/MuJoCo-WASM/HEAD/public/mujoco_wasm.wasm
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import { Buffer } from "buffer";
2 | import { mujoco_wasm } from "./publuc/mujoco-wasm";
3 |
4 | export async function downloadFile(url, outputPath) {
5 | const x = await fetch(url);
6 | const x_1 = await x.arrayBuffer();
7 | FS.writeFile(outputPath, Buffer.from(x_1));
8 |
9 | }
10 |
11 | export * from mujoco_wasm;
12 |
13 |
--------------------------------------------------------------------------------
/public/simple.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.2)
2 | project(mujoco_wasm)
3 |
4 | set(SOURCE_FILES main.cc)
5 | add_compile_options(-pthread)
6 | set(EMCC_LINKER_FLAGS "-s ASSERTIONS=1 --bind")
7 | set(CMAKE_REQUIRED_FLAGS "${EMCC_LINKER_FLAGS}")
8 | add_executable(mujoco_wasm ${SOURCE_FILES})
9 | set_target_properties(mujoco_wasm PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS}")
10 |
11 | target_link_libraries(mujoco_wasm ccd elasticity lodepng mujoco tinyxml2 qhullstatic_r)
12 | install(TARGETS mujoco_wasm DESTINATION ${DIVISIBLE_INSTALL_BIN_DIR})
13 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.2)
2 | option(JS_ONLY "Compiles to native JS (No WASM)" OFF)
3 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/public")
4 |
5 | project(cmake-project-template)
6 |
7 | set(CMAKE_CXX_STANDARD 11)
8 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
9 |
10 | set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
11 |
12 | set(MUJOCO_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
13 | set(MUJOCO_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin)
14 | set(MUJOCO_INSTALL_LIB_DIR ${PROJECT_SOURCE_DIR}/lib)
15 |
16 | include_directories(${MUJOCO_INSTALL_INCLUDE_DIR})
17 | link_directories(${MUJOCO_INSTALL_LIB_DIR})
18 |
19 | add_subdirectory(src)
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@cwiz89/mujoco-wasm",
3 | "version": "0.0.1",
4 | "description": "Run MuJoCo simulations in browser",
5 | "main": "index.js",
6 | "directories": {
7 | "lib": "lib"
8 | },
9 | "scripts": {
10 | "test": "echo \"Error: no test specified\" && exit 1"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/stillonearth/MuJoCo-wasm.git"
15 | },
16 | "keywords": [
17 | "mujoco",
18 | "wasm"
19 | ],
20 | "author": "Sergei Surovtsev",
21 | "license": "ISC",
22 | "bugs": {
23 | "url": "https://github.com/stillonearth/MuJoCo-wasm/issues"
24 | },
25 | "homepage": "https://github.com/stillonearth/MuJoCo-wasm#readme",
26 | "dependencies": {
27 | "buffer": "^6.0.3"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | **/.DS_Store
3 | *.slo
4 | *.lo
5 | *.o
6 | *.obj
7 |
8 | # Precompiled Headers
9 | *.gch
10 | *.pch
11 |
12 | # Compiled Dynamic libraries
13 | *.so
14 | *.dylib
15 | *.dll
16 |
17 | # Fortran module files
18 | *.mod
19 | *.smod
20 |
21 | # Compiled Static libraries
22 | *.lai
23 | *.la
24 | *.a
25 | *.lib
26 |
27 | # Executables
28 | *.exe
29 | *.out
30 | *.app
31 |
32 | **/cmake-build-debug
33 | **/CMakeCache.txt
34 | **/cmake_install.cmake
35 | **/install_manifest.txt
36 | **/CMakeFiles/
37 | **/CTestTestfile.cmake
38 | **/Makefile
39 | **/*.cbp
40 | **/CMakeScripts
41 | **/compile_commands.json
42 |
43 | include/divisible/*
44 |
45 |
46 | ## Local
47 |
48 | .idea/*.xml
49 |
50 | build/**/*
51 |
52 | include/*
53 | lib/*
54 | bin/*
55 | test/test_runner
56 |
--------------------------------------------------------------------------------
/public/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Konstantin Gredeskoul
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/include/mujoco/mjtnum.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_INCLUDE_MJTNUM_H_
16 | #define MUJOCO_INCLUDE_MJTNUM_H_
17 |
18 | //---------------------------------- floating-point definition -------------------------------------
19 |
20 | // compile-time configuration options
21 | #define mjUSEDOUBLE // single or double precision for mjtNum
22 |
23 |
24 | // floating point data type and minval
25 | #ifdef mjUSEDOUBLE
26 | typedef double mjtNum;
27 | #define mjMINVAL 1E-15 // minimum value in any denominator
28 | #else
29 | typedef float mjtNum;
30 | #define mjMINVAL 1E-15f
31 | #endif
32 |
33 |
34 |
35 | //-------------------------------------- byte definition -------------------------------------------
36 |
37 | typedef unsigned char mjtByte; // used for true/false
38 |
39 |
40 |
41 | #endif // MUJOCO_INCLUDE_MJTNUM_H_
42 |
--------------------------------------------------------------------------------
/include/mujoco/mjexport.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MJEXPORT_H_
16 | #define MUJOCO_MJEXPORT_H_
17 |
18 | #if defined _WIN32 || defined __CYGWIN__
19 | #define MUJOCO_HELPER_DLL_IMPORT __declspec(dllimport)
20 | #define MUJOCO_HELPER_DLL_EXPORT __declspec(dllexport)
21 | #define MUJOCO_HELPER_DLL_LOCAL
22 | #else
23 | #if __GNUC__ >= 4
24 | #define MUJOCO_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
25 | #define MUJOCO_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
26 | #define MUJOCO_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
27 | #else
28 | #define MUJOCO_HELPER_DLL_IMPORT
29 | #define MUJOCO_HELPER_DLL_EXPORT
30 | #define MUJOCO_HELPER_DLL_LOCAL
31 | #endif
32 | #endif
33 |
34 | #ifdef MJ_STATIC
35 | // static library
36 | #define MJAPI
37 | #define MJLOCAL
38 | #else
39 | #ifdef MUJOCO_DLL_EXPORTS
40 | #define MJAPI MUJOCO_HELPER_DLL_EXPORT
41 | #else
42 | #define MJAPI MUJOCO_HELPER_DLL_IMPORT
43 | #endif
44 | #define MJLOCAL MUJOCO_HELPER_DLL_LOCAL
45 | #endif
46 |
47 | #endif // MUJOCO_MJEXPORT_H_
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MuJoCo-WASM
2 |
3 | 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.
4 |
5 | ## Usage
6 |
7 | **0. (Optional) Build MuJoCo libs with WASM targets**
8 |
9 | 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).
10 |
11 | **1. Install emscripten**
12 |
13 | **2. Build MuJoCo-WASM application**
14 |
15 | ```bash
16 | mkdir build
17 | cd build
18 | emcmake cmake ..
19 | make
20 | ```
21 |
22 | ## JavaScript API
23 |
24 | ```bash
25 | npm install mujoco-wasm --save
26 | ```
27 |
28 | ```javascript
29 | import { Model, Simulation, State, downloadFile } from "mujoco-wasm";
30 | ```
31 |
32 | **Utility Functions**
33 |
34 | | method | description |
35 | | -------------------------- | ------------------------------------------------------------------------- |
36 | | `async downloadFile(path)` | Download file from url and store in MEMFS so that wasm module can read it |
37 |
38 | **Model**
39 |
40 | | method | description |
41 | | ----------------- | --------------------------- |
42 | | `load_from_xml()` | Load model from xml string |
43 | | `ptr()` | Get pointer to MuJoCo model |
44 | | `val()` | Get MuJoCo model value |
45 | | `names()` | Get names of model |
46 | | `mesh_vertadr()` | Get mesh vertex address |
47 | | `mesh_vertnum()` | Get mesh vertex number |
48 | | `mesh_faceadr()` | Get mesh face address |
49 | | `mesh_facenum()` | Get mesh face number |
50 | | `body_parentid()` | Get body parent id |
51 | | `body_geomnum()` | Get body geometry number |
52 | | `body_geomadr()` | Get body geometry address |
53 | | `geom_type()` | Get geometry type |
54 | | `geom_bodyid()` | Get geometry body id |
55 | | `geom_group()` | Get geometry group |
56 | | `geom_contype()` | Get geometry contact type |
57 | | `mesh_normal()` | Get mesh normal |
58 | | `mesh_face()` | Get mesh face |
59 | | `mesh_vert()` | Get mesh vertex |
60 | | `name_meshadr()` | Get name mesh address |
61 | | `geom_pos()` | Get geometry position |
62 | | `geom_quat()` | Get geometry quaternion |
63 | | `geom_size()` | Get geometry size |
64 | | `geom_rgba()` | Get geometry rgba |
65 | | `body_pos()` | Get body position |
66 | | `body_quat()` | Get body quaternion |
67 |
68 | **State**
69 |
70 | | method | description |
71 | | ------- | --------------------------- |
72 | | `ptr()` | Get pointer to MuJoCo state |
73 | | `val()` | Get MuJoCo state value |
74 |
75 | **Simulation**
76 |
77 | | method | description |
78 | | --------- | -------------------- |
79 | | `step()` | Step simulation |
80 | | `state()` | Get simulation state |
81 | | `model()` | Get simulation model |
82 | | `xquat()` | Get quaternion |
83 | | `xpos()` | Get position |
84 |
--------------------------------------------------------------------------------
/include/mujoco/mjplugin.h:
--------------------------------------------------------------------------------
1 | // Copyright 2022 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_INCLUDE_MJPLUGIN_H_
16 | #define MUJOCO_INCLUDE_MJPLUGIN_H_
17 |
18 | #include
19 | #include
20 | #include
21 |
22 |
23 | //---------------------------------- Resource Provider ---------------------------------------------
24 |
25 | #define mjVFS_PREFIX "vfs://" // prefix for VFS providers
26 |
27 | // callback for opeing a resource, returns zero on failure
28 | typedef int (*mjfOpenResource)(mjResource* resource);
29 |
30 | // callback for reading a resource
31 | // return number of bytes stored in buffer, return -1 if error
32 | typedef int (*mjfReadResource)(mjResource* resource, const void** buffer);
33 |
34 | // callback for closing a resource (responsible for freeing any allocated memory)
35 | typedef void (*mjfCloseResource)(mjResource* resource);
36 |
37 | // struct describing a single resource provider
38 | struct mjpResourceProvider_ {
39 | const char* prefix; // prefix for match against a resource name
40 | mjfOpenResource open; // opening callback
41 | mjfReadResource read; // reading callback
42 | mjfCloseResource close; // closing callback
43 | void* data; // opaque data pointer (resource invariant)
44 | };
45 | typedef struct mjpResourceProvider_ mjpResourceProvider;
46 |
47 |
48 | //---------------------------------- Plugins -------------------------------------------------------
49 |
50 | typedef enum mjtPluginCapabilityBit_ {
51 | mjPLUGIN_ACTUATOR = 1<<0, // actuator forces
52 | mjPLUGIN_SENSOR = 1<<1, // sensor measurements
53 | mjPLUGIN_PASSIVE = 1<<2, // passive forces
54 | } mjtPluginCapabilityBit;
55 |
56 | struct mjpPlugin_ {
57 | const char* name; // globally unique name identifying the plugin
58 |
59 | int nattribute; // number of configuration attributes
60 | const char* const* attributes; // name of configuration attributes
61 |
62 | int capabilityflags; // plugin capabilities: bitfield of mjtPluginCapabilityBit
63 | int needstage; // sensor computation stage (mjtStage)
64 |
65 | // number of mjtNums needed to store the state of a plugin instance (required)
66 | int (*nstate)(const mjModel* m, int instance);
67 |
68 | // dimension of the specified sensor's output (required only for sensor plugins)
69 | int (*nsensordata)(const mjModel* m, int instance, int sensor_id);
70 |
71 | // called when a new mjData is being created (required), returns 0 on success or -1 on failure
72 | int (*init)(const mjModel* m, mjData* d, int instance);
73 |
74 | // called when an mjData is being freed (optional)
75 | void (*destroy)(mjData* d, int instance);
76 |
77 | // called when an mjData is being copied (optional)
78 | void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
79 |
80 | // called when an mjData is being reset (required)
81 | void (*reset)(const mjModel* m, double* plugin_state, void* plugin_data, int instance);
82 |
83 | // called when the plugin needs to update its outputs (required)
84 | void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
85 |
86 | // called when time integration occurs (optional)
87 | void (*advance)(const mjModel* m, mjData* d, int instance);
88 |
89 | // called by mjv_updateScene (optional)
90 | void (*visualize)(const mjModel*m, mjData* d, const mjvOption* opt, mjvScene* scn, int instance);
91 | };
92 | typedef struct mjpPlugin_ mjpPlugin;
93 |
94 | #if defined(__has_attribute)
95 |
96 | #if __has_attribute(constructor)
97 | #define mjPLUGIN_LIB_INIT __attribute__((constructor)) static void _mjplugin_init(void)
98 | #endif // __has_attribute(constructor)
99 |
100 | #elif defined(_MSC_VER)
101 |
102 | #ifndef mjDLLMAIN
103 | #define mjDLLMAIN DllMain
104 | #endif
105 |
106 | #if !defined(mjEXTERNC)
107 | #if defined(__cplusplus)
108 | #define mjEXTERNC extern "C"
109 | #else
110 | #define mjEXTERNC
111 | #endif // defined(__cplusplus)
112 | #endif // !defined(mjEXTERNC)
113 |
114 | // NOLINTBEGIN(runtime/int)
115 | #define mjPLUGIN_LIB_INIT \
116 | static void _mjplugin_dllmain(void); \
117 | mjEXTERNC int __stdcall mjDLLMAIN(void* hinst, unsigned long reason, void* reserved) { \
118 | if (reason == 1) { \
119 | _mjplugin_dllmain(); \
120 | } \
121 | return 1; \
122 | } \
123 | static void _mjplugin_dllmain(void)
124 | // NOLINTEND(runtime/int)
125 |
126 | #endif // defined(_MSC_VER)
127 |
128 | // function pointer type for mj_loadAllPluginLibraries callback
129 | typedef void (*mjfPluginLibraryLoadCallback)(const char* filename, int first, int count);
130 |
131 | #endif // MUJOCO_INCLUDE_MJPLUGIN_H_
132 |
--------------------------------------------------------------------------------
/include/mujoco/mjrender.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MJRENDER_H_
16 | #define MUJOCO_MJRENDER_H_
17 |
18 |
19 | #if defined(__cplusplus)
20 | extern "C" {
21 | #endif
22 |
23 | #define mjNAUX 10 // number of auxiliary buffers
24 | #define mjMAXTEXTURE 1000 // maximum number of textures
25 |
26 |
27 | //---------------------------------- primitive types (mjt) -----------------------------------------
28 |
29 | typedef enum mjtGridPos_ { // grid position for overlay
30 | mjGRID_TOPLEFT = 0, // top left
31 | mjGRID_TOPRIGHT, // top right
32 | mjGRID_BOTTOMLEFT, // bottom left
33 | mjGRID_BOTTOMRIGHT // bottom right
34 | } mjtGridPos;
35 |
36 |
37 | typedef enum mjtFramebuffer_ { // OpenGL framebuffer option
38 | mjFB_WINDOW = 0, // default/window buffer
39 | mjFB_OFFSCREEN // offscreen buffer
40 | } mjtFramebuffer;
41 |
42 |
43 | typedef enum mjtFontScale_ { // font scale, used at context creation
44 | mjFONTSCALE_50 = 50, // 50% scale, suitable for low-res rendering
45 | mjFONTSCALE_100 = 100, // normal scale, suitable in the absence of DPI scaling
46 | mjFONTSCALE_150 = 150, // 150% scale
47 | mjFONTSCALE_200 = 200, // 200% scale
48 | mjFONTSCALE_250 = 250, // 250% scale
49 | mjFONTSCALE_300 = 300 // 300% scale
50 | } mjtFontScale;
51 |
52 |
53 | typedef enum mjtFont_ { // font type, used at each text operation
54 | mjFONT_NORMAL = 0, // normal font
55 | mjFONT_SHADOW, // normal font with shadow (for higher contrast)
56 | mjFONT_BIG // big font (for user alerts)
57 | } mjtFont;
58 |
59 |
60 | struct mjrRect_ { // OpenGL rectangle
61 | int left; // left (usually 0)
62 | int bottom; // bottom (usually 0)
63 | int width; // width (usually buffer width)
64 | int height; // height (usually buffer height)
65 | };
66 | typedef struct mjrRect_ mjrRect;
67 |
68 |
69 | //---------------------------------- mjrContext ----------------------------------------------------
70 |
71 | struct mjrContext_ { // custom OpenGL context
72 | // parameters copied from mjVisual
73 | float lineWidth; // line width for wireframe rendering
74 | float shadowClip; // clipping radius for directional lights
75 | float shadowScale; // fraction of light cutoff for spot lights
76 | float fogStart; // fog start = stat.extent * vis.map.fogstart
77 | float fogEnd; // fog end = stat.extent * vis.map.fogend
78 | float fogRGBA[4]; // fog rgba
79 | int shadowSize; // size of shadow map texture
80 | int offWidth; // width of offscreen buffer
81 | int offHeight; // height of offscreen buffer
82 | int offSamples; // number of offscreen buffer multisamples
83 |
84 | // parameters specified at creation
85 | int fontScale; // font scale
86 | int auxWidth[mjNAUX]; // auxiliary buffer width
87 | int auxHeight[mjNAUX]; // auxiliary buffer height
88 | int auxSamples[mjNAUX]; // auxiliary buffer multisamples
89 |
90 | // offscreen rendering objects
91 | unsigned int offFBO; // offscreen framebuffer object
92 | unsigned int offFBO_r; // offscreen framebuffer for resolving multisamples
93 | unsigned int offColor; // offscreen color buffer
94 | unsigned int offColor_r; // offscreen color buffer for resolving multisamples
95 | unsigned int offDepthStencil; // offscreen depth and stencil buffer
96 | unsigned int offDepthStencil_r; // offscreen depth and stencil buffer for resolving multisamples
97 |
98 | // shadow rendering objects
99 | unsigned int shadowFBO; // shadow map framebuffer object
100 | unsigned int shadowTex; // shadow map texture
101 |
102 | // auxiliary buffers
103 | unsigned int auxFBO[mjNAUX]; // auxiliary framebuffer object
104 | unsigned int auxFBO_r[mjNAUX]; // auxiliary framebuffer object for resolving
105 | unsigned int auxColor[mjNAUX]; // auxiliary color buffer
106 | unsigned int auxColor_r[mjNAUX];// auxiliary color buffer for resolving
107 |
108 | // texture objects and info
109 | int ntexture; // number of allocated textures
110 | int textureType[100]; // type of texture (mjtTexture) (ntexture)
111 | unsigned int texture[100]; // texture names
112 |
113 | // displaylist starting positions
114 | unsigned int basePlane; // all planes from model
115 | unsigned int baseMesh; // all meshes from model
116 | unsigned int baseHField; // all hfields from model
117 | unsigned int baseBuiltin; // all buildin geoms, with quality from model
118 | unsigned int baseFontNormal; // normal font
119 | unsigned int baseFontShadow; // shadow font
120 | unsigned int baseFontBig; // big font
121 |
122 | // displaylist ranges
123 | int rangePlane; // all planes from model
124 | int rangeMesh; // all meshes from model
125 | int rangeHField; // all hfields from model
126 | int rangeBuiltin; // all builtin geoms, with quality from model
127 | int rangeFont; // all characters in font
128 |
129 | // skin VBOs
130 | int nskin; // number of skins
131 | unsigned int* skinvertVBO; // skin vertex position VBOs (nskin)
132 | unsigned int* skinnormalVBO; // skin vertex normal VBOs (nskin)
133 | unsigned int* skintexcoordVBO; // skin vertex texture coordinate VBOs (nskin)
134 | unsigned int* skinfaceVBO; // skin face index VBOs (nskin)
135 |
136 | // character info
137 | int charWidth[127]; // character widths: normal and shadow
138 | int charWidthBig[127]; // chacarter widths: big
139 | int charHeight; // character heights: normal and shadow
140 | int charHeightBig; // character heights: big
141 |
142 | // capabilities
143 | int glInitialized; // is OpenGL initialized
144 | int windowAvailable; // is default/window framebuffer available
145 | int windowSamples; // number of samples for default/window framebuffer
146 | int windowStereo; // is stereo available for default/window framebuffer
147 | int windowDoublebuffer; // is default/window framebuffer double buffered
148 |
149 | // framebuffer
150 | int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN
151 |
152 | // pixel output format
153 | int readPixelFormat; // default color pixel format for mjr_readPixels
154 | };
155 | typedef struct mjrContext_ mjrContext;
156 |
157 | #if defined(__cplusplus)
158 | }
159 | #endif
160 | #endif // MUJOCO_MJRENDER_H_
161 |
--------------------------------------------------------------------------------
/src/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "mujoco/mujoco.h"
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | using namespace emscripten;
15 |
16 | int finish(const char *msg = NULL, mjModel *m = NULL)
17 | {
18 | // deallocate model
19 | if (m)
20 | {
21 | mj_deleteModel(m);
22 | }
23 |
24 | // print message
25 | if (msg)
26 | {
27 | std::printf("%s\n", msg);
28 | }
29 |
30 | return 0;
31 | }
32 |
33 | class Model
34 | {
35 | public:
36 | Model()
37 | {
38 | m = NULL;
39 | }
40 |
41 | static Model load_from_xml(const std::string filename)
42 | {
43 | Model model;
44 | char error[1000] = "Could not load xml model";
45 | model.m = mj_loadXML(filename.c_str(), 0, error, 1000);
46 |
47 | if (!model.m)
48 | {
49 | finish(error, model.m);
50 | }
51 |
52 | return model;
53 | }
54 |
55 | mjModel *ptr()
56 | {
57 | return m;
58 | }
59 |
60 | mjModel val()
61 | {
62 | return *m;
63 | }
64 |
65 | std::vector names()
66 | {
67 | std::vector names;
68 | int j = 0;
69 |
70 | for (int i = 0; i < m->nnames; i++)
71 | {
72 | std::string name;
73 |
74 | while (true)
75 | {
76 | char c = m->names[j];
77 | j += 1;
78 | if (c == 0)
79 | {
80 | names.push_back(name);
81 | break;
82 | }
83 | else
84 | {
85 | name.push_back(c);
86 | }
87 | }
88 | }
89 |
90 | return names;
91 | }
92 |
93 | std::vector mesh_vertadr()
94 | {
95 | std::vector ret;
96 |
97 | for (int i = 0; i < m->nmesh; i++)
98 | {
99 | int addr;
100 | ret.push_back(m->mesh_vertadr[i]);
101 | }
102 |
103 | return ret;
104 | }
105 |
106 | std::vector mesh_vertnum()
107 | {
108 | std::vector ret;
109 |
110 | for (int i = 0; i < m->nmesh; i++)
111 | {
112 | int addr;
113 | ret.push_back(m->mesh_vertnum[i]);
114 | }
115 |
116 | return ret;
117 | }
118 |
119 | std::vector mesh_faceadr()
120 | {
121 | std::vector ret;
122 |
123 | for (int i = 0; i < m->nmesh; i++)
124 | {
125 | int addr;
126 | ret.push_back(m->mesh_faceadr[i]);
127 | }
128 |
129 | return ret;
130 | }
131 |
132 | std::vector mesh_facenum()
133 | {
134 | std::vector ret;
135 |
136 | for (int i = 0; i < m->nmesh; i++)
137 | {
138 | int addr;
139 | ret.push_back(m->mesh_facenum[i]);
140 | }
141 |
142 | return ret;
143 | }
144 |
145 | std::vector body_parentid()
146 | {
147 | std::vector ret;
148 |
149 | for (int i = 0; i < m->nbody; i++)
150 | {
151 | int addr;
152 | ret.push_back(m->body_parentid[i]);
153 | }
154 |
155 | return ret;
156 | }
157 |
158 | std::vector body_geomnum()
159 | {
160 | std::vector ret;
161 |
162 | for (int i = 0; i < m->nbody; i++)
163 | {
164 | int addr;
165 | ret.push_back(m->body_geomnum[i]);
166 | }
167 |
168 | return ret;
169 | }
170 |
171 | std::vector body_geomadr()
172 | {
173 | std::vector ret;
174 |
175 | for (int i = 0; i < m->nbody; i++)
176 | {
177 | int addr;
178 | ret.push_back(m->body_geomadr[i]);
179 | }
180 |
181 | return ret;
182 | }
183 |
184 | std::vector geom_type()
185 | {
186 | std::vector ret;
187 |
188 | for (int i = 0; i < m->ngeom; i++)
189 | {
190 | int addr;
191 | ret.push_back(m->geom_type[i]);
192 | }
193 |
194 | return ret;
195 | }
196 |
197 | std::vector geom_bodyid()
198 | {
199 | std::vector ret;
200 |
201 | for (int i = 0; i < m->ngeom; i++)
202 | {
203 | int addr;
204 | ret.push_back(m->geom_bodyid[i]);
205 | }
206 |
207 | return ret;
208 | }
209 |
210 | std::vector geom_group()
211 | {
212 | std::vector ret;
213 |
214 | for (int i = 0; i < m->ngeom; i++)
215 | {
216 | int addr;
217 | ret.push_back(m->geom_group[i]);
218 | }
219 |
220 | return ret;
221 | }
222 |
223 | std::vector geom_contype()
224 | {
225 | std::vector ret;
226 |
227 | for (int i = 0; i < m->ngeom; i++)
228 | {
229 | int addr;
230 | ret.push_back(m->geom_contype[i]);
231 | }
232 |
233 | return ret;
234 | }
235 |
236 | std::vector> mesh_normal()
237 | {
238 | std::vector> ret;
239 |
240 | for (int i = 0; i < m->nmeshvert; i++)
241 | {
242 | ret.push_back({m->mesh_normal[3 * i], m->mesh_normal[3 * i + 1], m->mesh_normal[3 * i + 2]});
243 | }
244 |
245 | return ret;
246 | }
247 |
248 | std::vector> mesh_face()
249 | {
250 | std::vector> ret;
251 |
252 | for (int i = 0; i < m->nmeshface; i++)
253 | {
254 | ret.push_back({m->mesh_face[3 * i], m->mesh_face[3 * i + 1], m->mesh_face[3 * i + 2]});
255 | }
256 |
257 | return ret;
258 | }
259 |
260 | std::vector> mesh_vert()
261 | {
262 | std::vector> ret;
263 |
264 | for (int i = 0; i < m->nmeshvert; i++)
265 | {
266 | ret.push_back({m->mesh_vert[3 * i], m->mesh_vert[3 * i + 1], m->mesh_vert[3 * i + 2]});
267 | }
268 |
269 | return ret;
270 | }
271 |
272 | std::vector name_meshadr()
273 | {
274 | std::vector ret;
275 |
276 | for (int i = 0; i < m->nmesh; i++)
277 | {
278 | int addr;
279 | ret.push_back(m->name_meshadr[i]);
280 | }
281 |
282 | return ret;
283 | }
284 |
285 | std::vector> geom_size()
286 | {
287 | std::vector> ret;
288 |
289 | for (int i = 0; i < m->ngeom; i++)
290 | {
291 | ret.push_back({m->geom_size[3 * i], m->geom_size[3 * i + 1], m->geom_size[3 * i + 2]});
292 | }
293 |
294 | return ret;
295 | }
296 |
297 | std::vector> geom_pos()
298 | {
299 | std::vector> ret;
300 |
301 | for (int i = 0; i < m->ngeom; i++)
302 | {
303 | ret.push_back({m->geom_pos[3 * i], m->geom_pos[3 * i + 1], m->geom_pos[3 * i + 2]});
304 | }
305 |
306 | return ret;
307 | }
308 |
309 | std::vector> body_pos()
310 | {
311 | std::vector> ret;
312 |
313 | for (int i = 0; i < m->nbody; i++)
314 | {
315 | ret.push_back({m->body_pos[3 * i], m->body_pos[3 * i + 1], m->body_pos[3 * i + 2]});
316 | }
317 |
318 | return ret;
319 | }
320 |
321 | std::vector> geom_quat()
322 | {
323 | std::vector> ret;
324 |
325 | for (int i = 0; i < m->ngeom; i++)
326 | {
327 | ret.push_back({m->geom_quat[4 * i], m->geom_quat[4 * i + 1], m->geom_quat[4 * i + 2], m->geom_quat[4 * i + 3]});
328 | }
329 |
330 | return ret;
331 | }
332 |
333 | std::vector> body_quat()
334 | {
335 | std::vector> ret;
336 |
337 | for (int i = 0; i < m->nbody; i++)
338 | {
339 | ret.push_back({m->body_quat[4 * i], m->body_quat[4 * i + 1], m->body_quat[4 * i + 2], m->body_quat[4 * i + 3]});
340 | }
341 |
342 | return ret;
343 | }
344 |
345 | std::vector> geom_rgba()
346 | {
347 | std::vector> ret;
348 |
349 | for (int i = 0; i < m->ngeom; i++)
350 | {
351 | ret.push_back({m->geom_rgba[4 * i], m->geom_rgba[4 * i + 1], m->geom_rgba[4 * i + 2], m->geom_rgba[4 * i + 3]});
352 | }
353 |
354 | return ret;
355 | }
356 |
357 | private:
358 | mjModel *m;
359 | };
360 |
361 | class State
362 | {
363 | public:
364 | State(Model m)
365 | {
366 | d = mj_makeData(m.ptr());
367 | }
368 |
369 | mjData *ptr()
370 | {
371 | return d;
372 | }
373 |
374 | mjData val()
375 | {
376 | return *d;
377 | }
378 |
379 | private:
380 | mjData *d;
381 | };
382 |
383 | class Simulation
384 | {
385 | public:
386 | Simulation(Model *m, State *s)
387 | {
388 | _model = m;
389 | _state = s;
390 | }
391 |
392 | State *state()
393 | {
394 | return _state;
395 | }
396 |
397 | Model *model()
398 | {
399 | return _model;
400 | }
401 |
402 | void step()
403 | {
404 | mj_step(_model->ptr(), _state->ptr());
405 | }
406 |
407 | std::vector> xquat()
408 | {
409 | std::vector> ret;
410 |
411 | for (int i = 0; i < _model->ptr()->ngeom; i++)
412 | {
413 | ret.push_back({_state->ptr()->xquat[4 * i], _state->ptr()->xquat[4 * i + 1], _state->ptr()->xquat[4 * i + 2], _state->ptr()->xquat[4 * i + 3]});
414 | }
415 |
416 | return ret;
417 | }
418 |
419 | std::vector> xpos()
420 | {
421 | std::vector> ret;
422 |
423 | for (int i = 0; i < _model->ptr()->ngeom; i++)
424 | {
425 | ret.push_back({_state->ptr()->xpos[3 * i], _state->ptr()->xpos[3 * i + 1], _state->ptr()->xpos[3 * i + 2]});
426 | }
427 |
428 | return ret;
429 | }
430 |
431 | private:
432 | Model *_model;
433 | State *_state;
434 | };
435 |
436 | // main function
437 | int main(int argc, char **argv)
438 | {
439 | std::printf("MuJoCo version: %d\n\n", mj_version());
440 | return 0;
441 | }
442 |
443 | EMSCRIPTEN_BINDINGS(mujoco_wasm)
444 | {
445 | class_("Model")
446 | .constructor<>()
447 | .class_function("load_from_xml", &Model::load_from_xml)
448 | .function("ptr", &Model::ptr, allow_raw_pointers())
449 | .function("val", &Model::val)
450 | .function("names", &Model::names)
451 | .function("mesh_vertadr", &Model::mesh_vertadr)
452 | .function("mesh_vertnum", &Model::mesh_vertnum)
453 | .function("mesh_faceadr", &Model::mesh_faceadr)
454 | .function("mesh_facenum", &Model::mesh_facenum)
455 | .function("body_parentid", &Model::body_parentid)
456 | .function("body_geomnum", &Model::body_geomnum)
457 | .function("body_geomadr", &Model::body_geomadr)
458 | .function("geom_type", &Model::geom_type)
459 | .function("geom_bodyid", &Model::geom_bodyid)
460 | .function("geom_group", &Model::geom_group)
461 | .function("geom_contype", &Model::geom_contype)
462 | .function("mesh_normal", &Model::mesh_normal)
463 | .function("mesh_face", &Model::mesh_face)
464 | .function("mesh_vert", &Model::mesh_vert)
465 | .function("name_meshadr", &Model::name_meshadr)
466 | .function("geom_pos", &Model::geom_pos)
467 | .function("geom_quat", &Model::geom_quat)
468 | .function("geom_size", &Model::geom_size)
469 | .function("geom_rgba", &Model::geom_rgba)
470 | .function("body_pos", &Model::body_pos)
471 | .function("body_quat", &Model::body_quat);
472 |
473 | class_("State")
474 | .constructor()
475 | .function("ptr", &State::ptr, allow_raw_pointers())
476 | .function("val", &State::val);
477 |
478 | class_("Simulation")
479 | .constructor()
480 | .function("step", &Simulation::step)
481 | .function("state", &Simulation::state, allow_raw_pointers())
482 | .function("model", &Simulation::model, allow_raw_pointers())
483 | .function("xquat", &Simulation::xquat)
484 | .function("xquat", &Simulation::xpos);
485 |
486 | value_object("mjModel")
487 | .field("ngeom", &mjModel::ngeom)
488 | .field("nq", &mjModel::nq)
489 | .field("na", &mjModel::na)
490 | .field("nv", &mjModel::nv)
491 | .field("nu", &mjModel::nu)
492 | .field("nbody", &mjModel::nbody)
493 | .field("nsensordata", &mjModel::nsensordata)
494 | .field("nmesh", &mjModel::nmesh)
495 | .field("nmeshvert", &mjModel::nmeshvert)
496 | .field("nmeshface", &mjModel::nmeshface);
497 |
498 | register_vector("vector");
499 | register_vector>("vector>");
500 | register_vector>("vector>");
501 | register_vector>("vector>");
502 | register_vector>("vector>");
503 | register_vector>("vector>");
504 |
505 | value_object("mjData");
506 | }
--------------------------------------------------------------------------------
/include/mujoco/mjui.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MJUI_H_
16 | #define MUJOCO_MJUI_H_
17 |
18 | #include
19 |
20 | #define mjMAXUISECT 10 // maximum number of sections
21 | #define mjMAXUIITEM 80 // maximum number of items per section
22 | #define mjMAXUITEXT 300 // maximum number of chars in edittext and other
23 | #define mjMAXUINAME 40 // maximum number of chars in name
24 | #define mjMAXUIMULTI 35 // maximum number of radio/select items in group
25 | #define mjMAXUIEDIT 7 // maximum number of elements in edit list
26 | #define mjMAXUIRECT 25 // maximum number of rectangles
27 |
28 | #define mjSEPCLOSED 1000 // closed state of adjustable separator
29 |
30 |
31 | // key codes matching GLFW (user must remap for other frameworks)
32 | #define mjKEY_ESCAPE 256
33 | #define mjKEY_ENTER 257
34 | #define mjKEY_TAB 258
35 | #define mjKEY_BACKSPACE 259
36 | #define mjKEY_INSERT 260
37 | #define mjKEY_DELETE 261
38 | #define mjKEY_RIGHT 262
39 | #define mjKEY_LEFT 263
40 | #define mjKEY_DOWN 264
41 | #define mjKEY_UP 265
42 | #define mjKEY_PAGE_UP 266
43 | #define mjKEY_PAGE_DOWN 267
44 | #define mjKEY_HOME 268
45 | #define mjKEY_END 269
46 | #define mjKEY_F1 290
47 | #define mjKEY_F2 291
48 | #define mjKEY_F3 292
49 | #define mjKEY_F4 293
50 | #define mjKEY_F5 294
51 | #define mjKEY_F6 295
52 | #define mjKEY_F7 296
53 | #define mjKEY_F8 297
54 | #define mjKEY_F9 298
55 | #define mjKEY_F10 299
56 | #define mjKEY_F11 300
57 | #define mjKEY_F12 301
58 |
59 |
60 | //---------------------------------- primitive types (mjt) -----------------------------------------
61 |
62 | typedef enum mjtButton_ { // mouse button
63 | mjBUTTON_NONE = 0, // no button
64 | mjBUTTON_LEFT, // left button
65 | mjBUTTON_RIGHT, // right button
66 | mjBUTTON_MIDDLE // middle button
67 | } mjtButton;
68 |
69 |
70 | typedef enum mjtEvent_ { // mouse and keyboard event type
71 | mjEVENT_NONE = 0, // no event
72 | mjEVENT_MOVE, // mouse move
73 | mjEVENT_PRESS, // mouse button press
74 | mjEVENT_RELEASE, // mouse button release
75 | mjEVENT_SCROLL, // scroll
76 | mjEVENT_KEY, // key press
77 | mjEVENT_RESIZE, // resize
78 | mjEVENT_REDRAW, // redraw
79 | mjEVENT_FILESDROP // files drop
80 | } mjtEvent;
81 |
82 |
83 | typedef enum mjtItem_ { // UI item type
84 | mjITEM_END = -2, // end of definition list (not an item)
85 | mjITEM_SECTION = -1, // section (not an item)
86 | mjITEM_SEPARATOR = 0, // separator
87 | mjITEM_STATIC, // static text
88 | mjITEM_BUTTON, // button
89 |
90 | // the rest have data pointer
91 | mjITEM_CHECKINT, // check box, int value
92 | mjITEM_CHECKBYTE, // check box, mjtByte value
93 | mjITEM_RADIO, // radio group
94 | mjITEM_RADIOLINE, // radio group, single line
95 | mjITEM_SELECT, // selection box
96 | mjITEM_SLIDERINT, // slider, int value
97 | mjITEM_SLIDERNUM, // slider, mjtNum value
98 | mjITEM_EDITINT, // editable array, int values
99 | mjITEM_EDITNUM, // editable array, mjtNum values
100 | mjITEM_EDITTXT, // editable text
101 |
102 | mjNITEM // number of item types
103 | } mjtItem;
104 |
105 |
106 | // predicate function: set enable/disable based on item category
107 | typedef int (*mjfItemEnable)(int category, void* data);
108 |
109 |
110 | //---------------------------------- mjuiState -----------------------------------------------------
111 |
112 | struct mjuiState_ { // mouse and keyboard state
113 | // constants set by user
114 | int nrect; // number of rectangles used
115 | mjrRect rect[mjMAXUIRECT]; // rectangles (index 0: entire window)
116 | void* userdata; // pointer to user data (for callbacks)
117 |
118 | // event type
119 | int type; // (type mjtEvent)
120 |
121 | // mouse buttons
122 | int left; // is left button down
123 | int right; // is right button down
124 | int middle; // is middle button down
125 | int doubleclick; // is last press a double click
126 | int button; // which button was pressed (mjtButton)
127 | double buttontime; // time of last button press
128 |
129 | // mouse position
130 | double x; // x position
131 | double y; // y position
132 | double dx; // x displacement
133 | double dy; // y displacement
134 | double sx; // x scroll
135 | double sy; // y scroll
136 |
137 | // keyboard
138 | int control; // is control down
139 | int shift; // is shift down
140 | int alt; // is alt down
141 | int key; // which key was pressed
142 | double keytime; // time of last key press
143 |
144 | // rectangle ownership and dragging
145 | int mouserect; // which rectangle contains mouse
146 | int dragrect; // which rectangle is dragged with mouse
147 | int dragbutton; // which button started drag (mjtButton)
148 |
149 | // files dropping (only valid when type == mjEVENT_FILESDROP)
150 | int dropcount; // number of files dropped
151 | const char** droppaths; // paths to files dropped
152 | };
153 | typedef struct mjuiState_ mjuiState;
154 |
155 |
156 | //---------------------------------- mjuiThemeSpacing ----------------------------------------------
157 |
158 | struct mjuiThemeSpacing_ { // UI visualization theme spacing
159 | int total; // total width
160 | int scroll; // scrollbar width
161 | int label; // label width
162 | int section; // section gap
163 | int itemside; // item side gap
164 | int itemmid; // item middle gap
165 | int itemver; // item vertical gap
166 | int texthor; // text horizontal gap
167 | int textver; // text vertical gap
168 | int linescroll; // number of pixels to scroll
169 | int samples; // number of multisamples
170 | };
171 | typedef struct mjuiThemeSpacing_ mjuiThemeSpacing;
172 |
173 |
174 | //---------------------------------- mjuiThemeColor ------------------------------------------------
175 |
176 | struct mjuiThemeColor_ { // UI visualization theme color
177 | float master[3]; // master background
178 | float thumb[3]; // scrollbar thumb
179 | float secttitle[3]; // section title
180 | float sectfont[3]; // section font
181 | float sectsymbol[3]; // section symbol
182 | float sectpane[3]; // section pane
183 | float shortcut[3]; // shortcut background
184 | float fontactive[3]; // font active
185 | float fontinactive[3]; // font inactive
186 | float decorinactive[3]; // decor inactive
187 | float decorinactive2[3]; // inactive slider color 2
188 | float button[3]; // button
189 | float check[3]; // check
190 | float radio[3]; // radio
191 | float select[3]; // select
192 | float select2[3]; // select pane
193 | float slider[3]; // slider
194 | float slider2[3]; // slider color 2
195 | float edit[3]; // edit
196 | float edit2[3]; // edit invalid
197 | float cursor[3]; // edit cursor
198 | };
199 | typedef struct mjuiThemeColor_ mjuiThemeColor;
200 |
201 |
202 | //---------------------------------- mjuiItem ------------------------------------------------------
203 |
204 | struct mjuiItemSingle_ { // check and button-related
205 | int modifier; // 0: none, 1: control, 2: shift; 4: alt
206 | int shortcut; // shortcut key; 0: undefined
207 | };
208 |
209 |
210 | struct mjuiItemMulti_ { // static, radio and select-related
211 | int nelem; // number of elements in group
212 | char name[mjMAXUIMULTI][mjMAXUINAME]; // element names
213 | };
214 |
215 |
216 | struct mjuiItemSlider_ { // slider-related
217 | double range[2]; // slider range
218 | double divisions; // number of range divisions
219 | };
220 |
221 |
222 | struct mjuiItemEdit_ { // edit-related
223 | int nelem; // number of elements in list
224 | double range[mjMAXUIEDIT][2]; // element range (min>=max: ignore)
225 | };
226 |
227 |
228 | struct mjuiItem_ { // UI item
229 | // common properties
230 | int type; // type (mjtItem)
231 | char name[mjMAXUINAME]; // name
232 | int state; // 0: disable, 1: enable, 2+: use predicate
233 | void *pdata; // data pointer (type-specific)
234 | int sectionid; // id of section containing item
235 | int itemid; // id of item within section
236 |
237 | // type-specific properties
238 | union {
239 | struct mjuiItemSingle_ single; // check and button
240 | struct mjuiItemMulti_ multi; // static, radio and select
241 | struct mjuiItemSlider_ slider; // slider
242 | struct mjuiItemEdit_ edit; // edit
243 | };
244 |
245 | // internal
246 | mjrRect rect; // rectangle occupied by item
247 | };
248 | typedef struct mjuiItem_ mjuiItem;
249 |
250 |
251 | //---------------------------------- mjuiSection ---------------------------------------------------
252 |
253 | struct mjuiSection_ { // UI section
254 | // properties
255 | char name[mjMAXUINAME]; // name
256 | int state; // 0: closed, 1: open
257 | int modifier; // 0: none, 1: control, 2: shift; 4: alt
258 | int shortcut; // shortcut key; 0: undefined
259 | int nitem; // number of items in use
260 | mjuiItem item[mjMAXUIITEM]; // preallocated array of items
261 |
262 | // internal
263 | mjrRect rtitle; // rectangle occupied by title
264 | mjrRect rcontent; // rectangle occupied by content
265 | };
266 | typedef struct mjuiSection_ mjuiSection;
267 |
268 |
269 | //---------------------------------- mjUI ----------------------------------------------------------
270 |
271 | struct mjUI_ { // entire UI
272 | // constants set by user
273 | mjuiThemeSpacing spacing; // UI theme spacing
274 | mjuiThemeColor color; // UI theme color
275 | mjfItemEnable predicate; // callback to set item state programmatically
276 | void* userdata; // pointer to user data (passed to predicate)
277 | int rectid; // index of this ui rectangle in mjuiState
278 | int auxid; // aux buffer index of this ui
279 | int radiocol; // number of radio columns (0 defaults to 2)
280 |
281 | // UI sizes (framebuffer units)
282 | int width; // width
283 | int height; // current heigth
284 | int maxheight; // height when all sections open
285 | int scroll; // scroll from top of UI
286 |
287 | // mouse focus
288 | int mousesect; // 0: none, -1: scroll, otherwise 1+section
289 | int mouseitem; // item within section
290 | int mousehelp; // help button down: print shortcuts
291 |
292 | // keyboard focus and edit
293 | int editsect; // 0: none, otherwise 1+section
294 | int edititem; // item within section
295 | int editcursor; // cursor position
296 | int editscroll; // horizontal scroll
297 | char edittext[mjMAXUITEXT]; // current text
298 | mjuiItem* editchanged; // pointer to changed edit in last mjui_event
299 |
300 | // sections
301 | int nsect; // number of sections in use
302 | mjuiSection sect[mjMAXUISECT]; // preallocated array of sections
303 | };
304 | typedef struct mjUI_ mjUI;
305 |
306 |
307 | //---------------------------------- mjuiDef -------------------------------------------------------
308 |
309 | struct mjuiDef_ { // table passed to mjui_add()
310 | int type; // type (mjtItem); -1: section
311 | char name[mjMAXUINAME]; // name
312 | int state; // state
313 | void* pdata; // pointer to data
314 | char other[mjMAXUITEXT]; // string with type-specific properties
315 | };
316 | typedef struct mjuiDef_ mjuiDef;
317 |
318 | #endif // MUJOCO_MJUI_H_
319 |
--------------------------------------------------------------------------------
/include/mujoco/mjdata.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MJDATA_H_
16 | #define MUJOCO_MJDATA_H_
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 |
24 | //---------------------------------- primitive types (mjt) -----------------------------------------
25 |
26 | typedef enum mjtWarning_ { // warning types
27 | mjWARN_INERTIA = 0, // (near) singular inertia matrix
28 | mjWARN_CONTACTFULL, // too many contacts in contact list
29 | mjWARN_CNSTRFULL, // too many constraints
30 | mjWARN_VGEOMFULL, // too many visual geoms
31 | mjWARN_BADQPOS, // bad number in qpos
32 | mjWARN_BADQVEL, // bad number in qvel
33 | mjWARN_BADQACC, // bad number in qacc
34 | mjWARN_BADCTRL, // bad number in ctrl
35 |
36 | mjNWARNING // number of warnings
37 | } mjtWarning;
38 |
39 |
40 | typedef enum mjtTimer_ { // internal timers
41 | // main api
42 | mjTIMER_STEP = 0, // step
43 | mjTIMER_FORWARD, // forward
44 | mjTIMER_INVERSE, // inverse
45 |
46 | // breakdown of step/forward
47 | mjTIMER_POSITION, // fwdPosition
48 | mjTIMER_VELOCITY, // fwdVelocity
49 | mjTIMER_ACTUATION, // fwdActuation
50 | mjTIMER_ACCELERATION, // fwdAcceleration
51 | mjTIMER_CONSTRAINT, // fwdConstraint
52 |
53 | // breakdown of fwdPosition
54 | mjTIMER_POS_KINEMATICS, // kinematics, com, tendon, transmission
55 | mjTIMER_POS_INERTIA, // inertia computations
56 | mjTIMER_POS_COLLISION, // collision detection
57 | mjTIMER_POS_MAKE, // make constraints
58 | mjTIMER_POS_PROJECT, // project constraints
59 |
60 | mjNTIMER // number of timers
61 | } mjtTimer;
62 |
63 |
64 | //---------------------------------- mjContact -----------------------------------------------------
65 |
66 | struct mjContact_ { // result of collision detection functions
67 | // contact parameters set by geom-specific collision detector
68 | mjtNum dist; // distance between nearest points; neg: penetration
69 | mjtNum pos[3]; // position of contact point: midpoint between geoms
70 | mjtNum frame[9]; // normal is in [0-2]
71 |
72 | // contact parameters set by mj_collideGeoms
73 | mjtNum includemargin; // include if distplugin, required for deletion (nplugin x 1)
207 | uintptr_t* plugin_data; // pointer to plugin-managed data structure (nplugin x 1)
208 |
209 | //-------------------------------- POSITION dependent
210 |
211 | // computed by mj_fwdPosition/mj_kinematics
212 | mjtNum* xpos; // Cartesian position of body frame (nbody x 3)
213 | mjtNum* xquat; // Cartesian orientation of body frame (nbody x 4)
214 | mjtNum* xmat; // Cartesian orientation of body frame (nbody x 9)
215 | mjtNum* xipos; // Cartesian position of body com (nbody x 3)
216 | mjtNum* ximat; // Cartesian orientation of body inertia (nbody x 9)
217 | mjtNum* xanchor; // Cartesian position of joint anchor (njnt x 3)
218 | mjtNum* xaxis; // Cartesian joint axis (njnt x 3)
219 | mjtNum* geom_xpos; // Cartesian geom position (ngeom x 3)
220 | mjtNum* geom_xmat; // Cartesian geom orientation (ngeom x 9)
221 | mjtNum* site_xpos; // Cartesian site position (nsite x 3)
222 | mjtNum* site_xmat; // Cartesian site orientation (nsite x 9)
223 | mjtNum* cam_xpos; // Cartesian camera position (ncam x 3)
224 | mjtNum* cam_xmat; // Cartesian camera orientation (ncam x 9)
225 | mjtNum* light_xpos; // Cartesian light position (nlight x 3)
226 | mjtNum* light_xdir; // Cartesian light direction (nlight x 3)
227 |
228 | // computed by mj_fwdPosition/mj_comPos
229 | mjtNum* subtree_com; // center of mass of each subtree (nbody x 3)
230 | mjtNum* cdof; // com-based motion axis of each dof (nv x 6)
231 | mjtNum* cinert; // com-based body inertia and mass (nbody x 10)
232 |
233 | // computed by mj_fwdPosition/mj_tendon
234 | int* ten_wrapadr; // start address of tendon's path (ntendon x 1)
235 | int* ten_wrapnum; // number of wrap points in path (ntendon x 1)
236 | int* ten_J_rownnz; // number of non-zeros in Jacobian row (ntendon x 1)
237 | int* ten_J_rowadr; // row start address in colind array (ntendon x 1)
238 | int* ten_J_colind; // column indices in sparse Jacobian (ntendon x nv)
239 | mjtNum* ten_length; // tendon lengths (ntendon x 1)
240 | mjtNum* ten_J; // tendon Jacobian (ntendon x nv)
241 | int* wrap_obj; // geom id; -1: site; -2: pulley (nwrap*2 x 1)
242 | mjtNum* wrap_xpos; // Cartesian 3D points in all path (nwrap*2 x 3)
243 |
244 | // computed by mj_fwdPosition/mj_transmission
245 | mjtNum* actuator_length; // actuator lengths (nu x 1)
246 | mjtNum* actuator_moment; // actuator moments (nu x nv)
247 |
248 | // computed by mj_fwdPosition/mj_crb
249 | mjtNum* crb; // com-based composite inertia and mass (nbody x 10)
250 | mjtNum* qM; // total inertia (sparse) (nM x 1)
251 |
252 | // computed by mj_fwdPosition/mj_factorM
253 | mjtNum* qLD; // L'*D*L factorization of M (sparse) (nM x 1)
254 | mjtNum* qLDiagInv; // 1/diag(D) (nv x 1)
255 | mjtNum* qLDiagSqrtInv; // 1/sqrt(diag(D)) (nv x 1)
256 |
257 | // computed by mj_collisionTree
258 | mjtByte* bvh_active; // volume has been added to collisions (nbvh x 1)
259 |
260 | //-------------------------------- POSITION, VELOCITY dependent
261 |
262 | // computed by mj_fwdVelocity
263 | mjtNum* ten_velocity; // tendon velocities (ntendon x 1)
264 | mjtNum* actuator_velocity; // actuator velocities (nu x 1)
265 |
266 | // computed by mj_fwdVelocity/mj_comVel
267 | mjtNum* cvel; // com-based velocity [3D rot; 3D tran] (nbody x 6)
268 | mjtNum* cdof_dot; // time-derivative of cdof (nv x 6)
269 |
270 | // computed by mj_fwdVelocity/mj_rne (without acceleration)
271 | mjtNum* qfrc_bias; // C(qpos,qvel) (nv x 1)
272 |
273 | // computed by mj_fwdVelocity/mj_passive
274 | mjtNum* qfrc_passive; // passive force (nv x 1)
275 |
276 | // computed by mj_fwdVelocity/mj_referenceConstraint
277 | mjtNum* efc_vel; // velocity in constraint space: J*qvel (nefc x 1)
278 | mjtNum* efc_aref; // reference pseudo-acceleration (nefc x 1)
279 |
280 | // computed by mj_sensorVel/mj_subtreeVel if needed
281 | mjtNum* subtree_linvel; // linear velocity of subtree com (nbody x 3)
282 | mjtNum* subtree_angmom; // angular momentum about subtree com (nbody x 3)
283 |
284 | // computed by mj_Euler or mj_implicit
285 | mjtNum* qH; // L'*D*L factorization of modified M (nM x 1)
286 | mjtNum* qHDiagInv; // 1/diag(D) of modified M (nv x 1)
287 |
288 | // computed by mj_resetData
289 | int* D_rownnz; // non-zeros in each row (nv x 1)
290 | int* D_rowadr; // address of each row in D_colind (nv x 1)
291 | int* D_colind; // column indices of non-zeros (nD x 1)
292 | int* B_rownnz; // non-zeros in each row (nbody x 1)
293 | int* B_rowadr; // address of each row in B_colind (nbody x 1)
294 | int* B_colind; // column indices of non-zeros (nB x 1)
295 |
296 | // computed by mj_implicit/mj_derivative
297 | mjtNum* qDeriv; // d (passive + actuator - bias) / d qvel (nD x 1)
298 |
299 | // computed by mj_implicit/mju_factorLUSparse
300 | mjtNum* qLU; // sparse LU of (qM - dt*qDeriv) (nD x 1)
301 |
302 | //-------------------------------- POSITION, VELOCITY, CONTROL/ACCELERATION dependent
303 |
304 | // computed by mj_fwdActuation
305 | mjtNum* actuator_force; // actuator force in actuation space (nu x 1)
306 | mjtNum* qfrc_actuator; // actuator force (nv x 1)
307 |
308 | // computed by mj_fwdAcceleration
309 | mjtNum* qfrc_smooth; // net unconstrained force (nv x 1)
310 | mjtNum* qacc_smooth; // unconstrained acceleration (nv x 1)
311 |
312 | // computed by mj_fwdConstraint/mj_inverse
313 | mjtNum* qfrc_constraint; // constraint force (nv x 1)
314 |
315 | // computed by mj_inverse
316 | mjtNum* qfrc_inverse; // net external force; should equal: (nv x 1)
317 | // qfrc_applied + J'*xfrc_applied + qfrc_actuator
318 |
319 | // computed by mj_sensorAcc/mj_rnePostConstraint if needed; rotation:translation format
320 | mjtNum* cacc; // com-based acceleration (nbody x 6)
321 | mjtNum* cfrc_int; // com-based interaction force with parent (nbody x 6)
322 | mjtNum* cfrc_ext; // com-based external force on body (nbody x 6)
323 |
324 | //-------------------------------- ARENA-ALLOCATED ARRAYS
325 |
326 | // computed by mj_collision
327 | mjContact* contact; // list of all detected contacts (ncon x 1)
328 |
329 | // computed by mj_makeConstraint
330 | int* efc_type; // constraint type (mjtConstraint) (nefc x 1)
331 | int* efc_id; // id of object of specified type (nefc x 1)
332 | int* efc_J_rownnz; // number of non-zeros in constraint Jacobian row (nefc x 1)
333 | int* efc_J_rowadr; // row start address in colind array (nefc x 1)
334 | int* efc_J_rowsuper; // number of subsequent rows in supernode (nefc x 1)
335 | int* efc_J_colind; // column indices in constraint Jacobian (nnzJ x 1)
336 | int* efc_JT_rownnz; // number of non-zeros in constraint Jacobian row T (nv x 1)
337 | int* efc_JT_rowadr; // row start address in colind array T (nv x 1)
338 | int* efc_JT_rowsuper; // number of subsequent rows in supernode T (nv x 1)
339 | int* efc_JT_colind; // column indices in constraint Jacobian T (nnzJ x 1)
340 | mjtNum* efc_J; // constraint Jacobian (nnzJ x 1)
341 | mjtNum* efc_JT; // constraint Jacobian transposed (nnzJ x 1)
342 | mjtNum* efc_pos; // constraint position (equality, contact) (nefc x 1)
343 | mjtNum* efc_margin; // inclusion margin (contact) (nefc x 1)
344 | mjtNum* efc_frictionloss; // frictionloss (friction) (nefc x 1)
345 | mjtNum* efc_diagApprox; // approximation to diagonal of A (nefc x 1)
346 | mjtNum* efc_KBIP; // stiffness, damping, impedance, imp' (nefc x 4)
347 | mjtNum* efc_D; // constraint mass (nefc x 1)
348 | mjtNum* efc_R; // inverse constraint mass (nefc x 1)
349 |
350 | // computed by mj_fwdConstraint/mj_inverse
351 | mjtNum* efc_b; // linear cost term: J*qacc_smooth - aref (nefc x 1)
352 | mjtNum* efc_force; // constraint force in constraint space (nefc x 1)
353 | int* efc_state; // constraint state (mjtConstraintState) (nefc x 1)
354 |
355 | // computed by mj_projectConstraint
356 | int* efc_AR_rownnz; // number of non-zeros in AR (nefc x 1)
357 | int* efc_AR_rowadr; // row start address in colind array (nefc x 1)
358 | int* efc_AR_colind; // column indices in sparse AR (nefc x nefc)
359 | mjtNum* efc_AR; // J*inv(M)*J' + R (nefc x nefc)
360 | };
361 | typedef struct mjData_ mjData;
362 |
363 |
364 | //---------------------------------- callback function types ---------------------------------------
365 |
366 | // generic MuJoCo function
367 | typedef void (*mjfGeneric)(const mjModel* m, mjData* d);
368 |
369 | // contact filter: 1- discard, 0- collide
370 | typedef int (*mjfConFilt)(const mjModel* m, mjData* d, int geom1, int geom2);
371 |
372 | // sensor simulation
373 | typedef void (*mjfSensor)(const mjModel* m, mjData* d, int stage);
374 |
375 | // timer
376 | typedef mjtNum (*mjfTime)(void);
377 |
378 | // actuator dynamics, gain, bias
379 | typedef mjtNum (*mjfAct)(const mjModel* m, const mjData* d, int id);
380 |
381 | // collision detection
382 | typedef int (*mjfCollision)(const mjModel* m, const mjData* d,
383 | mjContact* con, int g1, int g2, mjtNum margin);
384 |
385 | #endif // MUJOCO_MJDATA_H_
386 |
--------------------------------------------------------------------------------
/include/mujoco/mjvisualize.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MJVISUALIZE_H_
16 | #define MUJOCO_MJVISUALIZE_H_
17 |
18 | #include
19 | #include
20 | #include
21 |
22 |
23 | #define mjNGROUP 6 // number of geom, site, joint, skin groups with visflags
24 | #define mjMAXLIGHT 100 // maximum number of lights in a scene
25 | #define mjMAXOVERLAY 500 // maximum number of characters in overlay text
26 | #define mjMAXLINE 100 // maximum number of lines per plot
27 | #define mjMAXLINEPNT 1000 // maximum number points per line
28 | #define mjMAXPLANEGRID 200 // maximum number of grid divisions for plane
29 |
30 |
31 | //---------------------------------- primitive types (mjt) -----------------------------------------
32 |
33 | typedef enum mjtCatBit_ { // bitflags for mjvGeom category
34 | mjCAT_STATIC = 1, // model elements in body 0
35 | mjCAT_DYNAMIC = 2, // model elements in all other bodies
36 | mjCAT_DECOR = 4, // decorative geoms
37 | mjCAT_ALL = 7 // select all categories
38 | } mjtCatBit;
39 |
40 |
41 | typedef enum mjtMouse_ { // mouse interaction mode
42 | mjMOUSE_NONE = 0, // no action
43 | mjMOUSE_ROTATE_V, // rotate, vertical plane
44 | mjMOUSE_ROTATE_H, // rotate, horizontal plane
45 | mjMOUSE_MOVE_V, // move, vertical plane
46 | mjMOUSE_MOVE_H, // move, horizontal plane
47 | mjMOUSE_ZOOM, // zoom
48 | mjMOUSE_SELECT // selection
49 | } mjtMouse;
50 |
51 |
52 | typedef enum mjtPertBit_ { // mouse perturbations
53 | mjPERT_TRANSLATE = 1, // translation
54 | mjPERT_ROTATE = 2 // rotation
55 | } mjtPertBit;
56 |
57 |
58 | typedef enum mjtCamera_ { // abstract camera type
59 | mjCAMERA_FREE = 0, // free camera
60 | mjCAMERA_TRACKING, // tracking camera; uses trackbodyid
61 | mjCAMERA_FIXED, // fixed camera; uses fixedcamid
62 | mjCAMERA_USER // user is responsible for setting OpenGL camera
63 | } mjtCamera;
64 |
65 |
66 | typedef enum mjtLabel_ { // object labeling
67 | mjLABEL_NONE = 0, // nothing
68 | mjLABEL_BODY, // body labels
69 | mjLABEL_JOINT, // joint labels
70 | mjLABEL_GEOM, // geom labels
71 | mjLABEL_SITE, // site labels
72 | mjLABEL_CAMERA, // camera labels
73 | mjLABEL_LIGHT, // light labels
74 | mjLABEL_TENDON, // tendon labels
75 | mjLABEL_ACTUATOR, // actuator labels
76 | mjLABEL_CONSTRAINT, // constraint labels
77 | mjLABEL_SKIN, // skin labels
78 | mjLABEL_SELECTION, // selected object
79 | mjLABEL_SELPNT, // coordinates of selection point
80 | mjLABEL_CONTACTPOINT, // contact information
81 | mjLABEL_CONTACTFORCE, // magnitude of contact force
82 |
83 | mjNLABEL // number of label types
84 | } mjtLabel;
85 |
86 |
87 | typedef enum mjtFrame_ { // frame visualization
88 | mjFRAME_NONE = 0, // no frames
89 | mjFRAME_BODY, // body frames
90 | mjFRAME_GEOM, // geom frames
91 | mjFRAME_SITE, // site frames
92 | mjFRAME_CAMERA, // camera frames
93 | mjFRAME_LIGHT, // light frames
94 | mjFRAME_CONTACT, // contact frames
95 | mjFRAME_WORLD, // world frame
96 |
97 | mjNFRAME // number of visualization frames
98 | } mjtFrame;
99 |
100 |
101 | typedef enum mjtVisFlag_ { // flags enabling model element visualization
102 | mjVIS_CONVEXHULL = 0, // mesh convex hull
103 | mjVIS_TEXTURE, // textures
104 | mjVIS_JOINT, // joints
105 | mjVIS_CAMERA, // cameras
106 | mjVIS_ACTUATOR, // actuators
107 | mjVIS_ACTIVATION, // activations
108 | mjVIS_LIGHT, // lights
109 | mjVIS_TENDON, // tendons
110 | mjVIS_RANGEFINDER, // rangefinder sensors
111 | mjVIS_CONSTRAINT, // point constraints
112 | mjVIS_INERTIA, // equivalent inertia boxes
113 | mjVIS_SCLINERTIA, // scale equivalent inertia boxes with mass
114 | mjVIS_PERTFORCE, // perturbation force
115 | mjVIS_PERTOBJ, // perturbation object
116 | mjVIS_CONTACTPOINT, // contact points
117 | mjVIS_CONTACTFORCE, // contact force
118 | mjVIS_CONTACTSPLIT, // split contact force into normal and tangent
119 | mjVIS_TRANSPARENT, // make dynamic geoms more transparent
120 | mjVIS_AUTOCONNECT, // auto connect joints and body coms
121 | mjVIS_COM, // center of mass
122 | mjVIS_SELECT, // selection point
123 | mjVIS_STATIC, // static bodies
124 | mjVIS_SKIN, // skin
125 | mjVIS_MIDPHASE, // mid-phase bounding volume hierarchy
126 |
127 | mjNVISFLAG // number of visualization flags
128 | } mjtVisFlag;
129 |
130 |
131 | typedef enum mjtRndFlag_ { // flags enabling rendering effects
132 | mjRND_SHADOW = 0, // shadows
133 | mjRND_WIREFRAME, // wireframe
134 | mjRND_REFLECTION, // reflections
135 | mjRND_ADDITIVE, // additive transparency
136 | mjRND_SKYBOX, // skybox
137 | mjRND_FOG, // fog
138 | mjRND_HAZE, // haze
139 | mjRND_SEGMENT, // segmentation with random color
140 | mjRND_IDCOLOR, // segmentation with segid+1 color
141 | mjRND_CULL_FACE, // cull backward faces
142 |
143 | mjNRNDFLAG // number of rendering flags
144 | } mjtRndFlag;
145 |
146 |
147 | typedef enum mjtStereo_ { // type of stereo rendering
148 | mjSTEREO_NONE = 0, // no stereo; use left eye only
149 | mjSTEREO_QUADBUFFERED, // quad buffered; revert to side-by-side if no hardware support
150 | mjSTEREO_SIDEBYSIDE // side-by-side
151 | } mjtStereo;
152 |
153 |
154 | //---------------------------------- mjvPerturb ----------------------------------------------------
155 |
156 | struct mjvPerturb_ { // object selection and perturbation
157 | int select; // selected body id; non-positive: none
158 | int skinselect; // selected skin id; negative: none
159 | int active; // perturbation bitmask (mjtPertBit)
160 | int active2; // secondary perturbation bitmask (mjtPertBit)
161 | mjtNum refpos[3]; // reference position for selected object
162 | mjtNum refquat[4]; // reference orientation for selected object
163 | mjtNum refselpos[3]; // reference position for selection point
164 | mjtNum localpos[3]; // selection point in object coordinates
165 | mjtNum localmass; // spatial inertia at selection point
166 | mjtNum scale; // relative mouse motion-to-space scaling (set by initPerturb)
167 | };
168 | typedef struct mjvPerturb_ mjvPerturb;
169 |
170 |
171 | //---------------------------------- mjvCamera -----------------------------------------------------
172 |
173 | struct mjvCamera_ { // abstract camera
174 | // type and ids
175 | int type; // camera type (mjtCamera)
176 | int fixedcamid; // fixed camera id
177 | int trackbodyid; // body id to track
178 |
179 | // abstract camera pose specification
180 | mjtNum lookat[3]; // lookat point
181 | mjtNum distance; // distance to lookat point or tracked body
182 | mjtNum azimuth; // camera azimuth (deg)
183 | mjtNum elevation; // camera elevation (deg)
184 | };
185 | typedef struct mjvCamera_ mjvCamera;
186 |
187 |
188 | //---------------------------------- mjvGLCamera ---------------------------------------------------
189 |
190 | struct mjvGLCamera_ { // OpenGL camera
191 | // camera frame
192 | float pos[3]; // position
193 | float forward[3]; // forward direction
194 | float up[3]; // up direction
195 |
196 | // camera projection
197 | float frustum_center; // hor. center (left,right set to match aspect)
198 | float frustum_bottom; // bottom
199 | float frustum_top; // top
200 | float frustum_near; // near
201 | float frustum_far; // far
202 | };
203 | typedef struct mjvGLCamera_ mjvGLCamera;
204 |
205 |
206 | //---------------------------------- mjvGeom -------------------------------------------------------
207 |
208 | struct mjvGeom_ { // abstract geom
209 | // type info
210 | int type; // geom type (mjtGeom)
211 | int dataid; // mesh, hfield or plane id; -1: none
212 | int objtype; // mujoco object type; mjOBJ_UNKNOWN for decor
213 | int objid; // mujoco object id; -1 for decor
214 | int category; // visual category
215 | int texid; // texture id; -1: no texture
216 | int texuniform; // uniform cube mapping
217 | int texcoord; // mesh geom has texture coordinates
218 | int segid; // segmentation id; -1: not shown
219 |
220 | // OpenGL info
221 | float texrepeat[2]; // texture repetition for 2D mapping
222 | float size[3]; // size parameters
223 | float pos[3]; // Cartesian position
224 | float mat[9]; // Cartesian orientation
225 | float rgba[4]; // color and transparency
226 | float emission; // emission coef
227 | float specular; // specular coef
228 | float shininess; // shininess coef
229 | float reflectance; // reflectance coef
230 | char label[100]; // text label
231 |
232 | // transparency rendering (set internally)
233 | float camdist; // distance to camera (used by sorter)
234 | float modelrbound; // geom rbound from model, 0 if not model geom
235 | mjtByte transparent; // treat geom as transparent
236 | };
237 | typedef struct mjvGeom_ mjvGeom;
238 |
239 |
240 | //---------------------------------- mjvLight ------------------------------------------------------
241 |
242 | struct mjvLight_ { // OpenGL light
243 | float pos[3]; // position rel. to body frame
244 | float dir[3]; // direction rel. to body frame
245 | float attenuation[3]; // OpenGL attenuation (quadratic model)
246 | float cutoff; // OpenGL cutoff
247 | float exponent; // OpenGL exponent
248 | float ambient[3]; // ambient rgb (alpha=1)
249 | float diffuse[3]; // diffuse rgb (alpha=1)
250 | float specular[3]; // specular rgb (alpha=1)
251 | mjtByte headlight; // headlight
252 | mjtByte directional; // directional light
253 | mjtByte castshadow; // does light cast shadows
254 | };
255 | typedef struct mjvLight_ mjvLight;
256 |
257 |
258 | //---------------------------------- mjvOption -----------------------------------------------------
259 |
260 | struct mjvOption_ { // abstract visualization options
261 | int label; // what objects to label (mjtLabel)
262 | int frame; // which frame to show (mjtFrame)
263 | mjtByte geomgroup[mjNGROUP]; // geom visualization by group
264 | mjtByte sitegroup[mjNGROUP]; // site visualization by group
265 | mjtByte jointgroup[mjNGROUP]; // joint visualization by group
266 | mjtByte tendongroup[mjNGROUP]; // tendon visualization by group
267 | mjtByte actuatorgroup[mjNGROUP]; // actuator visualization by group
268 | mjtByte skingroup[mjNGROUP]; // skin visualization by group
269 | mjtByte flags[mjNVISFLAG]; // visualization flags (indexed by mjtVisFlag)
270 | int bvh_depth; // depth of the bounding volume hierarchy to be visualized
271 | };
272 | typedef struct mjvOption_ mjvOption;
273 |
274 |
275 | //---------------------------------- mjvScene ------------------------------------------------------
276 |
277 | struct mjvScene_ { // abstract scene passed to OpenGL renderer
278 | // abstract geoms
279 | int maxgeom; // size of allocated geom buffer
280 | int ngeom; // number of geoms currently in buffer
281 | mjvGeom* geoms; // buffer for geoms (ngeom)
282 | int* geomorder; // buffer for ordering geoms by distance to camera (ngeom)
283 |
284 | // skin data
285 | int nskin; // number of skins
286 | int* skinfacenum; // number of faces in skin (nskin)
287 | int* skinvertadr; // address of skin vertices (nskin)
288 | int* skinvertnum; // number of vertices in skin (nskin)
289 | float* skinvert; // skin vertex data (nskin)
290 | float* skinnormal; // skin normal data (nskin)
291 |
292 | // OpenGL lights
293 | int nlight; // number of lights currently in buffer
294 | mjvLight lights[mjMAXLIGHT]; // buffer for lights (nlight)
295 |
296 | // OpenGL cameras
297 | mjvGLCamera camera[2]; // left and right camera
298 |
299 | // OpenGL model transformation
300 | mjtByte enabletransform; // enable model transformation
301 | float translate[3]; // model translation
302 | float rotate[4]; // model quaternion rotation
303 | float scale; // model scaling
304 |
305 | // OpenGL rendering effects
306 | int stereo; // stereoscopic rendering (mjtStereo)
307 | mjtByte flags[mjNRNDFLAG]; // rendering flags (indexed by mjtRndFlag)
308 |
309 | // framing
310 | int framewidth; // frame pixel width; 0: disable framing
311 | float framergb[3]; // frame color
312 | };
313 | typedef struct mjvScene_ mjvScene;
314 |
315 |
316 | //---------------------------------- mjvFigure -----------------------------------------------------
317 |
318 | struct mjvFigure_ { // abstract 2D figure passed to OpenGL renderer
319 | // enable flags
320 | int flg_legend; // show legend
321 | int flg_ticklabel[2]; // show grid tick labels (x,y)
322 | int flg_extend; // automatically extend axis ranges to fit data
323 | int flg_barplot; // isolated line segments (i.e. GL_LINES)
324 | int flg_selection; // vertical selection line
325 | int flg_symmetric; // symmetric y-axis
326 |
327 | // style settings
328 | float linewidth; // line width
329 | float gridwidth; // grid line width
330 | int gridsize[2]; // number of grid points in (x,y)
331 | float gridrgb[3]; // grid line rgb
332 | float figurergba[4]; // figure color and alpha
333 | float panergba[4]; // pane color and alpha
334 | float legendrgba[4]; // legend color and alpha
335 | float textrgb[3]; // text color
336 | float linergb[mjMAXLINE][3]; // line colors
337 | float range[2][2]; // axis ranges; (min>=max) automatic
338 | char xformat[20]; // x-tick label format for sprintf
339 | char yformat[20]; // y-tick label format for sprintf
340 | char minwidth[20]; // string used to determine min y-tick width
341 |
342 | // text labels
343 | char title[1000]; // figure title; subplots separated with 2+ spaces
344 | char xlabel[100]; // x-axis label
345 | char linename[mjMAXLINE][100]; // line names for legend
346 |
347 | // dynamic settings
348 | int legendoffset; // number of lines to offset legend
349 | int subplot; // selected subplot (for title rendering)
350 | int highlight[2]; // if point is in legend rect, highlight line
351 | int highlightid; // if id>=0 and no point, highlight id
352 | float selection; // selection line x-value
353 |
354 | // line data
355 | int linepnt[mjMAXLINE]; // number of points in line; (0) disable
356 | float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y)
357 |
358 | // output from renderer
359 | int xaxispixel[2]; // range of x-axis in pixels
360 | int yaxispixel[2]; // range of y-axis in pixels
361 | float xaxisdata[2]; // range of x-axis in data units
362 | float yaxisdata[2]; // range of y-axis in data units
363 | };
364 | typedef struct mjvFigure_ mjvFigure;
365 |
366 |
367 | //---------------------------------- mjvSceneState -------------------------------------------------
368 |
369 | struct mjvSceneState_ {
370 | int nbuffer; // size of the buffer in bytes
371 | void* buffer; // heap-allocated memory for all arrays in this struct
372 | int maxgeom; // maximum number of mjvGeom supported by this state object
373 | mjvScene plugincache; // scratch space for vis geoms inserted by plugins
374 |
375 | // fields in mjModel that are necessary to re-render a scene
376 | struct {
377 | int nu;
378 | int na;
379 | int nbody;
380 | int nbvh;
381 | int njnt;
382 | int ngeom;
383 | int nsite;
384 | int ncam;
385 | int nlight;
386 | int nmesh;
387 | int nskin;
388 | int nskinvert;
389 | int nskinface;
390 | int nskinbone;
391 | int nskinbonevert;
392 | int nmat;
393 | int neq;
394 | int ntendon;
395 | int nwrap;
396 | int nsensor;
397 | int nnames;
398 | int nsensordata;
399 |
400 | mjOption opt;
401 | mjVisual vis;
402 | mjStatistic stat;
403 |
404 | int* body_parentid;
405 | int* body_rootid;
406 | int* body_weldid;
407 | int* body_mocapid;
408 | int* body_jntnum;
409 | int* body_jntadr;
410 | int* body_geomnum;
411 | int* body_geomadr;
412 | mjtNum* body_iquat;
413 | mjtNum* body_mass;
414 | mjtNum* body_inertia;
415 | int* body_bvhadr;
416 | int* body_bvhnum;
417 |
418 | int* bvh_depth;
419 | int* bvh_child;
420 | int* bvh_geomid;
421 | mjtNum* bvh_aabb;
422 |
423 | int* jnt_type;
424 | int* jnt_bodyid;
425 | int* jnt_group;
426 |
427 | int* geom_type;
428 | int* geom_bodyid;
429 | int* geom_dataid;
430 | int* geom_matid;
431 | int* geom_group;
432 | mjtNum* geom_size;
433 | mjtNum* geom_aabb;
434 | mjtNum* geom_rbound;
435 | float* geom_rgba;
436 |
437 | int* site_type;
438 | int* site_bodyid;
439 | int* site_matid;
440 | int* site_group;
441 | mjtNum* site_size;
442 | float* site_rgba;
443 |
444 | mjtNum* cam_fovy;
445 | mjtNum* cam_ipd;
446 |
447 | mjtByte* light_directional;
448 | mjtByte* light_castshadow;
449 | mjtByte* light_active;
450 | float* light_attenuation;
451 | float* light_cutoff;
452 | float* light_exponent;
453 | float* light_ambient;
454 | float* light_diffuse;
455 | float* light_specular;
456 |
457 | int* mesh_texcoordadr;
458 | int* mesh_graphadr;
459 |
460 | int* skin_matid;
461 | int* skin_group;
462 | float* skin_rgba;
463 | float* skin_inflate;
464 | int* skin_vertadr;
465 | int* skin_vertnum;
466 | int* skin_texcoordadr;
467 | int* skin_faceadr;
468 | int* skin_facenum;
469 | int* skin_boneadr;
470 | int* skin_bonenum;
471 | float* skin_vert;
472 | int* skin_face;
473 | int* skin_bonevertadr;
474 | int* skin_bonevertnum;
475 | float* skin_bonebindpos;
476 | float* skin_bonebindquat;
477 | int* skin_bonebodyid;
478 | int* skin_bonevertid;
479 | float* skin_bonevertweight;
480 |
481 | int* mat_texid;
482 | mjtByte* mat_texuniform;
483 | float* mat_texrepeat;
484 | float* mat_emission;
485 | float* mat_specular;
486 | float* mat_shininess;
487 | float* mat_reflectance;
488 | float* mat_rgba;
489 |
490 | int* eq_type;
491 | int* eq_obj1id;
492 | int* eq_obj2id;
493 | mjtByte* eq_active;
494 | mjtNum* eq_data;
495 |
496 | int* tendon_num;
497 | int* tendon_matid;
498 | int* tendon_group;
499 | mjtByte* tendon_limited;
500 | mjtNum* tendon_width;
501 | mjtNum* tendon_range;
502 | mjtNum* tendon_stiffness;
503 | mjtNum* tendon_damping;
504 | mjtNum* tendon_frictionloss;
505 | mjtNum* tendon_lengthspring;
506 | float* tendon_rgba;
507 |
508 | int* actuator_trntype;
509 | int* actuator_dyntype;
510 | int* actuator_trnid;
511 | int* actuator_actadr;
512 | int* actuator_actnum;
513 | int* actuator_group;
514 | mjtByte* actuator_ctrllimited;
515 | mjtByte* actuator_actlimited;
516 | mjtNum* actuator_ctrlrange;
517 | mjtNum* actuator_actrange;
518 | mjtNum* actuator_cranklength;
519 |
520 | int* sensor_type;
521 | int* sensor_objid;
522 | int* sensor_adr;
523 |
524 | int* name_bodyadr;
525 | int* name_jntadr;
526 | int* name_geomadr;
527 | int* name_siteadr;
528 | int* name_camadr;
529 | int* name_lightadr;
530 | int* name_eqadr;
531 | int* name_tendonadr;
532 | int* name_actuatoradr;
533 | char* names;
534 | } model;
535 |
536 | // fields in mjData that are necessary to re-render a scene
537 | struct {
538 | mjWarningStat warning[mjNWARNING];
539 |
540 | int nefc;
541 | int ncon;
542 |
543 | mjtNum time;
544 |
545 | mjtNum* act;
546 |
547 | mjtNum* ctrl;
548 | mjtNum* xfrc_applied;
549 |
550 | mjtNum* sensordata;
551 |
552 | mjtNum* xpos;
553 | mjtNum* xquat;
554 | mjtNum* xmat;
555 | mjtNum* xipos;
556 | mjtNum* ximat;
557 | mjtNum* xanchor;
558 | mjtNum* xaxis;
559 | mjtNum* geom_xpos;
560 | mjtNum* geom_xmat;
561 | mjtNum* site_xpos;
562 | mjtNum* site_xmat;
563 | mjtNum* cam_xpos;
564 | mjtNum* cam_xmat;
565 | mjtNum* light_xpos;
566 | mjtNum* light_xdir;
567 |
568 | mjtNum* subtree_com;
569 |
570 | int* ten_wrapadr;
571 | int* ten_wrapnum;
572 | int* wrap_obj;
573 | mjtNum* wrap_xpos;
574 |
575 | mjtByte* bvh_active;
576 |
577 | mjContact* contact;
578 | mjtNum* efc_force;
579 | } data;
580 | };
581 | typedef struct mjvSceneState_ mjvSceneState;
582 |
583 | #endif // MUJOCO_MJVISUALIZE_H_
584 |
--------------------------------------------------------------------------------
/include/mujoco/mjxmacro.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MJXMACRO_H_
16 | #define MUJOCO_MJXMACRO_H_
17 |
18 |
19 | //-------------------------------- mjOption --------------------------------------------------------
20 |
21 | // scalar fields of mjOption
22 | #define MJOPTION_FLOATS \
23 | X( mjtNum, timestep ) \
24 | X( mjtNum, apirate ) \
25 | X( mjtNum, impratio ) \
26 | X( mjtNum, tolerance ) \
27 | X( mjtNum, noslip_tolerance ) \
28 | X( mjtNum, mpr_tolerance ) \
29 | X( mjtNum, density ) \
30 | X( mjtNum, viscosity ) \
31 | X( mjtNum, o_margin ) \
32 |
33 |
34 | #define MJOPTION_INTS \
35 | X( int, integrator ) \
36 | X( int, collision ) \
37 | X( int, cone ) \
38 | X( int, jacobian ) \
39 | X( int, solver ) \
40 | X( int, iterations ) \
41 | X( int, noslip_iterations ) \
42 | X( int, mpr_iterations ) \
43 | X( int, disableflags ) \
44 | X( int, enableflags )
45 |
46 |
47 | #define MJOPTION_SCALARS \
48 | MJOPTION_FLOATS \
49 | MJOPTION_INTS
50 |
51 |
52 | // vector fields of mjOption
53 | #define MJOPTION_VECTORS \
54 | X( gravity, 3 ) \
55 | X( wind, 3 ) \
56 | X( magnetic, 3 ) \
57 | X( o_solref, mjNREF ) \
58 | X( o_solimp, mjNIMP )
59 |
60 |
61 | //-------------------------------- mjModel ---------------------------------------------------------
62 |
63 | // int fields of mjModel
64 | #define MJMODEL_INTS \
65 | X ( nq ) \
66 | X ( nv ) \
67 | XMJV( nu ) \
68 | XMJV( na ) \
69 | XMJV( nbody ) \
70 | XMJV( nbvh ) \
71 | XMJV( njnt ) \
72 | XMJV( ngeom ) \
73 | XMJV( nsite ) \
74 | XMJV( ncam ) \
75 | XMJV( nlight ) \
76 | XMJV( nmesh ) \
77 | X ( nmeshvert ) \
78 | X ( nmeshnormal ) \
79 | X ( nmeshtexcoord ) \
80 | X ( nmeshface ) \
81 | X ( nmeshgraph ) \
82 | XMJV( nskin ) \
83 | XMJV( nskinvert ) \
84 | X ( nskintexvert ) \
85 | XMJV( nskinface ) \
86 | XMJV( nskinbone ) \
87 | XMJV( nskinbonevert ) \
88 | X ( nhfield ) \
89 | X ( nhfielddata ) \
90 | X ( ntex ) \
91 | X ( ntexdata ) \
92 | XMJV( nmat ) \
93 | X ( npair ) \
94 | X ( nexclude ) \
95 | XMJV( neq ) \
96 | XMJV( ntendon ) \
97 | XMJV( nwrap ) \
98 | XMJV( nsensor ) \
99 | X ( nnumeric ) \
100 | X ( nnumericdata ) \
101 | X ( ntext ) \
102 | X ( ntextdata ) \
103 | X ( ntuple ) \
104 | X ( ntupledata ) \
105 | X ( nkey ) \
106 | X ( nmocap ) \
107 | X ( nplugin ) \
108 | X ( npluginattr ) \
109 | X ( nuser_body ) \
110 | X ( nuser_jnt ) \
111 | X ( nuser_geom ) \
112 | X ( nuser_site ) \
113 | X ( nuser_cam ) \
114 | X ( nuser_tendon ) \
115 | X ( nuser_actuator ) \
116 | X ( nuser_sensor ) \
117 | XMJV( nnames ) \
118 | X ( nnames_map ) \
119 | X ( nM ) \
120 | X ( nD ) \
121 | X ( nB ) \
122 | X ( nemax ) \
123 | X ( njmax ) \
124 | X ( nconmax ) \
125 | X ( nstack ) \
126 | X ( nuserdata ) \
127 | XMJV( nsensordata ) \
128 | X ( npluginstate ) \
129 | X ( nbuffer )
130 |
131 |
132 | // define symbols needed in MJMODEL_POINTERS (corresponding to number of columns)
133 | #define MJMODEL_POINTERS_PREAMBLE( m ) \
134 | int nuser_body = m->nuser_body; \
135 | int nuser_jnt = m->nuser_jnt; \
136 | int nuser_geom = m->nuser_geom; \
137 | int nuser_site = m->nuser_site; \
138 | int nuser_cam = m->nuser_cam; \
139 | int nuser_tendon = m->nuser_tendon; \
140 | int nuser_actuator = m->nuser_actuator; \
141 | int nuser_sensor = m->nuser_sensor; \
142 | int nq = m->nq; \
143 | int nv = m->nv; \
144 | int na = m->na; \
145 | int nu = m->nu; \
146 | int nmocap = m->nmocap;
147 |
148 | // macro for annotating that an array size in an X macro is a member of mjModel
149 | // by default this macro does nothing, but users can redefine it as necessary
150 | #define MJ_M(n) n
151 |
152 |
153 | // pointer fields of mjModel
154 | // XMJV means that the field is required to construct mjvScene
155 | // (by default we define XMJV to be the same as X)
156 | #define MJMODEL_POINTERS \
157 | X ( mjtNum, qpos0, nq, 1 ) \
158 | X ( mjtNum, qpos_spring, nq, 1 ) \
159 | XMJV( int, body_parentid, nbody, 1 ) \
160 | XMJV( int, body_rootid, nbody, 1 ) \
161 | XMJV( int, body_weldid, nbody, 1 ) \
162 | XMJV( int, body_mocapid, nbody, 1 ) \
163 | XMJV( int, body_jntnum, nbody, 1 ) \
164 | XMJV( int, body_jntadr, nbody, 1 ) \
165 | X ( int, body_dofnum, nbody, 1 ) \
166 | X ( int, body_dofadr, nbody, 1 ) \
167 | XMJV( int, body_geomnum, nbody, 1 ) \
168 | XMJV( int, body_geomadr, nbody, 1 ) \
169 | X ( mjtByte, body_simple, nbody, 1 ) \
170 | X ( mjtByte, body_sameframe, nbody, 1 ) \
171 | X ( mjtNum, body_pos, nbody, 3 ) \
172 | X ( mjtNum, body_quat, nbody, 4 ) \
173 | X ( mjtNum, body_ipos, nbody, 3 ) \
174 | XMJV( mjtNum, body_iquat, nbody, 4 ) \
175 | XMJV( mjtNum, body_mass, nbody, 1 ) \
176 | X ( mjtNum, body_subtreemass, nbody, 1 ) \
177 | XMJV( mjtNum, body_inertia, nbody, 3 ) \
178 | X ( mjtNum, body_invweight0, nbody, 2 ) \
179 | X ( mjtNum, body_gravcomp, nbody, 1 ) \
180 | X ( mjtNum, body_user, nbody, MJ_M(nuser_body) ) \
181 | X ( int, body_plugin, nbody, 1 ) \
182 | XMJV( int, body_bvhadr, nbody, 1 ) \
183 | XMJV( int, body_bvhnum, nbody, 1 ) \
184 | XMJV( int, bvh_depth, nbvh, 1 ) \
185 | XMJV( int, bvh_child, nbvh, 2 ) \
186 | XMJV( int, bvh_geomid, nbvh, 1 ) \
187 | XMJV( mjtNum, bvh_aabb, nbvh, 6 ) \
188 | XMJV( int, jnt_type, njnt, 1 ) \
189 | X ( int, jnt_qposadr, njnt, 1 ) \
190 | X ( int, jnt_dofadr, njnt, 1 ) \
191 | XMJV( int, jnt_bodyid, njnt, 1 ) \
192 | XMJV( int, jnt_group, njnt, 1 ) \
193 | X ( mjtByte, jnt_limited, njnt, 1 ) \
194 | X ( mjtNum, jnt_solref, njnt, mjNREF ) \
195 | X ( mjtNum, jnt_solimp, njnt, mjNIMP ) \
196 | X ( mjtNum, jnt_pos, njnt, 3 ) \
197 | X ( mjtNum, jnt_axis, njnt, 3 ) \
198 | X ( mjtNum, jnt_stiffness, njnt, 1 ) \
199 | X ( mjtNum, jnt_range, njnt, 2 ) \
200 | X ( mjtNum, jnt_margin, njnt, 1 ) \
201 | X ( mjtNum, jnt_user, njnt, MJ_M(nuser_jnt) ) \
202 | X ( int, dof_bodyid, nv, 1 ) \
203 | X ( int, dof_jntid, nv, 1 ) \
204 | X ( int, dof_parentid, nv, 1 ) \
205 | X ( int, dof_Madr, nv, 1 ) \
206 | X ( int, dof_simplenum, nv, 1 ) \
207 | X ( mjtNum, dof_solref, nv, mjNREF ) \
208 | X ( mjtNum, dof_solimp, nv, mjNIMP ) \
209 | X ( mjtNum, dof_frictionloss, nv, 1 ) \
210 | X ( mjtNum, dof_armature, nv, 1 ) \
211 | X ( mjtNum, dof_damping, nv, 1 ) \
212 | X ( mjtNum, dof_invweight0, nv, 1 ) \
213 | X ( mjtNum, dof_M0, nv, 1 ) \
214 | XMJV( int, geom_type, ngeom, 1 ) \
215 | X ( int, geom_contype, ngeom, 1 ) \
216 | X ( int, geom_conaffinity, ngeom, 1 ) \
217 | X ( int, geom_condim, ngeom, 1 ) \
218 | XMJV( int, geom_bodyid, ngeom, 1 ) \
219 | XMJV( int, geom_dataid, ngeom, 1 ) \
220 | XMJV( int, geom_matid, ngeom, 1 ) \
221 | XMJV( int, geom_group, ngeom, 1 ) \
222 | X ( int, geom_priority, ngeom, 1 ) \
223 | X ( mjtByte, geom_sameframe, ngeom, 1 ) \
224 | X ( mjtNum, geom_solmix, ngeom, 1 ) \
225 | X ( mjtNum, geom_solref, ngeom, mjNREF ) \
226 | X ( mjtNum, geom_solimp, ngeom, mjNIMP ) \
227 | XMJV( mjtNum, geom_size, ngeom, 3 ) \
228 | XMJV( mjtNum, geom_aabb, ngeom, 6 ) \
229 | XMJV( mjtNum, geom_rbound, ngeom, 1 ) \
230 | X ( mjtNum, geom_pos, ngeom, 3 ) \
231 | X ( mjtNum, geom_quat, ngeom, 4 ) \
232 | X ( mjtNum, geom_friction, ngeom, 3 ) \
233 | X ( mjtNum, geom_margin, ngeom, 1 ) \
234 | X ( mjtNum, geom_gap, ngeom, 1 ) \
235 | X ( mjtNum, geom_fluid, ngeom, mjNFLUID ) \
236 | X ( mjtNum, geom_user, ngeom, MJ_M(nuser_geom) ) \
237 | XMJV( float, geom_rgba, ngeom, 4 ) \
238 | XMJV( int, site_type, nsite, 1 ) \
239 | XMJV( int, site_bodyid, nsite, 1 ) \
240 | XMJV( int, site_matid, nsite, 1 ) \
241 | XMJV( int, site_group, nsite, 1 ) \
242 | X ( mjtByte, site_sameframe, nsite, 1 ) \
243 | XMJV( mjtNum, site_size, nsite, 3 ) \
244 | X ( mjtNum, site_pos, nsite, 3 ) \
245 | X ( mjtNum, site_quat, nsite, 4 ) \
246 | X ( mjtNum, site_user, nsite, MJ_M(nuser_site) ) \
247 | XMJV( float, site_rgba, nsite, 4 ) \
248 | X ( int, cam_mode, ncam, 1 ) \
249 | X ( int, cam_bodyid, ncam, 1 ) \
250 | X ( int, cam_targetbodyid, ncam, 1 ) \
251 | X ( mjtNum, cam_pos, ncam, 3 ) \
252 | X ( mjtNum, cam_quat, ncam, 4 ) \
253 | X ( mjtNum, cam_poscom0, ncam, 3 ) \
254 | X ( mjtNum, cam_pos0, ncam, 3 ) \
255 | X ( mjtNum, cam_mat0, ncam, 9 ) \
256 | XMJV( mjtNum, cam_fovy, ncam, 1 ) \
257 | XMJV( mjtNum, cam_ipd, ncam, 1 ) \
258 | X ( mjtNum, cam_user, ncam, MJ_M(nuser_cam) ) \
259 | X ( int, light_mode, nlight, 1 ) \
260 | X ( int, light_bodyid, nlight, 1 ) \
261 | X ( int, light_targetbodyid, nlight, 1 ) \
262 | XMJV( mjtByte, light_directional, nlight, 1 ) \
263 | XMJV( mjtByte, light_castshadow, nlight, 1 ) \
264 | XMJV( mjtByte, light_active, nlight, 1 ) \
265 | X ( mjtNum, light_pos, nlight, 3 ) \
266 | X ( mjtNum, light_dir, nlight, 3 ) \
267 | X ( mjtNum, light_poscom0, nlight, 3 ) \
268 | X ( mjtNum, light_pos0, nlight, 3 ) \
269 | X ( mjtNum, light_dir0, nlight, 3 ) \
270 | XMJV( float, light_attenuation, nlight, 3 ) \
271 | XMJV( float, light_cutoff, nlight, 1 ) \
272 | XMJV( float, light_exponent, nlight, 1 ) \
273 | XMJV( float, light_ambient, nlight, 3 ) \
274 | XMJV( float, light_diffuse, nlight, 3 ) \
275 | XMJV( float, light_specular, nlight, 3 ) \
276 | X ( int, mesh_vertadr, nmesh, 1 ) \
277 | X ( int, mesh_vertnum, nmesh, 1 ) \
278 | X ( int, mesh_normaladr, nmesh, 1 ) \
279 | X ( int, mesh_normalnum, nmesh, 1 ) \
280 | XMJV( int, mesh_texcoordadr, nmesh, 1 ) \
281 | X ( int, mesh_texcoordnum, nmesh, 1 ) \
282 | X ( int, mesh_faceadr, nmesh, 1 ) \
283 | X ( int, mesh_facenum, nmesh, 1 ) \
284 | XMJV( int, mesh_graphadr, nmesh, 1 ) \
285 | X ( float, mesh_vert, nmeshvert, 3 ) \
286 | X ( float, mesh_normal, nmeshnormal, 3 ) \
287 | X ( float, mesh_texcoord, nmeshtexcoord, 2 ) \
288 | X ( int, mesh_face, nmeshface, 3 ) \
289 | X ( int, mesh_facenormal, nmeshface, 3 ) \
290 | X ( int, mesh_facetexcoord, nmeshface, 3 ) \
291 | X ( int, mesh_graph, nmeshgraph, 1 ) \
292 | XMJV( int, skin_matid, nskin, 1 ) \
293 | XMJV( int, skin_group, nskin, 1 ) \
294 | XMJV( float, skin_rgba, nskin, 4 ) \
295 | XMJV( float, skin_inflate, nskin, 1 ) \
296 | XMJV( int, skin_vertadr, nskin, 1 ) \
297 | XMJV( int, skin_vertnum, nskin, 1 ) \
298 | XMJV( int, skin_texcoordadr, nskin, 1 ) \
299 | XMJV( int, skin_faceadr, nskin, 1 ) \
300 | XMJV( int, skin_facenum, nskin, 1 ) \
301 | XMJV( int, skin_boneadr, nskin, 1 ) \
302 | XMJV( int, skin_bonenum, nskin, 1 ) \
303 | XMJV( float, skin_vert, nskinvert, 3 ) \
304 | X ( float, skin_texcoord, nskintexvert, 2 ) \
305 | XMJV( int, skin_face, nskinface, 3 ) \
306 | XMJV( int, skin_bonevertadr, nskinbone, 1 ) \
307 | XMJV( int, skin_bonevertnum, nskinbone, 1 ) \
308 | XMJV( float, skin_bonebindpos, nskinbone, 3 ) \
309 | XMJV( float, skin_bonebindquat, nskinbone, 4 ) \
310 | XMJV( int, skin_bonebodyid, nskinbone, 1 ) \
311 | XMJV( int, skin_bonevertid, nskinbonevert, 1 ) \
312 | XMJV( float, skin_bonevertweight, nskinbonevert, 1 ) \
313 | X ( mjtNum, hfield_size, nhfield, 4 ) \
314 | X ( int, hfield_nrow, nhfield, 1 ) \
315 | X ( int, hfield_ncol, nhfield, 1 ) \
316 | X ( int, hfield_adr, nhfield, 1 ) \
317 | X ( float, hfield_data, nhfielddata, 1 ) \
318 | X ( int, tex_type, ntex, 1 ) \
319 | X ( int, tex_height, ntex, 1 ) \
320 | X ( int, tex_width, ntex, 1 ) \
321 | X ( int, tex_adr, ntex, 1 ) \
322 | X ( mjtByte, tex_rgb, ntexdata, 1 ) \
323 | XMJV( int, mat_texid, nmat, 1 ) \
324 | XMJV( mjtByte, mat_texuniform, nmat, 1 ) \
325 | XMJV( float, mat_texrepeat, nmat, 2 ) \
326 | XMJV( float, mat_emission, nmat, 1 ) \
327 | XMJV( float, mat_specular, nmat, 1 ) \
328 | XMJV( float, mat_shininess, nmat, 1 ) \
329 | XMJV( float, mat_reflectance, nmat, 1 ) \
330 | XMJV( float, mat_rgba, nmat, 4 ) \
331 | X ( int, pair_dim, npair, 1 ) \
332 | X ( int, pair_geom1, npair, 1 ) \
333 | X ( int, pair_geom2, npair, 1 ) \
334 | X ( int, pair_signature, npair, 1 ) \
335 | X ( mjtNum, pair_solref, npair, mjNREF ) \
336 | X ( mjtNum, pair_solimp, npair, mjNIMP ) \
337 | X ( mjtNum, pair_margin, npair, 1 ) \
338 | X ( mjtNum, pair_gap, npair, 1 ) \
339 | X ( mjtNum, pair_friction, npair, 5 ) \
340 | X ( int, exclude_signature, nexclude, 1 ) \
341 | XMJV( int, eq_type, neq, 1 ) \
342 | XMJV( int, eq_obj1id, neq, 1 ) \
343 | XMJV( int, eq_obj2id, neq, 1 ) \
344 | XMJV( mjtByte, eq_active, neq, 1 ) \
345 | X ( mjtNum, eq_solref, neq, mjNREF ) \
346 | X ( mjtNum, eq_solimp, neq, mjNIMP ) \
347 | XMJV( mjtNum, eq_data, neq, mjNEQDATA ) \
348 | X ( int, tendon_adr, ntendon, 1 ) \
349 | XMJV( int, tendon_num, ntendon, 1 ) \
350 | XMJV( int, tendon_matid, ntendon, 1 ) \
351 | XMJV( int, tendon_group, ntendon, 1 ) \
352 | XMJV( mjtByte, tendon_limited, ntendon, 1 ) \
353 | XMJV( mjtNum, tendon_width, ntendon, 1 ) \
354 | X ( mjtNum, tendon_solref_lim, ntendon, mjNREF ) \
355 | X ( mjtNum, tendon_solimp_lim, ntendon, mjNIMP ) \
356 | X ( mjtNum, tendon_solref_fri, ntendon, mjNREF ) \
357 | X ( mjtNum, tendon_solimp_fri, ntendon, mjNIMP ) \
358 | XMJV( mjtNum, tendon_range, ntendon, 2 ) \
359 | X ( mjtNum, tendon_margin, ntendon, 1 ) \
360 | XMJV( mjtNum, tendon_stiffness, ntendon, 1 ) \
361 | XMJV( mjtNum, tendon_damping, ntendon, 1 ) \
362 | XMJV( mjtNum, tendon_frictionloss, ntendon, 1 ) \
363 | XMJV( mjtNum, tendon_lengthspring, ntendon, 2 ) \
364 | X ( mjtNum, tendon_length0, ntendon, 1 ) \
365 | X ( mjtNum, tendon_invweight0, ntendon, 1 ) \
366 | X ( mjtNum, tendon_user, ntendon, MJ_M(nuser_tendon) ) \
367 | XMJV( float, tendon_rgba, ntendon, 4 ) \
368 | X ( int, wrap_type, nwrap, 1 ) \
369 | X ( int, wrap_objid, nwrap, 1 ) \
370 | X ( mjtNum, wrap_prm, nwrap, 1 ) \
371 | XMJV( int, actuator_trntype, nu, 1 ) \
372 | XMJV( int, actuator_dyntype, nu, 1 ) \
373 | X ( int, actuator_gaintype, nu, 1 ) \
374 | X ( int, actuator_biastype, nu, 1 ) \
375 | XMJV( int, actuator_trnid, nu, 2 ) \
376 | XMJV( int, actuator_actadr, nu, 1 ) \
377 | XMJV( int, actuator_actnum, nu, 1 ) \
378 | XMJV( int, actuator_group, nu, 1 ) \
379 | XMJV( mjtByte, actuator_ctrllimited, nu, 1 ) \
380 | X ( mjtByte, actuator_forcelimited, nu, 1 ) \
381 | XMJV( mjtByte, actuator_actlimited, nu, 1 ) \
382 | X ( mjtNum, actuator_dynprm, nu, mjNDYN ) \
383 | X ( mjtNum, actuator_gainprm, nu, mjNGAIN ) \
384 | X ( mjtNum, actuator_biasprm, nu, mjNBIAS ) \
385 | XMJV( mjtNum, actuator_ctrlrange, nu, 2 ) \
386 | X ( mjtNum, actuator_forcerange, nu, 2 ) \
387 | XMJV( mjtNum, actuator_actrange, nu, 2 ) \
388 | X ( mjtNum, actuator_gear, nu, 6 ) \
389 | XMJV( mjtNum, actuator_cranklength, nu, 1 ) \
390 | X ( mjtNum, actuator_acc0, nu, 1 ) \
391 | X ( mjtNum, actuator_length0, nu, 1 ) \
392 | X ( mjtNum, actuator_lengthrange, nu, 2 ) \
393 | X ( mjtNum, actuator_user, nu, MJ_M(nuser_actuator) ) \
394 | X ( int, actuator_plugin, nu, 1 ) \
395 | XMJV( int, sensor_type, nsensor, 1 ) \
396 | X ( int, sensor_datatype, nsensor, 1 ) \
397 | X ( int, sensor_needstage, nsensor, 1 ) \
398 | X ( int, sensor_objtype, nsensor, 1 ) \
399 | XMJV( int, sensor_objid, nsensor, 1 ) \
400 | X ( int, sensor_reftype, nsensor, 1 ) \
401 | X ( int, sensor_refid, nsensor, 1 ) \
402 | X ( int, sensor_dim, nsensor, 1 ) \
403 | XMJV( int, sensor_adr, nsensor, 1 ) \
404 | X ( mjtNum, sensor_cutoff, nsensor, 1 ) \
405 | X ( mjtNum, sensor_noise, nsensor, 1 ) \
406 | X ( mjtNum, sensor_user, nsensor, MJ_M(nuser_sensor) ) \
407 | X ( int, sensor_plugin, nsensor, 1 ) \
408 | X ( int, plugin, nplugin, 1 ) \
409 | X ( int, plugin_stateadr, nplugin, 1 ) \
410 | X ( int, plugin_statenum, nplugin, 1 ) \
411 | X ( char, plugin_attr, npluginattr, 1 ) \
412 | X ( int, plugin_attradr, nplugin, 1 ) \
413 | X ( int, numeric_adr, nnumeric, 1 ) \
414 | X ( int, numeric_size, nnumeric, 1 ) \
415 | X ( mjtNum, numeric_data, nnumericdata, 1 ) \
416 | X ( int, text_adr, ntext, 1 ) \
417 | X ( int, text_size, ntext, 1 ) \
418 | X ( char, text_data, ntextdata, 1 ) \
419 | X ( int, tuple_adr, ntuple, 1 ) \
420 | X ( int, tuple_size, ntuple, 1 ) \
421 | X ( int, tuple_objtype, ntupledata, 1 ) \
422 | X ( int, tuple_objid, ntupledata, 1 ) \
423 | X ( mjtNum, tuple_objprm, ntupledata, 1 ) \
424 | X ( mjtNum, key_time, nkey, 1 ) \
425 | X ( mjtNum, key_qpos, nkey, MJ_M(nq) ) \
426 | X ( mjtNum, key_qvel, nkey, MJ_M(nv) ) \
427 | X ( mjtNum, key_act, nkey, MJ_M(na) ) \
428 | X ( mjtNum, key_mpos, nkey, MJ_M(nmocap)*3 ) \
429 | X ( mjtNum, key_mquat, nkey, MJ_M(nmocap)*4 ) \
430 | X ( mjtNum, key_ctrl, nkey, MJ_M(nu) ) \
431 | XMJV( int, name_bodyadr, nbody, 1 ) \
432 | XMJV( int, name_jntadr, njnt, 1 ) \
433 | XMJV( int, name_geomadr, ngeom, 1 ) \
434 | XMJV( int, name_siteadr, nsite, 1 ) \
435 | XMJV( int, name_camadr, ncam, 1 ) \
436 | XMJV( int, name_lightadr, nlight, 1 ) \
437 | X ( int, name_meshadr, nmesh, 1 ) \
438 | X ( int, name_skinadr, nskin, 1 ) \
439 | X ( int, name_hfieldadr, nhfield, 1 ) \
440 | X ( int, name_texadr, ntex, 1 ) \
441 | X ( int, name_matadr, nmat, 1 ) \
442 | X ( int, name_pairadr, npair, 1 ) \
443 | X ( int, name_excludeadr, nexclude, 1 ) \
444 | XMJV( int, name_eqadr, neq, 1 ) \
445 | XMJV( int, name_tendonadr, ntendon, 1 ) \
446 | XMJV( int, name_actuatoradr, nu, 1 ) \
447 | X ( int, name_sensoradr, nsensor, 1 ) \
448 | X ( int, name_numericadr, nnumeric, 1 ) \
449 | X ( int, name_textadr, ntext, 1 ) \
450 | X ( int, name_tupleadr, ntuple, 1 ) \
451 | X ( int, name_keyadr, nkey, 1 ) \
452 | X ( int, name_pluginadr, nplugin, 1 ) \
453 | XMJV( char, names, nnames, 1 ) \
454 | X ( int, names_map, nnames_map, 1 ) \
455 |
456 | //-------------------------------- mjData ----------------------------------------------------------
457 |
458 | // define symbols needed in MJDATA_POINTERS (corresponding to number of columns)
459 | #define MJDATA_POINTERS_PREAMBLE( m ) \
460 | int nv = m->nv;
461 |
462 |
463 | // pointer fields of mjData
464 | // XMJV means that the field is required to construct mjvScene
465 | // (by default we define XMJV to be the same as X)
466 | #define MJDATA_POINTERS \
467 | X ( mjtNum, qpos, nq, 1 ) \
468 | X ( mjtNum, qvel, nv, 1 ) \
469 | XMJV( mjtNum, act, na, 1 ) \
470 | X ( mjtNum, qacc_warmstart, nv, 1 ) \
471 | X ( mjtNum, plugin_state, npluginstate, 1 ) \
472 | XMJV( mjtNum, ctrl, nu, 1 ) \
473 | X ( mjtNum, qfrc_applied, nv, 1 ) \
474 | XMJV( mjtNum, xfrc_applied, nbody, 6 ) \
475 | X ( mjtNum, mocap_pos, nmocap, 3 ) \
476 | X ( mjtNum, mocap_quat, nmocap, 4 ) \
477 | X ( mjtNum, qacc, nv, 1 ) \
478 | X ( mjtNum, act_dot, na, 1 ) \
479 | X ( mjtNum, userdata, nuserdata, 1 ) \
480 | XMJV( mjtNum, sensordata, nsensordata, 1 ) \
481 | X ( int, plugin, nplugin, 1 ) \
482 | X ( uintptr_t, plugin_data, nplugin, 1 ) \
483 | XMJV( mjtNum, xpos, nbody, 3 ) \
484 | XMJV( mjtNum, xquat, nbody, 4 ) \
485 | XMJV( mjtNum, xmat, nbody, 9 ) \
486 | XMJV( mjtNum, xipos, nbody, 3 ) \
487 | XMJV( mjtNum, ximat, nbody, 9 ) \
488 | XMJV( mjtNum, xanchor, njnt, 3 ) \
489 | XMJV( mjtNum, xaxis, njnt, 3 ) \
490 | XMJV( mjtNum, geom_xpos, ngeom, 3 ) \
491 | XMJV( mjtNum, geom_xmat, ngeom, 9 ) \
492 | XMJV( mjtNum, site_xpos, nsite, 3 ) \
493 | XMJV( mjtNum, site_xmat, nsite, 9 ) \
494 | XMJV( mjtNum, cam_xpos, ncam, 3 ) \
495 | XMJV( mjtNum, cam_xmat, ncam, 9 ) \
496 | XMJV( mjtNum, light_xpos, nlight, 3 ) \
497 | XMJV( mjtNum, light_xdir, nlight, 3 ) \
498 | XMJV( mjtNum, subtree_com, nbody, 3 ) \
499 | X ( mjtNum, cdof, nv, 6 ) \
500 | X ( mjtNum, cinert, nbody, 10 ) \
501 | XMJV( int, ten_wrapadr, ntendon, 1 ) \
502 | XMJV( int, ten_wrapnum, ntendon, 1 ) \
503 | X ( int, ten_J_rownnz, ntendon, 1 ) \
504 | X ( int, ten_J_rowadr, ntendon, 1 ) \
505 | X ( int, ten_J_colind, ntendon, MJ_M(nv) ) \
506 | X ( mjtNum, ten_length, ntendon, 1 ) \
507 | X ( mjtNum, ten_J, ntendon, MJ_M(nv) ) \
508 | XMJV( int, wrap_obj, nwrap, 2 ) \
509 | XMJV( mjtNum, wrap_xpos, nwrap, 6 ) \
510 | X ( mjtNum, actuator_length, nu, 1 ) \
511 | X ( mjtNum, actuator_moment, nu, MJ_M(nv) ) \
512 | X ( mjtNum, crb, nbody, 10 ) \
513 | X ( mjtNum, qM, nM, 1 ) \
514 | X ( mjtNum, qLD, nM, 1 ) \
515 | X ( mjtNum, qLDiagInv, nv, 1 ) \
516 | X ( mjtNum, qLDiagSqrtInv, nv, 1 ) \
517 | XMJV( mjtByte, bvh_active, nbvh, 1 ) \
518 | X ( mjtNum, ten_velocity, ntendon, 1 ) \
519 | X ( mjtNum, actuator_velocity, nu, 1 ) \
520 | X ( mjtNum, cvel, nbody, 6 ) \
521 | X ( mjtNum, cdof_dot, nv, 6 ) \
522 | X ( mjtNum, qfrc_bias, nv, 1 ) \
523 | X ( mjtNum, qfrc_passive, nv, 1 ) \
524 | X ( mjtNum, subtree_linvel, nbody, 3 ) \
525 | X ( mjtNum, subtree_angmom, nbody, 3 ) \
526 | X ( mjtNum, qH, nM, 1 ) \
527 | X ( mjtNum, qHDiagInv, nv, 1 ) \
528 | X ( int, D_rownnz, nv, 1 ) \
529 | X ( int, D_rowadr, nv, 1 ) \
530 | X ( int, D_colind, nD, 1 ) \
531 | X ( int, B_rownnz, nbody, 1 ) \
532 | X ( int, B_rowadr, nbody, 1 ) \
533 | X ( int, B_colind, nB, 1 ) \
534 | X ( mjtNum, qDeriv, nD, 1 ) \
535 | X ( mjtNum, qLU, nD, 1 ) \
536 | X ( mjtNum, actuator_force, nu, 1 ) \
537 | X ( mjtNum, qfrc_actuator, nv, 1 ) \
538 | X ( mjtNum, qfrc_smooth, nv, 1 ) \
539 | X ( mjtNum, qacc_smooth, nv, 1 ) \
540 | X ( mjtNum, qfrc_constraint, nv, 1 ) \
541 | X ( mjtNum, qfrc_inverse, nv, 1 ) \
542 | X ( mjtNum, cacc, nbody, 6 ) \
543 | X ( mjtNum, cfrc_int, nbody, 6 ) \
544 | X ( mjtNum, cfrc_ext, nbody, 6 )
545 |
546 |
547 | // macro for annotating that an array size in an X macro is a member of mjData
548 | // by default this macro does nothing, but users can redefine it as necessary
549 | #define MJ_D(n) n
550 |
551 | // array of contacts
552 | #define MJDATA_ARENA_POINTERS_CONTACT \
553 | X( mjContact, contact, MJ_D(ncon), 1 )
554 |
555 | // array fields of mjData that are used in the primal problem
556 | #define MJDATA_ARENA_POINTERS_PRIMAL \
557 | X(int, efc_type, MJ_D(nefc), 1) \
558 | X(int, efc_id, MJ_D(nefc), 1) \
559 | X(int, efc_J_rownnz, MJ_D(nefc), 1) \
560 | X(int, efc_J_rowadr, MJ_D(nefc), 1) \
561 | X(int, efc_J_rowsuper, MJ_D(nefc), 1) \
562 | X(int, efc_J_colind, MJ_D(nnzJ), 1) \
563 | X(int, efc_JT_rownnz, MJ_M(nv), 1) \
564 | X(int, efc_JT_rowadr, MJ_M(nv), 1) \
565 | X(int, efc_JT_rowsuper, MJ_M(nv), 1) \
566 | X(int, efc_JT_colind, MJ_D(nnzJ), 1) \
567 | X(mjtNum, efc_J, MJ_D(nnzJ), 1) \
568 | X(mjtNum, efc_JT, MJ_D(nnzJ), 1) \
569 | X(mjtNum, efc_pos, MJ_D(nefc), 1) \
570 | X(mjtNum, efc_margin, MJ_D(nefc), 1) \
571 | X(mjtNum, efc_frictionloss, MJ_D(nefc), 1) \
572 | X(mjtNum, efc_diagApprox, MJ_D(nefc), 1) \
573 | X(mjtNum, efc_KBIP, MJ_D(nefc), 4) \
574 | X(mjtNum, efc_D, MJ_D(nefc), 1) \
575 | X(mjtNum, efc_R, MJ_D(nefc), 1) \
576 | X(mjtNum, efc_vel, MJ_D(nefc), 1) \
577 | X(mjtNum, efc_aref, MJ_D(nefc), 1) \
578 | X(mjtNum, efc_b, MJ_D(nefc), 1) \
579 | X(mjtNum, efc_force, MJ_D(nefc), 1) \
580 | X(int, efc_state, MJ_D(nefc), 1)
581 |
582 | // array fields of mjData that are used in the dual problem
583 | #define MJDATA_ARENA_POINTERS_DUAL \
584 | X( int, efc_AR_rownnz, MJ_D(nefc), 1 ) \
585 | X( int, efc_AR_rowadr, MJ_D(nefc), 1 ) \
586 | X( int, efc_AR_colind, MJ_D(nefc), MJ_D(nefc) ) \
587 | X( mjtNum, efc_AR, MJ_D(nefc), MJ_D(nefc) )
588 |
589 | // array fields of mjData that live in d->arena
590 | #define MJDATA_ARENA_POINTERS \
591 | MJDATA_ARENA_POINTERS_CONTACT \
592 | MJDATA_ARENA_POINTERS_PRIMAL \
593 | MJDATA_ARENA_POINTERS_DUAL
594 |
595 |
596 | // scalar fields of mjData
597 | #define MJDATA_SCALAR \
598 | X( int, nstack ) \
599 | X( int, nbuffer ) \
600 | X( int, nplugin ) \
601 | X( int, pstack ) \
602 | X( int, parena ) \
603 | X( int, maxuse_stack ) \
604 | X( int, maxuse_arena ) \
605 | X( int, maxuse_con ) \
606 | X( int, maxuse_efc ) \
607 | X( int, solver_iter ) \
608 | X( int, solver_nnz ) \
609 | X( int, nbodypair_broad ) \
610 | X( int, nbodypair_narrow ) \
611 | X( int, ngeompair_mid ) \
612 | X( int, ngeompair_narrow ) \
613 | X( int, ne ) \
614 | X( int, nf ) \
615 | X( int, nefc ) \
616 | X( int, nnzJ ) \
617 | X( int, ncon ) \
618 | X( mjtNum, time )
619 |
620 |
621 | // vector fields of mjData
622 | #define MJDATA_VECTOR \
623 | X( mjWarningStat, warning, mjNWARNING, 1 ) \
624 | X( mjTimerStat, timer, mjNTIMER, 1 ) \
625 | X( mjSolverStat, solver, mjNSOLVER, 1 ) \
626 | X( mjtNum, solver_fwdinv, 2, 1 ) \
627 | X( mjtNum, energy, 2, 1 )
628 |
629 |
630 | // alias XMJV to be the same as X
631 | // to obtain only X macros for fields that are relevant for mjvScene creation,
632 | // redefine X to expand to nothing, and XMJV to do what's required
633 | #define XMJV X
634 |
635 | #endif // MUJOCO_MJXMACRO_H_
636 |
--------------------------------------------------------------------------------
/include/mujoco/mujoco.h:
--------------------------------------------------------------------------------
1 | // Copyright 2021 DeepMind Technologies Limited
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef MUJOCO_MUJOCO_H_
16 | #define MUJOCO_MUJOCO_H_
17 |
18 | #include
19 |
20 |
21 | // this is a C-API
22 | #if defined(__cplusplus)
23 | extern "C" {
24 | #endif
25 |
26 | // header version; should match the library version as returned by mj_version()
27 | #define mjVERSION_HEADER 235
28 |
29 | // needed to define size_t, fabs and log10
30 | #include
31 | #include
32 |
33 |
34 | // type definitions
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 |
43 |
44 | // macros
45 | #define mjMARKSTACK int _mark = d->pstack;
46 | #define mjFREESTACK d->pstack = _mark;
47 | #define mjDISABLED(x) (m->opt.disableflags & (x))
48 | #define mjENABLED(x) (m->opt.enableflags & (x))
49 |
50 | #ifndef mjPRINTFLIKE
51 | #if defined(__GNUC__)
52 | #define mjPRINTFLIKE(n, m) __attribute__((format(printf, n, m)))
53 | #else
54 | #define mjPRINTFLIKE(n, m)
55 | #endif // __GNUC__
56 | #endif // mjPRINTFLIKE
57 |
58 |
59 | // user error and memory handlers
60 | MJAPI extern void (*mju_user_error)(const char*);
61 | MJAPI extern void (*mju_user_warning)(const char*);
62 | MJAPI extern void* (*mju_user_malloc)(size_t);
63 | MJAPI extern void (*mju_user_free)(void*);
64 |
65 |
66 | // callbacks extending computation pipeline
67 | MJAPI extern mjfGeneric mjcb_passive;
68 | MJAPI extern mjfGeneric mjcb_control;
69 | MJAPI extern mjfConFilt mjcb_contactfilter;
70 | MJAPI extern mjfSensor mjcb_sensor;
71 | MJAPI extern mjfTime mjcb_time;
72 | MJAPI extern mjfAct mjcb_act_dyn;
73 | MJAPI extern mjfAct mjcb_act_gain;
74 | MJAPI extern mjfAct mjcb_act_bias;
75 |
76 |
77 | // collision function table
78 | MJAPI extern mjfCollision mjCOLLISIONFUNC[mjNGEOMTYPES][mjNGEOMTYPES];
79 |
80 |
81 | // string names
82 | MJAPI extern const char* mjDISABLESTRING[mjNDISABLE];
83 | MJAPI extern const char* mjENABLESTRING[mjNENABLE];
84 | MJAPI extern const char* mjTIMERSTRING[mjNTIMER];
85 | MJAPI extern const char* mjLABELSTRING[mjNLABEL];
86 | MJAPI extern const char* mjFRAMESTRING[mjNFRAME];
87 | MJAPI extern const char* mjVISSTRING[mjNVISFLAG][3];
88 | MJAPI extern const char* mjRNDSTRING[mjNRNDFLAG][3];
89 |
90 |
91 | //---------------------------------- Virtual file system -------------------------------------------
92 |
93 | // Initialize VFS to empty (no deallocation).
94 | MJAPI void mj_defaultVFS(mjVFS* vfs);
95 |
96 | // Add file to VFS, return 0: success, 1: full, 2: repeated name, -1: failed to load.
97 | MJAPI int mj_addFileVFS(mjVFS* vfs, const char* directory, const char* filename);
98 |
99 | // Make empty file in VFS, return 0: success, 1: full, 2: repeated name.
100 | MJAPI int mj_makeEmptyFileVFS(mjVFS* vfs, const char* filename, int filesize);
101 |
102 | // Return file index in VFS, or -1 if not found in VFS.
103 | MJAPI int mj_findFileVFS(const mjVFS* vfs, const char* filename);
104 |
105 | // Delete file from VFS, return 0: success, -1: not found in VFS.
106 | MJAPI int mj_deleteFileVFS(mjVFS* vfs, const char* filename);
107 |
108 | // Delete all files from VFS.
109 | MJAPI void mj_deleteVFS(mjVFS* vfs);
110 |
111 |
112 | //---------------------------------- Parse and compile ---------------------------------------------
113 |
114 | // Parse XML file in MJCF or URDF format, compile it, return low-level model.
115 | // If vfs is not NULL, look up files in vfs before reading from disk.
116 | // If error is not NULL, it must have size error_sz.
117 | MJAPI mjModel* mj_loadXML(const char* filename, const mjVFS* vfs, char* error, int error_sz);
118 |
119 | // Update XML data structures with info from low-level model, save as MJCF.
120 | // If error is not NULL, it must have size error_sz.
121 | MJAPI int mj_saveLastXML(const char* filename, const mjModel* m, char* error, int error_sz);
122 |
123 | // Free last XML model if loaded. Called internally at each load.
124 | MJAPI void mj_freeLastXML(void);
125 |
126 | // Print internal XML schema as plain text or HTML, with style-padding or .
127 | MJAPI int mj_printSchema(const char* filename, char* buffer, int buffer_sz,
128 | int flg_html, int flg_pad);
129 |
130 |
131 | //---------------------------------- Main simulation -----------------------------------------------
132 |
133 | // Advance simulation, use control callback to obtain external force and control.
134 | MJAPI void mj_step(const mjModel* m, mjData* d);
135 |
136 | // Advance simulation in two steps: before external force and control is set by user.
137 | MJAPI void mj_step1(const mjModel* m, mjData* d);
138 |
139 | // Advance simulation in two steps: after external force and control is set by user.
140 | MJAPI void mj_step2(const mjModel* m, mjData* d);
141 |
142 | // Forward dynamics: same as mj_step but do not integrate in time.
143 | MJAPI void mj_forward(const mjModel* m, mjData* d);
144 |
145 | // Inverse dynamics: qacc must be set before calling.
146 | MJAPI void mj_inverse(const mjModel* m, mjData* d);
147 |
148 | // Forward dynamics with skip; skipstage is mjtStage.
149 | MJAPI void mj_forwardSkip(const mjModel* m, mjData* d, int skipstage, int skipsensor);
150 |
151 | // Inverse dynamics with skip; skipstage is mjtStage.
152 | MJAPI void mj_inverseSkip(const mjModel* m, mjData* d, int skipstage, int skipsensor);
153 |
154 |
155 | //---------------------------------- Initialization ------------------------------------------------
156 |
157 | // Set default options for length range computation.
158 | MJAPI void mj_defaultLROpt(mjLROpt* opt);
159 |
160 | // Set solver parameters to default values.
161 | MJAPI void mj_defaultSolRefImp(mjtNum* solref, mjtNum* solimp);
162 |
163 | // Set physics options to default values.
164 | MJAPI void mj_defaultOption(mjOption* opt);
165 |
166 | // Set visual options to default values.
167 | MJAPI void mj_defaultVisual(mjVisual* vis);
168 |
169 | // Copy mjModel, allocate new if dest is NULL.
170 | MJAPI mjModel* mj_copyModel(mjModel* dest, const mjModel* src);
171 |
172 | // Save model to binary MJB file or memory buffer; buffer has precedence when given.
173 | MJAPI void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buffer_sz);
174 |
175 | // Load model from binary MJB file.
176 | // If vfs is not NULL, look up file in vfs before reading from disk.
177 | MJAPI mjModel* mj_loadModel(const char* filename, const mjVFS* vfs);
178 |
179 | // Free memory allocation in model.
180 | MJAPI void mj_deleteModel(mjModel* m);
181 |
182 | // Return size of buffer needed to hold model.
183 | MJAPI int mj_sizeModel(const mjModel* m);
184 |
185 | // Allocate mjData corresponding to given model.
186 | // If the model buffer is unallocated the initial configuration will not be set.
187 | MJAPI mjData* mj_makeData(const mjModel* m);
188 |
189 | // Copy mjData.
190 | // m is only required to contain the size fields from MJMODEL_INTS.
191 | MJAPI mjData* mj_copyData(mjData* dest, const mjModel* m, const mjData* src);
192 |
193 | // Reset data to defaults.
194 | MJAPI void mj_resetData(const mjModel* m, mjData* d);
195 |
196 | // Reset data to defaults, fill everything else with debug_value.
197 | MJAPI void mj_resetDataDebug(const mjModel* m, mjData* d, unsigned char debug_value);
198 |
199 | // Reset data, set fields from specified keyframe.
200 | MJAPI void mj_resetDataKeyframe(const mjModel* m, mjData* d, int key);
201 |
202 | // Allocate array of mjtNums on mjData stack. Call mju_error on stack overflow.
203 | MJAPI mjtNum* mj_stackAlloc(mjData* d, int size);
204 |
205 | // Allocate array of ints on mjData stack. Call mju_error on stack overflow.
206 | MJAPI int* mj_stackAllocInt(mjData* d, int size);
207 |
208 | // Free memory allocation in mjData.
209 | MJAPI void mj_deleteData(mjData* d);
210 |
211 | // Reset all callbacks to NULL pointers (NULL is the default).
212 | MJAPI void mj_resetCallbacks(void);
213 |
214 | // Set constant fields of mjModel, corresponding to qpos0 configuration.
215 | MJAPI void mj_setConst(mjModel* m, mjData* d);
216 |
217 | // Set actuator_lengthrange for specified actuator; return 1 if ok, 0 if error.
218 | MJAPI int mj_setLengthRange(mjModel* m, mjData* d, int index,
219 | const mjLROpt* opt, char* error, int error_sz);
220 |
221 |
222 | //---------------------------------- Printing ------------------------------------------------------
223 |
224 | // Print mjModel to text file, specifying format.
225 | // float_format must be a valid printf-style format string for a single float value.
226 | MJAPI void mj_printFormattedModel(const mjModel* m, const char* filename, const char* float_format);
227 |
228 | // Print model to text file.
229 | MJAPI void mj_printModel(const mjModel* m, const char* filename);
230 |
231 | // Print mjData to text file, specifying format.
232 | // float_format must be a valid printf-style format string for a single float value
233 | MJAPI void mj_printFormattedData(const mjModel* m, mjData* d, const char* filename,
234 | const char* float_format);
235 |
236 | // Print data to text file.
237 | MJAPI void mj_printData(const mjModel* m, mjData* d, const char* filename);
238 |
239 | // Print matrix to screen.
240 | MJAPI void mju_printMat(const mjtNum* mat, int nr, int nc);
241 |
242 | // Print sparse matrix to screen.
243 | MJAPI void mju_printMatSparse(const mjtNum* mat, int nr,
244 | const int* rownnz, const int* rowadr, const int* colind);
245 |
246 |
247 | //---------------------------------- Components ----------------------------------------------------
248 |
249 | // Run position-dependent computations.
250 | MJAPI void mj_fwdPosition(const mjModel* m, mjData* d);
251 |
252 | // Run velocity-dependent computations.
253 | MJAPI void mj_fwdVelocity(const mjModel* m, mjData* d);
254 |
255 | // Compute actuator force qfrc_actuator.
256 | MJAPI void mj_fwdActuation(const mjModel* m, mjData* d);
257 |
258 | // Add up all non-constraint forces, compute qacc_smooth.
259 | MJAPI void mj_fwdAcceleration(const mjModel* m, mjData* d);
260 |
261 | // Run selected constraint solver.
262 | MJAPI void mj_fwdConstraint(const mjModel* m, mjData* d);
263 |
264 | // Euler integrator, semi-implicit in velocity.
265 | MJAPI void mj_Euler(const mjModel* m, mjData* d);
266 |
267 | // Runge-Kutta explicit order-N integrator.
268 | MJAPI void mj_RungeKutta(const mjModel* m, mjData* d, int N);
269 |
270 | // Run position-dependent computations in inverse dynamics.
271 | MJAPI void mj_invPosition(const mjModel* m, mjData* d);
272 |
273 | // Run velocity-dependent computations in inverse dynamics.
274 | MJAPI void mj_invVelocity(const mjModel* m, mjData* d);
275 |
276 | // Apply the analytical formula for inverse constraint dynamics.
277 | MJAPI void mj_invConstraint(const mjModel* m, mjData* d);
278 |
279 | // Compare forward and inverse dynamics, save results in fwdinv.
280 | MJAPI void mj_compareFwdInv(const mjModel* m, mjData* d);
281 |
282 |
283 | //---------------------------------- Sub components ------------------------------------------------
284 |
285 | // Evaluate position-dependent sensors.
286 | MJAPI void mj_sensorPos(const mjModel* m, mjData* d);
287 |
288 | // Evaluate velocity-dependent sensors.
289 | MJAPI void mj_sensorVel(const mjModel* m, mjData* d);
290 |
291 | // Evaluate acceleration and force-dependent sensors.
292 | MJAPI void mj_sensorAcc(const mjModel* m, mjData* d);
293 |
294 | // Evaluate position-dependent energy (potential).
295 | MJAPI void mj_energyPos(const mjModel* m, mjData* d);
296 |
297 | // Evaluate velocity-dependent energy (kinetic).
298 | MJAPI void mj_energyVel(const mjModel* m, mjData* d);
299 |
300 | // Check qpos, reset if any element is too big or nan.
301 | MJAPI void mj_checkPos(const mjModel* m, mjData* d);
302 |
303 | // Check qvel, reset if any element is too big or nan.
304 | MJAPI void mj_checkVel(const mjModel* m, mjData* d);
305 |
306 | // Check qacc, reset if any element is too big or nan.
307 | MJAPI void mj_checkAcc(const mjModel* m, mjData* d);
308 |
309 | // Run forward kinematics.
310 | MJAPI void mj_kinematics(const mjModel* m, mjData* d);
311 |
312 | // Map inertias and motion dofs to global frame centered at CoM.
313 | MJAPI void mj_comPos(const mjModel* m, mjData* d);
314 |
315 | // Compute camera and light positions and orientations.
316 | MJAPI void mj_camlight(const mjModel* m, mjData* d);
317 |
318 | // Compute tendon lengths, velocities and moment arms.
319 | MJAPI void mj_tendon(const mjModel* m, mjData* d);
320 |
321 | // Compute actuator transmission lengths and moments.
322 | MJAPI void mj_transmission(const mjModel* m, mjData* d);
323 |
324 | // Run composite rigid body inertia algorithm (CRB).
325 | MJAPI void mj_crb(const mjModel* m, mjData* d);
326 |
327 | // Compute sparse L'*D*L factorizaton of inertia matrix.
328 | MJAPI void mj_factorM(const mjModel* m, mjData* d);
329 |
330 | // Solve linear system M * x = y using factorization: x = inv(L'*D*L)*y
331 | MJAPI void mj_solveM(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
332 |
333 | // Half of linear solve: x = sqrt(inv(D))*inv(L')*y
334 | MJAPI void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
335 |
336 | // Compute cvel, cdof_dot.
337 | MJAPI void mj_comVel(const mjModel* m, mjData* d);
338 |
339 | // Compute qfrc_passive from spring-dampers, viscosity and density.
340 | MJAPI void mj_passive(const mjModel* m, mjData* d);
341 |
342 | // subtree linear velocity and angular momentum
343 | MJAPI void mj_subtreeVel(const mjModel* m, mjData* d);
344 |
345 | // RNE: compute M(qpos)*qacc + C(qpos,qvel); flg_acc=0 removes inertial term.
346 | MJAPI void mj_rne(const mjModel* m, mjData* d, int flg_acc, mjtNum* result);
347 |
348 | // RNE with complete data: compute cacc, cfrc_ext, cfrc_int.
349 | MJAPI void mj_rnePostConstraint(const mjModel* m, mjData* d);
350 |
351 | // Run collision detection.
352 | MJAPI void mj_collision(const mjModel* m, mjData* d);
353 |
354 | // Construct constraints.
355 | MJAPI void mj_makeConstraint(const mjModel* m, mjData* d);
356 |
357 | // Compute inverse constraint inertia efc_AR.
358 | MJAPI void mj_projectConstraint(const mjModel* m, mjData* d);
359 |
360 | // Compute efc_vel, efc_aref.
361 | MJAPI void mj_referenceConstraint(const mjModel* m, mjData* d);
362 |
363 | // Compute efc_state, efc_force, qfrc_constraint, and (optionally) cone Hessians.
364 | // If cost is not NULL, set *cost = s(jar) where jar = Jac*qacc-aref.
365 | MJAPI void mj_constraintUpdate(const mjModel* m, mjData* d, const mjtNum* jar,
366 | mjtNum cost[1], int flg_coneHessian);
367 |
368 |
369 | //---------------------------------- Support -------------------------------------------------------
370 |
371 | // Add contact to d->contact list; return 0 if success; 1 if buffer full.
372 | MJAPI int mj_addContact(const mjModel* m, mjData* d, const mjContact* con);
373 |
374 | // Determine type of friction cone.
375 | MJAPI int mj_isPyramidal(const mjModel* m);
376 |
377 | // Determine type of constraint Jacobian.
378 | MJAPI int mj_isSparse(const mjModel* m);
379 |
380 | // Determine type of solver (PGS is dual, CG and Newton are primal).
381 | MJAPI int mj_isDual(const mjModel* m);
382 |
383 | // Multiply dense or sparse constraint Jacobian by vector.
384 | MJAPI void mj_mulJacVec(const mjModel* m, mjData* d, mjtNum* res, const mjtNum* vec);
385 |
386 | // Multiply dense or sparse constraint Jacobian transpose by vector.
387 | MJAPI void mj_mulJacTVec(const mjModel* m, mjData* d, mjtNum* res, const mjtNum* vec);
388 |
389 | // Compute 3/6-by-nv end-effector Jacobian of global point attached to given body.
390 | MJAPI void mj_jac(const mjModel* m, const mjData* d, mjtNum* jacp, mjtNum* jacr,
391 | const mjtNum point[3], int body);
392 |
393 | // Compute body frame end-effector Jacobian.
394 | MJAPI void mj_jacBody(const mjModel* m, const mjData* d, mjtNum* jacp, mjtNum* jacr, int body);
395 |
396 | // Compute body center-of-mass end-effector Jacobian.
397 | MJAPI void mj_jacBodyCom(const mjModel* m, const mjData* d, mjtNum* jacp, mjtNum* jacr, int body);
398 |
399 | // Compute subtree center-of-mass end-effector Jacobian.
400 | MJAPI void mj_jacSubtreeCom(const mjModel* m, mjData* d, mjtNum* jacp, int body);
401 |
402 | // Compute geom end-effector Jacobian.
403 | MJAPI void mj_jacGeom(const mjModel* m, const mjData* d, mjtNum* jacp, mjtNum* jacr, int geom);
404 |
405 | // Compute site end-effector Jacobian.
406 | MJAPI void mj_jacSite(const mjModel* m, const mjData* d, mjtNum* jacp, mjtNum* jacr, int site);
407 |
408 | // Compute translation end-effector Jacobian of point, and rotation Jacobian of axis.
409 | MJAPI void mj_jacPointAxis(const mjModel* m, mjData* d, mjtNum* jacPoint, mjtNum* jacAxis,
410 | const mjtNum point[3], const mjtNum axis[3], int body);
411 |
412 | // Get id of object with the specified mjtObj type and name, returns -1 if id not found.
413 | MJAPI int mj_name2id(const mjModel* m, int type, const char* name);
414 |
415 | // Get name of object with the specified mjtObj type and id, returns NULL if name not found.
416 | MJAPI const char* mj_id2name(const mjModel* m, int type, int id);
417 |
418 | // Convert sparse inertia matrix M into full (i.e. dense) matrix.
419 | MJAPI void mj_fullM(const mjModel* m, mjtNum* dst, const mjtNum* M);
420 |
421 | // Multiply vector by inertia matrix.
422 | MJAPI void mj_mulM(const mjModel* m, const mjData* d, mjtNum* res, const mjtNum* vec);
423 |
424 | // Multiply vector by (inertia matrix)^(1/2).
425 | MJAPI void mj_mulM2(const mjModel* m, const mjData* d, mjtNum* res, const mjtNum* vec);
426 |
427 | // Add inertia matrix to destination matrix.
428 | // Destination can be sparse uncompressed, or dense when all int* are NULL
429 | MJAPI void mj_addM(const mjModel* m, mjData* d, mjtNum* dst, int* rownnz, int* rowadr, int* colind);
430 |
431 | // Apply Cartesian force and torque (outside xfrc_applied mechanism).
432 | MJAPI void mj_applyFT(const mjModel* m, mjData* d, const mjtNum force[3], const mjtNum torque[3],
433 | const mjtNum point[3], int body, mjtNum* qfrc_target);
434 |
435 | // Compute object 6D velocity (rot:lin) in object-centered frame, world/local orientation.
436 | MJAPI void mj_objectVelocity(const mjModel* m, const mjData* d,
437 | int objtype, int objid, mjtNum res[6], int flg_local);
438 |
439 | // Compute object 6D acceleration (rot:lin) in object-centered frame, world/local orientation.
440 | MJAPI void mj_objectAcceleration(const mjModel* m, const mjData* d,
441 | int objtype, int objid, mjtNum res[6], int flg_local);
442 |
443 | // Extract 6D force:torque given contact id, in the contact frame.
444 | MJAPI void mj_contactForce(const mjModel* m, const mjData* d, int id, mjtNum result[6]);
445 |
446 | // Compute velocity by finite-differencing two positions.
447 | MJAPI void mj_differentiatePos(const mjModel* m, mjtNum* qvel, mjtNum dt,
448 | const mjtNum* qpos1, const mjtNum* qpos2);
449 |
450 | // Integrate position with given velocity.
451 | MJAPI void mj_integratePos(const mjModel* m, mjtNum* qpos, const mjtNum* qvel, mjtNum dt);
452 |
453 | // Normalize all quaternions in qpos-type vector.
454 | MJAPI void mj_normalizeQuat(const mjModel* m, mjtNum* qpos);
455 |
456 | // Map from body local to global Cartesian coordinates.
457 | MJAPI void mj_local2Global(mjData* d, mjtNum xpos[3], mjtNum xmat[9], const mjtNum pos[3],
458 | const mjtNum quat[4], int body, mjtByte sameframe);
459 |
460 | // Sum all body masses.
461 | MJAPI mjtNum mj_getTotalmass(const mjModel* m);
462 |
463 | // Scale body masses and inertias to achieve specified total mass.
464 | MJAPI void mj_setTotalmass(mjModel* m, mjtNum newmass);
465 |
466 | // Return a config attribute value of a plugin instance;
467 | // NULL: invalid plugin instance ID or attribute name
468 | MJAPI const char* mj_getPluginConfig(const mjModel* m, int plugin_id, const char* attrib);
469 |
470 | // Load a dynamic library. The dynamic library is assumed to register one or more plugins.
471 | MJAPI void mj_loadPluginLibrary(const char* path);
472 |
473 | // Scan a directory and load all dynamic libraries. Dynamic libraries in the specified directory
474 | // are assumed to register one or more plugins. Optionally, if a callback is specified, it is called
475 | // for each dynamic library encountered that registers plugins.
476 | MJAPI void mj_loadAllPluginLibraries(const char* directory, mjfPluginLibraryLoadCallback callback);
477 |
478 | // Return version number: 1.0.2 is encoded as 102.
479 | MJAPI int mj_version(void);
480 |
481 | // Return the current version of MuJoCo as a null-terminated string.
482 | MJAPI const char* mj_versionString();
483 |
484 |
485 | //---------------------------------- Ray collisions ------------------------------------------------
486 |
487 | // Intersect ray (pnt+x*vec, x>=0) with visible geoms, except geoms in bodyexclude.
488 | // Return distance (x) to nearest surface, or -1 if no intersection and output geomid.
489 | // geomgroup, flg_static are as in mjvOption; geomgroup==NULL skips group exclusion.
490 | MJAPI mjtNum mj_ray(const mjModel* m, const mjData* d, const mjtNum pnt[3], const mjtNum vec[3],
491 | const mjtByte* geomgroup, mjtByte flg_static, int bodyexclude,
492 | int geomid[1]);
493 |
494 | // Intersect ray with hfield, return nearest distance or -1 if no intersection.
495 | MJAPI mjtNum mj_rayHfield(const mjModel* m, const mjData* d, int geomid,
496 | const mjtNum pnt[3], const mjtNum vec[3]);
497 |
498 | // Intersect ray with mesh, return nearest distance or -1 if no intersection.
499 | MJAPI mjtNum mj_rayMesh(const mjModel* m, const mjData* d, int geomid,
500 | const mjtNum pnt[3], const mjtNum vec[3]);
501 |
502 | // Intersect ray with pure geom, return nearest distance or -1 if no intersection.
503 | MJAPI mjtNum mju_rayGeom(const mjtNum pos[3], const mjtNum mat[9], const mjtNum size[3],
504 | const mjtNum pnt[3], const mjtNum vec[3], int geomtype);
505 |
506 | // Intersect ray with skin, return nearest distance or -1 if no intersection,
507 | // and also output nearest vertex id.
508 | MJAPI mjtNum mju_raySkin(int nface, int nvert, const int* face, const float* vert,
509 | const mjtNum pnt[3], const mjtNum vec[3], int vertid[1]);
510 |
511 |
512 | //---------------------------------- Interaction ---------------------------------------------------
513 |
514 | // Set default camera.
515 | MJAPI void mjv_defaultCamera(mjvCamera* cam);
516 |
517 | // Set default free camera.
518 | MJAPI void mjv_defaultFreeCamera(const mjModel* m, mjvCamera* cam);
519 |
520 | // Set default perturbation.
521 | MJAPI void mjv_defaultPerturb(mjvPerturb* pert);
522 |
523 | // Transform pose from room to model space.
524 | MJAPI void mjv_room2model(mjtNum modelpos[3], mjtNum modelquat[4], const mjtNum roompos[3],
525 | const mjtNum roomquat[4], const mjvScene* scn);
526 |
527 | // Transform pose from model to room space.
528 | MJAPI void mjv_model2room(mjtNum roompos[3], mjtNum roomquat[4], const mjtNum modelpos[3],
529 | const mjtNum modelquat[4], const mjvScene* scn);
530 |
531 | // Get camera info in model space; average left and right OpenGL cameras.
532 | MJAPI void mjv_cameraInModel(mjtNum headpos[3], mjtNum forward[3], mjtNum up[3],
533 | const mjvScene* scn);
534 |
535 | // Get camera info in room space; average left and right OpenGL cameras.
536 | MJAPI void mjv_cameraInRoom(mjtNum headpos[3], mjtNum forward[3], mjtNum up[3],
537 | const mjvScene* scn);
538 |
539 | // Get frustum height at unit distance from camera; average left and right OpenGL cameras.
540 | MJAPI mjtNum mjv_frustumHeight(const mjvScene* scn);
541 |
542 | // Rotate 3D vec in horizontal plane by angle between (0,1) and (forward_x,forward_y).
543 | MJAPI void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]);
544 |
545 | // Move camera with mouse; action is mjtMouse.
546 | MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
547 | const mjvScene* scn, mjvCamera* cam);
548 |
549 | // Move camera with mouse given a scene state; action is mjtMouse.
550 | MJAPI void mjv_moveCameraFromState(const mjvSceneState* scnstate, int action,
551 | mjtNum reldx, mjtNum reldy,
552 | const mjvScene* scn, mjvCamera* cam);
553 |
554 | // Move perturb object with mouse; action is mjtMouse.
555 | MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
556 | mjtNum reldy, const mjvScene* scn, mjvPerturb* pert);
557 |
558 | // Move perturb object with mouse given a scene state; action is mjtMouse.
559 | MJAPI void mjv_movePerturbFromState(const mjvSceneState* scnstate, int action,
560 | mjtNum reldx, mjtNum reldy,
561 | const mjvScene* scn, mjvPerturb* pert);
562 |
563 | // Move model with mouse; action is mjtMouse.
564 | MJAPI void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
565 | const mjtNum roomup[3], mjvScene* scn);
566 |
567 | // Copy perturb pos,quat from selected body; set scale for perturbation.
568 | MJAPI void mjv_initPerturb(const mjModel* m, mjData* d, const mjvScene* scn, mjvPerturb* pert);
569 |
570 | // Set perturb pos,quat in d->mocap when selected body is mocap, and in d->qpos otherwise.
571 | // Write d->qpos only if flg_paused and subtree root for selected body has free joint.
572 | MJAPI void mjv_applyPerturbPose(const mjModel* m, mjData* d, const mjvPerturb* pert,
573 | int flg_paused);
574 |
575 | // Set perturb force,torque in d->xfrc_applied, if selected body is dynamic.
576 | MJAPI void mjv_applyPerturbForce(const mjModel* m, mjData* d, const mjvPerturb* pert);
577 |
578 | // Return the average of two OpenGL cameras.
579 | MJAPI mjvGLCamera mjv_averageCamera(const mjvGLCamera* cam1, const mjvGLCamera* cam2);
580 |
581 | // Select geom or skin with mouse, return bodyid; -1: none selected.
582 | MJAPI int mjv_select(const mjModel* m, const mjData* d, const mjvOption* vopt,
583 | mjtNum aspectratio, mjtNum relx, mjtNum rely,
584 | const mjvScene* scn, mjtNum selpnt[3], int geomid[1], int skinid[1]);
585 |
586 |
587 | //---------------------------------- Visualization -------------------------------------------------
588 |
589 | // Set default visualization options.
590 | MJAPI void mjv_defaultOption(mjvOption* opt);
591 |
592 | // Set default figure.
593 | MJAPI void mjv_defaultFigure(mjvFigure* fig);
594 |
595 | // Initialize given geom fields when not NULL, set the rest to their default values.
596 | MJAPI void mjv_initGeom(mjvGeom* geom, int type, const mjtNum size[3],
597 | const mjtNum pos[3], const mjtNum mat[9], const float rgba[4]);
598 |
599 | // Set (type, size, pos, mat) for connector-type geom between given points.
600 | // Assume that mjv_initGeom was already called to set all other properties.
601 | // Width of mjGEOM_LINE is denominated in pixels.
602 | MJAPI void mjv_makeConnector(mjvGeom* geom, int type, mjtNum width,
603 | mjtNum a0, mjtNum a1, mjtNum a2,
604 | mjtNum b0, mjtNum b1, mjtNum b2);
605 |
606 | // Set default abstract scene.
607 | MJAPI void mjv_defaultScene(mjvScene* scn);
608 |
609 | // Allocate resources in abstract scene.
610 | MJAPI void mjv_makeScene(const mjModel* m, mjvScene* scn, int maxgeom);
611 |
612 | // Free abstract scene.
613 | MJAPI void mjv_freeScene(mjvScene* scn);
614 |
615 | // Update entire scene given model state.
616 | MJAPI void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt,
617 | const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn);
618 |
619 | // Update entire scene from a scene state, return the number of new mjWARN_VGEOMFULL warnings.
620 | MJAPI int mjv_updateSceneFromState(const mjvSceneState* scnstate, const mjvOption* opt,
621 | const mjvPerturb* pert, mjvCamera* cam, int catmask,
622 | mjvScene* scn);
623 |
624 | // Set default scene state.
625 | MJAPI void mjv_defaultSceneState(mjvSceneState* scnstate);
626 |
627 | // Allocate resources and initialize a scene state object.
628 | MJAPI void mjv_makeSceneState(const mjModel* m, const mjData* d,
629 | mjvSceneState* scnstate, int maxgeom);
630 |
631 | // Free scene state.
632 | MJAPI void mjv_freeSceneState(mjvSceneState* scnstate);
633 |
634 | // Update a scene state from model and data.
635 | MJAPI void mjv_updateSceneState(const mjModel* m, mjData* d, const mjvOption* opt,
636 | mjvSceneState* scnstate);
637 |
638 | // Add geoms from selected categories.
639 | MJAPI void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* opt,
640 | const mjvPerturb* pert, int catmask, mjvScene* scn);
641 |
642 | // Make list of lights.
643 | MJAPI void mjv_makeLights(const mjModel* m, mjData* d, mjvScene* scn);
644 |
645 | // Update camera.
646 | MJAPI void mjv_updateCamera(const mjModel* m, mjData* d, mjvCamera* cam, mjvScene* scn);
647 |
648 | // Update skins.
649 | MJAPI void mjv_updateSkin(const mjModel* m, mjData* d, mjvScene* scn);
650 |
651 |
652 | //---------------------------------- OpenGL rendering ----------------------------------------------
653 |
654 | // Set default mjrContext.
655 | MJAPI void mjr_defaultContext(mjrContext* con);
656 |
657 | // Allocate resources in custom OpenGL context; fontscale is mjtFontScale.
658 | MJAPI void mjr_makeContext(const mjModel* m, mjrContext* con, int fontscale);
659 |
660 | // Change font of existing context.
661 | MJAPI void mjr_changeFont(int fontscale, mjrContext* con);
662 |
663 | // Add Aux buffer with given index to context; free previous Aux buffer.
664 | MJAPI void mjr_addAux(int index, int width, int height, int samples, mjrContext* con);
665 |
666 | // Free resources in custom OpenGL context, set to default.
667 | MJAPI void mjr_freeContext(mjrContext* con);
668 |
669 | // Resize offscreen buffers.
670 | MJAPI void mjr_resizeOffscreen(int width, int height, mjrContext* con);
671 |
672 | // Upload texture to GPU, overwriting previous upload if any.
673 | MJAPI void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid);
674 |
675 | // Upload mesh to GPU, overwriting previous upload if any.
676 | MJAPI void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid);
677 |
678 | // Upload height field to GPU, overwriting previous upload if any.
679 | MJAPI void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid);
680 |
681 | // Make con->currentBuffer current again.
682 | MJAPI void mjr_restoreBuffer(const mjrContext* con);
683 |
684 | // Set OpenGL framebuffer for rendering: mjFB_WINDOW or mjFB_OFFSCREEN.
685 | // If only one buffer is available, set that buffer and ignore framebuffer argument.
686 | MJAPI void mjr_setBuffer(int framebuffer, mjrContext* con);
687 |
688 | // Read pixels from current OpenGL framebuffer to client buffer.
689 | // Viewport is in OpenGL framebuffer; client buffer starts at (0,0).
690 | MJAPI void mjr_readPixels(unsigned char* rgb, float* depth,
691 | mjrRect viewport, const mjrContext* con);
692 |
693 | // Draw pixels from client buffer to current OpenGL framebuffer.
694 | // Viewport is in OpenGL framebuffer; client buffer starts at (0,0).
695 | MJAPI void mjr_drawPixels(const unsigned char* rgb, const float* depth,
696 | mjrRect viewport, const mjrContext* con);
697 |
698 | // Blit from src viewpoint in current framebuffer to dst viewport in other framebuffer.
699 | // If src, dst have different size and flg_depth==0, color is interpolated with GL_LINEAR.
700 | MJAPI void mjr_blitBuffer(mjrRect src, mjrRect dst,
701 | int flg_color, int flg_depth, const mjrContext* con);
702 |
703 | // Set Aux buffer for custom OpenGL rendering (call restoreBuffer when done).
704 | MJAPI void mjr_setAux(int index, const mjrContext* con);
705 |
706 | // Blit from Aux buffer to con->currentBuffer.
707 | MJAPI void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext* con);
708 |
709 | // Draw text at (x,y) in relative coordinates; font is mjtFont.
710 | MJAPI void mjr_text(int font, const char* txt, const mjrContext* con,
711 | float x, float y, float r, float g, float b);
712 |
713 | // Draw text overlay; font is mjtFont; gridpos is mjtGridPos.
714 | MJAPI void mjr_overlay(int font, int gridpos, mjrRect viewport,
715 | const char* overlay, const char* overlay2, const mjrContext* con);
716 |
717 | // Get maximum viewport for active buffer.
718 | MJAPI mjrRect mjr_maxViewport(const mjrContext* con);
719 |
720 | // Draw rectangle.
721 | MJAPI void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a);
722 |
723 | // Draw rectangle with centered text.
724 | MJAPI void mjr_label(mjrRect viewport, int font, const char* txt,
725 | float r, float g, float b, float a, float rt, float gt, float bt,
726 | const mjrContext* con);
727 |
728 | // Draw 2D figure.
729 | MJAPI void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con);
730 |
731 | // Render 3D scene.
732 | MJAPI void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con);
733 |
734 | // Call glFinish.
735 | MJAPI void mjr_finish(void);
736 |
737 | // Call glGetError and return result.
738 | MJAPI int mjr_getError(void);
739 |
740 | // Find first rectangle containing mouse, -1: not found.
741 | MJAPI int mjr_findRect(int x, int y, int nrect, const mjrRect* rect);
742 |
743 |
744 | //---------------------------------- UI framework --------------------------------------------------
745 |
746 | // Get builtin UI theme spacing (ind: 0-1).
747 | MJAPI mjuiThemeSpacing mjui_themeSpacing(int ind);
748 |
749 | // Get builtin UI theme color (ind: 0-3).
750 | MJAPI mjuiThemeColor mjui_themeColor(int ind);
751 |
752 | // Add definitions to UI.
753 | MJAPI void mjui_add(mjUI* ui, const mjuiDef* def);
754 |
755 | // Add definitions to UI section.
756 | MJAPI void mjui_addToSection(mjUI* ui, int sect, const mjuiDef* def);
757 |
758 | // Compute UI sizes.
759 | MJAPI void mjui_resize(mjUI* ui, const mjrContext* con);
760 |
761 | // Update specific section/item; -1: update all.
762 | MJAPI void mjui_update(int section, int item, const mjUI* ui,
763 | const mjuiState* state, const mjrContext* con);
764 |
765 | // Handle UI event, return pointer to changed item, NULL if no change.
766 | MJAPI mjuiItem* mjui_event(mjUI* ui, mjuiState* state, const mjrContext* con);
767 |
768 | // Copy UI image to current buffer.
769 | MJAPI void mjui_render(mjUI* ui, const mjuiState* state, const mjrContext* con);
770 |
771 |
772 | //---------------------------------- Error and memory ----------------------------------------------
773 |
774 | // Main error function; does not return to caller.
775 | MJAPI void mju_error(const char* msg, ...) mjPRINTFLIKE(1, 2);
776 |
777 | // Deprecated: use mju_error.
778 | MJAPI void mju_error_i(const char* msg, int i);
779 |
780 | // Deprecated: use mju_error.
781 | MJAPI void mju_error_s(const char* msg, const char* text);
782 |
783 | // Main warning function; returns to caller.
784 | MJAPI void mju_warning(const char* msg, ...) mjPRINTFLIKE(1, 2);
785 |
786 | // Deprecated: use mju_warning.
787 | MJAPI void mju_warning_i(const char* msg, int i);
788 |
789 | // Deprecated: use mju_warning.
790 | MJAPI void mju_warning_s(const char* msg, const char* text);
791 |
792 | // Clear user error and memory handlers.
793 | MJAPI void mju_clearHandlers(void);
794 |
795 | // Allocate memory; byte-align on 64; pad size to multiple of 64.
796 | MJAPI void* mju_malloc(size_t size);
797 |
798 | // Free memory, using free() by default.
799 | MJAPI void mju_free(void* ptr);
800 |
801 | // High-level warning function: count warnings in mjData, print only the first.
802 | MJAPI void mj_warning(mjData* d, int warning, int info);
803 |
804 | // Write [datetime, type: message] to MUJOCO_LOG.TXT.
805 | MJAPI void mju_writeLog(const char* type, const char* msg);
806 |
807 |
808 | //---------------------------------- Activation ----------------------------------------------------
809 |
810 | // Return 1 (for backward compatibility).
811 | MJAPI int mj_activate(const char* filename);
812 |
813 | // Do nothing (for backward compatibility).
814 | MJAPI void mj_deactivate(void);
815 |
816 |
817 | //---------------------------------- Standard math -------------------------------------------------
818 |
819 | #define mjMAX(a, b) (((a) > (b)) ? (a) : (b))
820 | #define mjMIN(a, b) (((a) < (b)) ? (a) : (b))
821 |
822 | #ifdef mjUSEDOUBLE
823 | #define mju_sqrt sqrt
824 | #define mju_exp exp
825 | #define mju_sin sin
826 | #define mju_cos cos
827 | #define mju_tan tan
828 | #define mju_asin asin
829 | #define mju_acos acos
830 | #define mju_atan2 atan2
831 | #define mju_tanh tanh
832 | #define mju_pow pow
833 | #define mju_abs fabs
834 | #define mju_log log
835 | #define mju_log10 log10
836 | #define mju_floor floor
837 | #define mju_ceil ceil
838 |
839 | #else
840 | #define mju_sqrt sqrtf
841 | #define mju_exp expf
842 | #define mju_sin sinf
843 | #define mju_cos cosf
844 | #define mju_tan tanf
845 | #define mju_asin asinf
846 | #define mju_acos acosf
847 | #define mju_atan2 atan2f
848 | #define mju_tanh tanhf
849 | #define mju_pow powf
850 | #define mju_abs fabsf
851 | #define mju_log logf
852 | #define mju_log10 log10f
853 | #define mju_floor floorf
854 | #define mju_ceil ceilf
855 | #endif
856 |
857 |
858 | //---------------------------------- Vector math ---------------------------------------------------
859 |
860 | // Set res = 0.
861 | MJAPI void mju_zero3(mjtNum res[3]);
862 |
863 | // Set res = vec.
864 | MJAPI void mju_copy3(mjtNum res[3], const mjtNum data[3]);
865 |
866 | // Set res = vec*scl.
867 | MJAPI void mju_scl3(mjtNum res[3], const mjtNum vec[3], mjtNum scl);
868 |
869 | // Set res = vec1 + vec2.
870 | MJAPI void mju_add3(mjtNum res[3], const mjtNum vec1[3], const mjtNum vec2[3]);
871 |
872 | // Set res = vec1 - vec2.
873 | MJAPI void mju_sub3(mjtNum res[3], const mjtNum vec1[3], const mjtNum vec2[3]);
874 |
875 | // Set res = res + vec.
876 | MJAPI void mju_addTo3(mjtNum res[3], const mjtNum vec[3]);
877 |
878 | // Set res = res - vec.
879 | MJAPI void mju_subFrom3(mjtNum res[3], const mjtNum vec[3]);
880 |
881 | // Set res = res + vec*scl.
882 | MJAPI void mju_addToScl3(mjtNum res[3], const mjtNum vec[3], mjtNum scl);
883 |
884 | // Set res = vec1 + vec2*scl.
885 | MJAPI void mju_addScl3(mjtNum res[3], const mjtNum vec1[3], const mjtNum vec2[3], mjtNum scl);
886 |
887 | // Normalize vector, return length before normalization.
888 | MJAPI mjtNum mju_normalize3(mjtNum res[3]);
889 |
890 | // Return vector length (without normalizing the vector).
891 | MJAPI mjtNum mju_norm3(const mjtNum vec[3]);
892 |
893 | // Return dot-product of vec1 and vec2.
894 | MJAPI mjtNum mju_dot3(const mjtNum vec1[3], const mjtNum vec2[3]);
895 |
896 | // Return Cartesian distance between 3D vectors pos1 and pos2.
897 | MJAPI mjtNum mju_dist3(const mjtNum pos1[3], const mjtNum pos2[3]);
898 |
899 | // Multiply vector by 3D rotation matrix: res = mat * vec.
900 | MJAPI void mju_rotVecMat(mjtNum res[3], const mjtNum vec[3], const mjtNum mat[9]);
901 |
902 | // Multiply vector by transposed 3D rotation matrix: res = mat' * vec.
903 | MJAPI void mju_rotVecMatT(mjtNum res[3], const mjtNum vec[3], const mjtNum mat[9]);
904 |
905 | // Compute cross-product: res = cross(a, b).
906 | MJAPI void mju_cross(mjtNum res[3], const mjtNum a[3], const mjtNum b[3]);
907 |
908 | // Set res = 0.
909 | MJAPI void mju_zero4(mjtNum res[4]);
910 |
911 | // Set res = (1,0,0,0).
912 | MJAPI void mju_unit4(mjtNum res[4]);
913 |
914 | // Set res = vec.
915 | MJAPI void mju_copy4(mjtNum res[4], const mjtNum data[4]);
916 |
917 | // Normalize vector, return length before normalization.
918 | MJAPI mjtNum mju_normalize4(mjtNum res[4]);
919 |
920 | // Set res = 0.
921 | MJAPI void mju_zero(mjtNum* res, int n);
922 |
923 | // Set res = val.
924 | MJAPI void mju_fill(mjtNum* res, mjtNum val, int n);
925 |
926 | // Set res = vec.
927 | MJAPI void mju_copy(mjtNum* res, const mjtNum* data, int n);
928 |
929 | // Return sum(vec).
930 | MJAPI mjtNum mju_sum(const mjtNum* vec, int n);
931 |
932 | // Return L1 norm: sum(abs(vec)).
933 | MJAPI mjtNum mju_L1(const mjtNum* vec, int n);
934 |
935 | // Set res = vec*scl.
936 | MJAPI void mju_scl(mjtNum* res, const mjtNum* vec, mjtNum scl, int n);
937 |
938 | // Set res = vec1 + vec2.
939 | MJAPI void mju_add(mjtNum* res, const mjtNum* vec1, const mjtNum* vec2, int n);
940 |
941 | // Set res = vec1 - vec2.
942 | MJAPI void mju_sub(mjtNum* res, const mjtNum* vec1, const mjtNum* vec2, int n);
943 |
944 | // Set res = res + vec.
945 | MJAPI void mju_addTo(mjtNum* res, const mjtNum* vec, int n);
946 |
947 | // Set res = res - vec.
948 | MJAPI void mju_subFrom(mjtNum* res, const mjtNum* vec, int n);
949 |
950 | // Set res = res + vec*scl.
951 | MJAPI void mju_addToScl(mjtNum* res, const mjtNum* vec, mjtNum scl, int n);
952 |
953 | // Set res = vec1 + vec2*scl.
954 | MJAPI void mju_addScl(mjtNum* res, const mjtNum* vec1, const mjtNum* vec2, mjtNum scl, int n);
955 |
956 | // Normalize vector, return length before normalization.
957 | MJAPI mjtNum mju_normalize(mjtNum* res, int n);
958 |
959 | // Return vector length (without normalizing vector).
960 | MJAPI mjtNum mju_norm(const mjtNum* res, int n);
961 |
962 | // Return dot-product of vec1 and vec2.
963 | MJAPI mjtNum mju_dot(const mjtNum* vec1, const mjtNum* vec2, int n);
964 |
965 | // Multiply matrix and vector: res = mat * vec.
966 | MJAPI void mju_mulMatVec(mjtNum* res, const mjtNum* mat, const mjtNum* vec, int nr, int nc);
967 |
968 | // Multiply transposed matrix and vector: res = mat' * vec.
969 | MJAPI void mju_mulMatTVec(mjtNum* res, const mjtNum* mat, const mjtNum* vec, int nr, int nc);
970 |
971 | // Multiply square matrix with vectors on both sides: returns vec1' * mat * vec2.
972 | MJAPI mjtNum mju_mulVecMatVec(const mjtNum* vec1, const mjtNum* mat, const mjtNum* vec2, int n);
973 |
974 | // Transpose matrix: res = mat'.
975 | MJAPI void mju_transpose(mjtNum* res, const mjtNum* mat, int nr, int nc);
976 |
977 | // Symmetrize square matrix res = (mat + mat')/2.
978 | MJAPI void mju_symmetrize(mjtNum* res, const mjtNum* mat, int n);
979 |
980 | // Set mat to the identity matrix.
981 | MJAPI void mju_eye(mjtNum* mat, int n);
982 |
983 | // Multiply matrices: res = mat1 * mat2.
984 | MJAPI void mju_mulMatMat(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2,
985 | int r1, int c1, int c2);
986 |
987 | // Multiply matrices, second argument transposed: res = mat1 * mat2'.
988 | MJAPI void mju_mulMatMatT(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2,
989 | int r1, int c1, int r2);
990 |
991 | // Multiply matrices, first argument transposed: res = mat1' * mat2.
992 | MJAPI void mju_mulMatTMat(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2,
993 | int r1, int c1, int c2);
994 |
995 | // Set res = mat' * diag * mat if diag is not NULL, and res = mat' * mat otherwise.
996 | MJAPI void mju_sqrMatTD(mjtNum* res, const mjtNum* mat, const mjtNum* diag, int nr, int nc);
997 |
998 | // Coordinate transform of 6D motion or force vector in rotation:translation format.
999 | // rotnew2old is 3-by-3, NULL means no rotation; flg_force specifies force or motion type.
1000 | MJAPI void mju_transformSpatial(mjtNum res[6], const mjtNum vec[6], int flg_force,
1001 | const mjtNum newpos[3], const mjtNum oldpos[3],
1002 | const mjtNum rotnew2old[9]);
1003 |
1004 |
1005 | //---------------------------------- Quaternions ---------------------------------------------------
1006 |
1007 | // Rotate vector by quaternion.
1008 | MJAPI void mju_rotVecQuat(mjtNum res[3], const mjtNum vec[3], const mjtNum quat[4]);
1009 |
1010 | // Conjugate quaternion, corresponding to opposite rotation.
1011 | MJAPI void mju_negQuat(mjtNum res[4], const mjtNum quat[4]);
1012 |
1013 | // Multiply quaternions.
1014 | MJAPI void mju_mulQuat(mjtNum res[4], const mjtNum quat1[4], const mjtNum quat2[4]);
1015 |
1016 | // Multiply quaternion and axis.
1017 | MJAPI void mju_mulQuatAxis(mjtNum res[4], const mjtNum quat[4], const mjtNum axis[3]);
1018 |
1019 | // Convert axisAngle to quaternion.
1020 | MJAPI void mju_axisAngle2Quat(mjtNum res[4], const mjtNum axis[3], mjtNum angle);
1021 |
1022 | // Convert quaternion (corresponding to orientation difference) to 3D velocity.
1023 | MJAPI void mju_quat2Vel(mjtNum res[3], const mjtNum quat[4], mjtNum dt);
1024 |
1025 | // Subtract quaternions, express as 3D velocity: qb*quat(res) = qa.
1026 | MJAPI void mju_subQuat(mjtNum res[3], const mjtNum qa[4], const mjtNum qb[4]);
1027 |
1028 | // Convert quaternion to 3D rotation matrix.
1029 | MJAPI void mju_quat2Mat(mjtNum res[9], const mjtNum quat[4]);
1030 |
1031 | // Convert 3D rotation matrix to quaternion.
1032 | MJAPI void mju_mat2Quat(mjtNum quat[4], const mjtNum mat[9]);
1033 |
1034 | // Compute time-derivative of quaternion, given 3D rotational velocity.
1035 | MJAPI void mju_derivQuat(mjtNum res[4], const mjtNum quat[4], const mjtNum vel[3]);
1036 |
1037 | // Integrate quaternion given 3D angular velocity.
1038 | MJAPI void mju_quatIntegrate(mjtNum quat[4], const mjtNum vel[3], mjtNum scale);
1039 |
1040 | // Construct quaternion performing rotation from z-axis to given vector.
1041 | MJAPI void mju_quatZ2Vec(mjtNum quat[4], const mjtNum vec[3]);
1042 |
1043 |
1044 | //---------------------------------- Poses ---------------------------------------------------------
1045 |
1046 | // Multiply two poses.
1047 | MJAPI void mju_mulPose(mjtNum posres[3], mjtNum quatres[4],
1048 | const mjtNum pos1[3], const mjtNum quat1[4],
1049 | const mjtNum pos2[3], const mjtNum quat2[4]);
1050 |
1051 | // Conjugate pose, corresponding to the opposite spatial transformation.
1052 | MJAPI void mju_negPose(mjtNum posres[3], mjtNum quatres[4],
1053 | const mjtNum pos[3], const mjtNum quat[4]);
1054 |
1055 | // Transform vector by pose.
1056 | MJAPI void mju_trnVecPose(mjtNum res[3], const mjtNum pos[3], const mjtNum quat[4],
1057 | const mjtNum vec[3]);
1058 |
1059 |
1060 | //--------------------------------- Decompositions / Solvers ---------------------------------------
1061 |
1062 | // Cholesky decomposition: mat = L*L'; return rank, decomposition performed in-place into mat.
1063 | MJAPI int mju_cholFactor(mjtNum* mat, int n, mjtNum mindiag);
1064 |
1065 | // Solve mat * res = vec, where mat is Cholesky-factorized
1066 | MJAPI void mju_cholSolve(mjtNum* res, const mjtNum* mat, const mjtNum* vec, int n);
1067 |
1068 | // Cholesky rank-one update: L*L' +/- x*x'; return rank.
1069 | MJAPI int mju_cholUpdate(mjtNum* mat, mjtNum* x, int n, int flg_plus);
1070 |
1071 | // Eigenvalue decomposition of symmetric 3x3 matrix.
1072 | MJAPI int mju_eig3(mjtNum eigval[3], mjtNum eigvec[9], mjtNum quat[4], const mjtNum mat[9]);
1073 |
1074 | // minimize 0.5*x'*H*x + x'*g s.t. lower <= x <= upper, return rank or -1 if failed
1075 | // inputs:
1076 | // n - problem dimension
1077 | // H - SPD matrix n*n
1078 | // g - bias vector n
1079 | // lower - lower bounds n
1080 | // upper - upper bounds n
1081 | // res - solution warmstart n
1082 | // return value:
1083 | // nfree <= n - rank of unconstrained subspace, -1 if failure
1084 | // outputs (required):
1085 | // res - solution n
1086 | // R - subspace Cholesky factor nfree*nfree allocated: n*(n+7)
1087 | // outputs (optional):
1088 | // index - set of free dimensions nfree allocated: n
1089 | // notes:
1090 | // the initial value of res is used to warmstart the solver
1091 | // R must have allocatd size n*(n+7), but only nfree*nfree values are used in output
1092 | // index (if given) must have allocated size n, but only nfree values are used in output
1093 | // only the lower triangles of H and R and are read from and written to, respectively
1094 | // the convenience function mju_boxQPmalloc allocates the required data structures
1095 | MJAPI int mju_boxQP(mjtNum* res, mjtNum* R, int* index, const mjtNum* H, const mjtNum* g, int n,
1096 | const mjtNum* lower, const mjtNum* upper);
1097 |
1098 | // allocate heap memory for box-constrained Quadratic Program
1099 | // as in mju_boxQP, index, lower, and upper are optional
1100 | // free all pointers with mju_free()
1101 | MJAPI void mju_boxQPmalloc(mjtNum** res, mjtNum** R, int** index, mjtNum** H, mjtNum** g, int n,
1102 | mjtNum** lower, mjtNum** upper);
1103 |
1104 | //---------------------- Miscellaneous -------------------------------------------------------------
1105 |
1106 | // Muscle active force, prm = (range[2], force, scale, lmin, lmax, vmax, fpmax, fvmax).
1107 | MJAPI mjtNum mju_muscleGain(mjtNum len, mjtNum vel, const mjtNum lengthrange[2],
1108 | mjtNum acc0, const mjtNum prm[9]);
1109 |
1110 | // Muscle passive force, prm = (range[2], force, scale, lmin, lmax, vmax, fpmax, fvmax).
1111 | MJAPI mjtNum mju_muscleBias(mjtNum len, const mjtNum lengthrange[2],
1112 | mjtNum acc0, const mjtNum prm[9]);
1113 |
1114 | // Muscle activation dynamics, prm = (tau_act, tau_deact).
1115 | MJAPI mjtNum mju_muscleDynamics(mjtNum ctrl, mjtNum act, const mjtNum prm[2]);
1116 |
1117 | // Convert contact force to pyramid representation.
1118 | MJAPI void mju_encodePyramid(mjtNum* pyramid, const mjtNum* force, const mjtNum* mu, int dim);
1119 |
1120 | // Convert pyramid representation to contact force.
1121 | MJAPI void mju_decodePyramid(mjtNum* force, const mjtNum* pyramid, const mjtNum* mu, int dim);
1122 |
1123 | // Integrate spring-damper analytically, return pos(dt).
1124 | MJAPI mjtNum mju_springDamper(mjtNum pos0, mjtNum vel0, mjtNum Kp, mjtNum Kv, mjtNum dt);
1125 |
1126 | // Return min(a,b) with single evaluation of a and b.
1127 | MJAPI mjtNum mju_min(mjtNum a, mjtNum b);
1128 |
1129 | // Return max(a,b) with single evaluation of a and b.
1130 | MJAPI mjtNum mju_max(mjtNum a, mjtNum b);
1131 |
1132 | // Clip x to the range [min, max].
1133 | MJAPI mjtNum mju_clip(mjtNum x, mjtNum min, mjtNum max);
1134 |
1135 | // Return sign of x: +1, -1 or 0.
1136 | MJAPI mjtNum mju_sign(mjtNum x);
1137 |
1138 | // Round x to nearest integer.
1139 | MJAPI int mju_round(mjtNum x);
1140 |
1141 | // Convert type id (mjtObj) to type name.
1142 | MJAPI const char* mju_type2Str(int type);
1143 |
1144 | // Convert type name to type id (mjtObj).
1145 | MJAPI int mju_str2Type(const char* str);
1146 |
1147 | // Return human readable number of bytes using standard letter suffix.
1148 | MJAPI const char* mju_writeNumBytes(size_t nbytes);
1149 |
1150 | // Construct a warning message given the warning type and info.
1151 | MJAPI const char* mju_warningText(int warning, size_t info);
1152 |
1153 | // Return 1 if nan or abs(x)>mjMAXVAL, 0 otherwise. Used by check functions.
1154 | MJAPI int mju_isBad(mjtNum x);
1155 |
1156 | // Return 1 if all elements are 0.
1157 | MJAPI int mju_isZero(mjtNum* vec, int n);
1158 |
1159 | // Standard normal random number generator (optional second number).
1160 | MJAPI mjtNum mju_standardNormal(mjtNum* num2);
1161 |
1162 | // Convert from float to mjtNum.
1163 | MJAPI void mju_f2n(mjtNum* res, const float* vec, int n);
1164 |
1165 | // Convert from mjtNum to float.
1166 | MJAPI void mju_n2f(float* res, const mjtNum* vec, int n);
1167 |
1168 | // Convert from double to mjtNum.
1169 | MJAPI void mju_d2n(mjtNum* res, const double* vec, int n);
1170 |
1171 | // Convert from mjtNum to double.
1172 | MJAPI void mju_n2d(double* res, const mjtNum* vec, int n);
1173 |
1174 | // Insertion sort, resulting list is in increasing order.
1175 | MJAPI void mju_insertionSort(mjtNum* list, int n);
1176 |
1177 | // Integer insertion sort, resulting list is in increasing order.
1178 | MJAPI void mju_insertionSortInt(int* list, int n);
1179 |
1180 | // Generate Halton sequence.
1181 | MJAPI mjtNum mju_Halton(int index, int base);
1182 |
1183 | // Call strncpy, then set dst[n-1] = 0.
1184 | MJAPI char* mju_strncpy(char *dst, const char *src, int n);
1185 |
1186 | // Sigmoid function over 0<=x<=1 constructed from half-quadratics.
1187 | MJAPI mjtNum mju_sigmoid(mjtNum x);
1188 |
1189 |
1190 | //---------------------- Derivatives ---------------------------------------------------------------
1191 |
1192 | // Finite differenced transition matrices (control theory notation)
1193 | // d(x_next) = A*dx + B*du
1194 | // d(sensor) = C*dx + D*du
1195 | // required output matrix dimensions:
1196 | // A: (2*nv+na x 2*nv+na)
1197 | // B: (2*nv+na x nu)
1198 | // D: (nsensordata x 2*nv+na)
1199 | // C: (nsensordata x nu)
1200 | MJAPI void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte centered,
1201 | mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D);
1202 |
1203 |
1204 |
1205 | //---------------------- Plugins -------------------------------------------------------------------
1206 |
1207 | // Set default plugin definition.
1208 | MJAPI void mjp_defaultPlugin(mjpPlugin* plugin);
1209 |
1210 | // Globally register a plugin. This function is thread-safe.
1211 | // If an identical mjpPlugin is already registered, this function does nothing.
1212 | // If a non-identical mjpPlugin with the same name is already registered, an mju_error is raised.
1213 | // Two mjpPlugins are considered identical if all member function pointers and numbers are equal,
1214 | // and the name and attribute strings are all identical, however the char pointers to the strings
1215 | // need not be the same.
1216 | MJAPI int mjp_registerPlugin(const mjpPlugin* plugin);
1217 |
1218 | // Return the number of globally registered plugins.
1219 | MJAPI int mjp_pluginCount();
1220 |
1221 | // Look up a plugin by name. If slot is not NULL, also write its registered slot number into it.
1222 | MJAPI const mjpPlugin* mjp_getPlugin(const char* name, int* slot);
1223 |
1224 | // Look up a plugin by the registered slot number that was returned by mjp_registerPlugin.
1225 | MJAPI const mjpPlugin* mjp_getPluginAtSlot(int slot);
1226 |
1227 | // Set default resource provider definition.
1228 | MJAPI void mjp_defaultResourceProvider(mjpResourceProvider* provider);
1229 |
1230 | // Globally register a resource provider in a thread-safe manner. The provider must have a prefix
1231 | // that is not a sub-prefix or super-prefix of any current registered providers. This function
1232 | // returns a slot number > 0 on success.
1233 | MJAPI int mjp_registerResourceProvider(const mjpResourceProvider* provider);
1234 |
1235 | // Return the number of globally registered resource providers.
1236 | MJAPI int mjp_resourceProviderCount();
1237 |
1238 | // Return the resource provider with the prefix that matches against the resource name.
1239 | // If no match, return NULL.
1240 | MJAPI const mjpResourceProvider* mjp_getResourceProvider(const char* resource_name);
1241 |
1242 | // Look up a resource provider by slot number returned by mjp_registerResourceProvider.
1243 | // If invalid slot number, return NULL.
1244 | MJAPI const mjpResourceProvider* mjp_getResourceProviderAtSlot(int slot);
1245 |
1246 |
1247 | #if defined(__cplusplus)
1248 | }
1249 | #endif
1250 |
1251 | #endif // MUJOCO_MUJOCO_H_
1252 |
--------------------------------------------------------------------------------