mjvive.cpp with mujoco 1.50 and OpenVR 1.0.7

Discussion in 'Visualization' started by Alex Ray, Jun 13, 2017.

  1. Figured I'd share this with the crowd in case other folks are looking for similar.

    This is a gist with mjvive.cpp updated to MuJoCo 1.50 and OpenVR SDK 1.0.7. The edits were very minor.

    mjvive.cpp is the whole updated mjvive, and minivive.cpp is a much simpler version without controllers. The makefile is a replacement for the makefile in mjpro150/samples which builds them.

    Note you have to copy the proper libraries (glew/openvr_api) and binaries into mjpro150/bin, and copy their respective headers into mjpro150/include. This is reasonably straightforward if you follow the compile errors.

    Gist https://gist.github.com/openai-vr/1e78eb568c2f4dbfc3395ff8143fd709
    GLEW (download the windows binaries, copy headers, lib and bin) http://glew.sourceforge.net/
    OpenVR (download the 1.0.7 ZIP, copy headers, lib and bin) https://github.com/ValveSoftware/openvr/tree/v1.0.7

    Happy to answer questions if folks have any, and if you email me at aray@openai.com I'll probably be more responsive than on this forum.
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    Thanks Alex, I inserted a link to your Forum post in the online documentation where mjvive.cpp is documented (Programming chapter).

    On a related note, there is a new feature in MuJoCo 1.50 that is very useful in VR: ray selection. You can use it to emulate a hand-held laser pointer and select the object it is pointing to (instead of relying on the controller buttons as in the present code sample). I will add this to the official code sample when I get around to updating it. If anyone wants to implement this on their own in the meantime, look at the latest simulate.cpp - it illustrates how to use ray selection. In VR, the origin/direction of the selection ray should correspond to the controller and not the camera.
  3. Although the gist is no longer available, I wanted to confirm that the rendering code snippets from `mjvive.cpp` work with the current MuJoCo 2.0, GLEW 2.1.0, OpenVR 1.14.15 and Valve Index headset. I implemented the rendering into our own project, which is based on `simulate.cpp` from MuJoCo 2.0 and I cannot post here, but I would be happy to help if someone encounters problems. I have made some changes that made the code run:

    Change the enum in line 864:
    Texture_t vTex = {(void*)hmd.idtex, TextureType_OpenGL, ColorSpace_Gamma};

    Include GLEW before GLFW in `uitools.h` (I also linked it statically). OpenVR can be included in the main file as in `mjvive.cpp`. Snippet from `uitools.h` line 11:
    #pragma once

    #define GLEW_STATIC

    #include "mujoco.h"
    #include <GL/glew.h>
    #include "glfw3.h"

    #pragma comment(lib, "glew32s.lib")

    Change `0` to the enum `mjFB_WINDOW` on line 834. Don't know why, because `mjFB_WINDOW` evaluates to 0, but it was not rendering to a window until I changed.
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mjFB_WINDOW);

    I did not test the Valve Index controllers as we don't use them, but the compiled version of mjvive worked with them out of the box.