Version 2.1.2: Python bindings, OBJ assets support, bugfixes.
PiperOrigin-RevId: 434731612 Change-Id: I0cfda3e7a3d1c72036764986efc252ffa1b8c6b0
This commit is contained in:
+13
-9
@@ -1,12 +1,16 @@
|
||||
COMMON=-O2 -I../include -L../bin -std=c++11 -mavx -pthread -Wl,-rpath,'$$ORIGIN'
|
||||
# This Makefile assumes that you have GLFW libraries and headers installed on,
|
||||
# which is commonly available through your distro's package manager.
|
||||
# On Debian and Ubuntu, GLFW can be installed via `apt install libglfw3-dev`.
|
||||
|
||||
COMMON=-O2 -I../include -L../lib -std=c++11 -pthread -Wl,-rpath,'$$ORIGIN'/../lib
|
||||
|
||||
all:
|
||||
g++ $(COMMON) testxml.cc -lmujoco210nogl -o ../bin/testxml
|
||||
g++ $(COMMON) testspeed.cc -lmujoco210nogl -o ../bin/testspeed
|
||||
g++ $(COMMON) compile.cc -lmujoco210nogl -o ../bin/compile
|
||||
g++ $(COMMON) derivative.cc -lmujoco210nogl -fopenmp -o ../bin/derivative
|
||||
g++ $(COMMON) basic.cc -lmujoco210 -lGL -lglew ../bin/libglfw.so.3 -o ../bin/basic
|
||||
g++ $(COMMON) record.cc -lmujoco210 -lGL -lglew ../bin/libglfw.so.3 -o ../bin/record
|
||||
gcc -c -O2 -mavx -I../include ../include/uitools.c
|
||||
g++ $(COMMON) uitools.o simulate.cc -lmujoco210 -lGL -lglew ../bin/libglfw.so.3 -o ../bin/simulate
|
||||
$(CXX) $(COMMON) testxml.cc -lmujoco_nogl -o ../bin/testxml
|
||||
$(CXX) $(COMMON) testspeed.cc -lmujoco_nogl -o ../bin/testspeed
|
||||
$(CXX) $(COMMON) compile.cc -lmujoco_nogl -o ../bin/compile
|
||||
$(CXX) $(COMMON) derivative.cc -lmujoco_nogl -fopenmp -o ../bin/derivative
|
||||
$(CXX) $(COMMON) basic.cc -lmujoco -lGL -lglew -lglfw -o ../bin/basic
|
||||
$(CXX) $(COMMON) record.cc -lmujoco -lGL -lglew -lglfw -o ../bin/record
|
||||
$(CC) -c -O2 -I../include uitools.c
|
||||
$(CXX) $(COMMON) uitools.o simulate.cc -lmujoco -lGL -lglew -lglfw -o ../bin/simulate
|
||||
rm *.o
|
||||
|
||||
+18
-9
@@ -1,12 +1,21 @@
|
||||
COMMON=-O2 -I../include -L../bin -std=c++11 -stdlib=libc++ -mavx -pthread
|
||||
# This Makefile assumes that GLFW is installed via Homebrew, and that Homebrew
|
||||
# packages are installed in /usr/local. If your setup is different, you will
|
||||
# need to adjust the HOMEBREW variable accordingly.
|
||||
|
||||
HOMEBREW?=/usr/local
|
||||
|
||||
MUJOCO_LIBDIR=../MuJoCo.Framework/Versions/A
|
||||
MUJOCO_INCLUDEDIR=../MuJoCo.Framework/Versions/A/Headers
|
||||
CFLAGS=-O2 -I$(MUJOCO_INCLUDEDIR) -I$(HOMEBREW)/include -pthread
|
||||
ALLFLAGS=$(CFLAGS) -L$(MUJOCO_LIBDIR) -L$(HOMEBREW)/lib -std=c++11 -stdlib=libc++
|
||||
|
||||
all:
|
||||
clang++ $(COMMON) testxml.cc -lmujoco210nogl -o ../bin/testxml
|
||||
clang++ $(COMMON) testspeed.cc -lmujoco210nogl -o ../bin/testspeed
|
||||
clang++ $(COMMON) compile.cc -lmujoco210nogl -o ../bin/compile
|
||||
clang++ $(COMMON) derivative.cc -lmujoco210nogl -o ../bin/derivative
|
||||
clang++ $(COMMON) basic.cc -lmujoco210 -lglfw.3 -o ../bin/basic
|
||||
clang++ $(COMMON) record.cc -lmujoco210 -lglfw.3 -o ../bin/record
|
||||
clang -c -O2 -mavx -I../include ../include/uitools.c
|
||||
clang++ $(COMMON) uitools.o simulate.cc -lmujoco210 -lglfw.3 -o ../bin/simulate
|
||||
clang++ $(ALLFLAGS) testxml.cc -lmujoco.2.1.2 -o testxml
|
||||
clang++ $(ALLFLAGS) testspeed.cc -lmujoco.2.1.2 -o testspeed
|
||||
clang++ $(ALLFLAGS) compile.cc -lmujoco.2.1.2 -o compile
|
||||
clang++ $(ALLFLAGS) derivative.cc -lmujoco.2.1.2 -o derivative
|
||||
clang++ $(ALLFLAGS) basic.cc -lmujoco.2.1.2 -lglfw -o basic
|
||||
clang++ $(ALLFLAGS) record.cc -lmujoco.2.1.2 -lglfw -o record
|
||||
clang -c $(CFLAGS) uitools.c
|
||||
clang++ $(ALLFLAGS) uitools.o simulate.cc -lmujoco.2.1.2 -lglfw -o simulate
|
||||
rm *.o
|
||||
|
||||
+15
-7
@@ -1,11 +1,19 @@
|
||||
# A copy of the GLFW library is required to build some sample programs.
|
||||
# If this is not already installed on your system, download the WIN64 archive
|
||||
# from https://github.com/glfw/glfw/releases, and copy files as follows:
|
||||
# - Copy the entire `include/GLFW` subdirectory to `mujoco/include/GLFW`.
|
||||
# - Copy glfw3dll.lib from the subdirectory corresponding into your compiler
|
||||
# choice to `mujoco/lib/glfw3.lib`.
|
||||
# - Copy glfw3.dll from the same subdirectory into `mujoco/bin/glfw3.dll`.
|
||||
|
||||
COMMON=/O2 /MT /EHsc /arch:AVX /I../include /Fe../bin/
|
||||
|
||||
all:
|
||||
cl $(COMMON) testxml.cc ../bin/mujoco210nogl.lib
|
||||
cl $(COMMON) testspeed.cc ../bin/mujoco210nogl.lib
|
||||
cl $(COMMON) compile.cc ../bin/mujoco210nogl.lib
|
||||
cl $(COMMON) derivative.cc /openmp ../bin/mujoco210nogl.lib
|
||||
cl $(COMMON) basic.cc ../bin/glfw3.lib ../bin/mujoco210.lib
|
||||
cl $(COMMON) record.cc ../bin/glfw3.lib ../bin/mujoco210.lib
|
||||
cl $(COMMON) simulate.cc ../include/uitools.c ../bin/glfw3.lib ../bin/mujoco210.lib
|
||||
cl $(COMMON) testxml.cc ../lib/mujoco_nogl.lib
|
||||
cl $(COMMON) testspeed.cc ../lib/mujoco_nogl.lib
|
||||
cl $(COMMON) compile.cc ../lib/mujoco_nogl.lib
|
||||
cl $(COMMON) derivative.cc /openmp ../lib/mujoco_nogl.lib
|
||||
cl $(COMMON) basic.cc ../lib/glfw3.lib ../lib/mujoco.lib
|
||||
cl $(COMMON) record.cc ../lib/glfw3.lib ../lib/mujoco.lib
|
||||
cl $(COMMON) simulate.cc uitools.c ../lib/glfw3.lib ../lib/mujoco.lib
|
||||
del *.obj
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "mujoco.h"
|
||||
#include <mujoco.h>
|
||||
|
||||
// MuJoCo data structures
|
||||
mjModel* m = NULL; // MuJoCo model
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "mujoco.h"
|
||||
#include <mujoco.h>
|
||||
|
||||
// help
|
||||
const char helpstring[] =
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "mujoco.h"
|
||||
#include <mujoco.h>
|
||||
|
||||
// enable compilation with and without OpenMP support
|
||||
#if defined(_OPENMP)
|
||||
@@ -61,7 +61,7 @@ void worker(const mjModel* m, const mjData* dmain, mjData* d, int id) {
|
||||
int nv = m->nv;
|
||||
|
||||
// allocate stack space for result at center
|
||||
mjMARKSTACK
|
||||
mjMARKSTACK;
|
||||
mjtNum* center = mj_stackAlloc(d, nv);
|
||||
mjtNum* warmstart = mj_stackAlloc(d, nv);
|
||||
|
||||
@@ -188,7 +188,7 @@ void worker(const mjModel* m, const mjData* dmain, mjData* d, int id) {
|
||||
}
|
||||
}
|
||||
|
||||
mjFREESTACK
|
||||
mjFREESTACK;
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ void checkderiv(const mjModel* m, mjData* d, mjtNum error[7]) {
|
||||
int nv = m->nv;
|
||||
|
||||
// allocate space
|
||||
mjMARKSTACK
|
||||
mjMARKSTACK;
|
||||
mjtNum* mat = mj_stackAlloc(d, nv*nv);
|
||||
|
||||
// get pointers to derivative matrices
|
||||
@@ -275,7 +275,7 @@ void checkderiv(const mjModel* m, mjData* d, mjtNum error[7]) {
|
||||
mju_addTo(mat, F0, nv*nv);
|
||||
error[7] = relnorm(mat, F0, nv*nv);
|
||||
|
||||
mjFREESTACK
|
||||
mjFREESTACK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "mujoco.h"
|
||||
#include <mujoco.h>
|
||||
|
||||
// select EGL, OSMESA or GLFW
|
||||
#if defined(MJ_EGL)
|
||||
|
||||
+51
-21
@@ -19,7 +19,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "mjxmacro.h"
|
||||
#include <mjxmacro.h>
|
||||
#include "uitools.h"
|
||||
|
||||
#include "array_safety.h"
|
||||
@@ -34,15 +34,17 @@ const int maxgeom = 5000; // preallocated geom array in mjvScene
|
||||
const double syncmisalign = 0.1; // maximum time mis-alignment before re-sync
|
||||
const double refreshfactor = 0.7; // fraction of refresh available for simulation
|
||||
const int max_slow_down = 128; // maximum slow-down quotient
|
||||
const double zoom_increment = 0.02; // ratio of single click-wheel zoom increment to vertical extent
|
||||
|
||||
// model and data
|
||||
mjModel* m = NULL;
|
||||
mjData* d = NULL;
|
||||
|
||||
|
||||
// filename strings
|
||||
// strings
|
||||
char filename[kBufSize] = "";
|
||||
char previous_filename[kBufSize] = "";
|
||||
char loadError[kBufSize] = "";
|
||||
|
||||
|
||||
// control noise variables
|
||||
@@ -758,7 +760,7 @@ void makerendering(int oldstate) {
|
||||
},
|
||||
{
|
||||
mjITEM_BUTTON,
|
||||
"Print camera",
|
||||
"Copy camera",
|
||||
2,
|
||||
NULL,
|
||||
""
|
||||
@@ -1067,20 +1069,29 @@ void cleartimers(void) {
|
||||
|
||||
|
||||
|
||||
// print current camera as MJCF specification
|
||||
// copy current camera to clipboard as MJCF specification
|
||||
void printcamera(mjvGLCamera* camera) {
|
||||
char clipboard[500];
|
||||
mjtNum cam_right[3];
|
||||
mjtNum cam_forward[3];
|
||||
mjtNum cam_up[3];
|
||||
|
||||
// get camera spec from the GLCamera
|
||||
mju_f2n(cam_forward, camera[0].forward, 3);
|
||||
mju_f2n(cam_up, camera[0].up, 3);
|
||||
mju_cross(cam_right, cam_forward, cam_up);
|
||||
std::printf("<camera pos=\"%.3f %.3f %.3f\" xyaxes=\"%.3f %.3f %.3f %.3f %.3f %.3f\"/>\n",
|
||||
|
||||
// make MJCF camera spec
|
||||
mju::sprintf_arr(clipboard,
|
||||
"<camera pos=\"%.3f %.3f %.3f\" xyaxes=\"%.3f %.3f %.3f %.3f %.3f %.3f\"/>\n",
|
||||
(camera[0].pos[0] + camera[1].pos[0]) / 2,
|
||||
(camera[0].pos[1] + camera[1].pos[1]) / 2,
|
||||
(camera[0].pos[2] + camera[1].pos[2]) / 2,
|
||||
cam_right[0], cam_right[1], cam_right[2],
|
||||
camera[0].up[0], camera[0].up[1], camera[0].up[2]);
|
||||
|
||||
// copy spec into clipboard
|
||||
glfwSetClipboardString(window, clipboard);
|
||||
}
|
||||
|
||||
|
||||
@@ -1134,28 +1145,34 @@ void loadmodel(void) {
|
||||
}
|
||||
|
||||
// load and compile
|
||||
char error[500] = "";
|
||||
loadError[0] = '\0';
|
||||
mjModel* mnew = 0;
|
||||
if (mju::strlen_arr(filename)>4 &&
|
||||
!std::strncmp(filename+mju::strlen_arr(filename)-4, ".mjb",
|
||||
mju::sizeof_arr(filename)-mju::strlen_arr(filename)+4)) {
|
||||
mnew = mj_loadModel(filename, NULL);
|
||||
if (!mnew) {
|
||||
mju::strcpy_arr(error, "could not load binary model");
|
||||
mju::strcpy_arr(loadError, "could not load binary model");
|
||||
}
|
||||
} else {
|
||||
mnew = mj_loadXML(filename, NULL, error, 500);
|
||||
mnew = mj_loadXML(filename, NULL, loadError, kBufSize);
|
||||
// remove trailing newline character from loadError
|
||||
if (loadError[0]) {
|
||||
int error_length = mju::strlen_arr(loadError);
|
||||
if (loadError[error_length-1] == '\n') {
|
||||
loadError[error_length-1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!mnew) {
|
||||
std::printf("%s\n", error);
|
||||
std::printf("%s\n", loadError);
|
||||
return;
|
||||
}
|
||||
|
||||
// compiler warning: print and pause
|
||||
if (error[0]) {
|
||||
if (loadError[0]) {
|
||||
// mj_forward() below will print the warning message
|
||||
std::printf("Model compiled, but simulation warning (paused):\n %s\n\n",
|
||||
error);
|
||||
std::printf("Model compiled, but simulation warning (paused):\n %s\n", loadError);
|
||||
settings.run = 0;
|
||||
}
|
||||
|
||||
@@ -1594,8 +1611,8 @@ void uiEvent(mjuiState* state) {
|
||||
|
||||
// 3D scroll
|
||||
if (state->type==mjEVENT_SCROLL && state->mouserect==3 && m) {
|
||||
// emulate vertical mouse motion = 5% of window height
|
||||
mjv_moveCamera(m, mjMOUSE_ZOOM, 0, -0.05*state->sy, &scn, &cam);
|
||||
// emulate vertical mouse motion = 2% of window height
|
||||
mjv_moveCamera(m, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &scn, &cam);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1797,12 +1814,19 @@ void render(GLFWwindow* window) {
|
||||
mjr_rectangle(rect, 0.2f, 0.3f, 0.4f, 1);
|
||||
|
||||
// label
|
||||
if (settings.loadrequest)
|
||||
mjr_overlay(mjFONT_BIG, mjGRID_TOPRIGHT, smallrect,
|
||||
"loading", NULL, &con);
|
||||
else
|
||||
mjr_overlay(mjFONT_NORMAL, mjGRID_TOPLEFT, rect,
|
||||
"Drag-and-drop model file here", 0, &con);
|
||||
if (settings.loadrequest) {
|
||||
mjr_overlay(mjFONT_BIG, mjGRID_TOPRIGHT, smallrect, "loading", NULL, &con);
|
||||
} else {
|
||||
char intro_message[kBufSize];
|
||||
mju::sprintf_arr(intro_message,
|
||||
"MuJoCo version %s\nDrag-and-drop model file here", mj_versionString());
|
||||
mjr_overlay(mjFONT_NORMAL, mjGRID_TOPLEFT, rect, intro_message, 0, &con);
|
||||
}
|
||||
|
||||
// show last loading error
|
||||
if (loadError[0]) {
|
||||
mjr_overlay(mjFONT_NORMAL, mjGRID_BOTTOMLEFT, rect, loadError, 0, &con);
|
||||
}
|
||||
|
||||
// render uis
|
||||
if (settings.ui0) {
|
||||
@@ -1821,10 +1845,16 @@ void render(GLFWwindow* window) {
|
||||
// render scene
|
||||
mjr_render(rect, &scn, &con);
|
||||
|
||||
// show last loading error
|
||||
if (loadError[0]) {
|
||||
mjr_overlay(mjFONT_NORMAL, mjGRID_BOTTOMLEFT, rect, loadError, 0, &con);
|
||||
}
|
||||
|
||||
// show pause/loading label
|
||||
if (!settings.run || settings.loadrequest)
|
||||
if (!settings.run || settings.loadrequest) {
|
||||
mjr_overlay(mjFONT_BIG, mjGRID_TOPRIGHT, smallrect,
|
||||
settings.loadrequest ? "loading" : "pause", NULL, &con);
|
||||
}
|
||||
|
||||
// show realtime label
|
||||
if (settings.run && settings.slow_down != 1) {
|
||||
|
||||
+11
-8
@@ -18,18 +18,21 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "mujoco.h"
|
||||
#include <mujoco.h>
|
||||
|
||||
|
||||
// maximum number of threads
|
||||
const int maxthread = 512;
|
||||
|
||||
// model and per-thread data
|
||||
mjModel* m = NULL;
|
||||
mjData* d[64];
|
||||
mjData* d[maxthread];
|
||||
|
||||
|
||||
// per-thread statistics
|
||||
int contacts[64];
|
||||
int constraints[64];
|
||||
double simtime[64];
|
||||
int contacts[maxthread];
|
||||
int constraints[maxthread];
|
||||
double simtime[maxthread];
|
||||
|
||||
|
||||
// timer
|
||||
@@ -121,8 +124,8 @@ int main(int argc, const char** argv) {
|
||||
// clamp ctrlnoise to [0.0, 1.0]
|
||||
ctrlnoise = mjMAX(0.0, mjMIN(ctrlnoise, 1.0));
|
||||
|
||||
// clamp nthread to [1, 64]
|
||||
nthread = mjMAX(1, mjMIN(64, nthread));
|
||||
// clamp nthread to [1, maxthread]
|
||||
nthread = mjMAX(1, mjMIN(maxthread, nthread));
|
||||
|
||||
// get filename, determine file type
|
||||
std::string filename(argv[1]);
|
||||
@@ -169,7 +172,7 @@ int main(int argc, const char** argv) {
|
||||
}
|
||||
|
||||
// run simulation, record total time
|
||||
std::thread th[64];
|
||||
std::thread th[maxthread];
|
||||
double starttime = gettm();
|
||||
for (int id=0; id<nthread; id++) {
|
||||
th[id] = std::thread(simulate, id, nstep, ctrlnoise);
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "mjxmacro.h"
|
||||
#include "mujoco.h"
|
||||
#include <mjxmacro.h>
|
||||
#include <mujoco.h>
|
||||
|
||||
#include "array_safety.h"
|
||||
namespace mju = ::mujoco::sample_util;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "mujoco.h"
|
||||
#include <mujoco.h>
|
||||
|
||||
// this is a C-API
|
||||
#if defined(__cplusplus)
|
||||
|
||||
Reference in New Issue
Block a user