0

I am trying to embed my Mujoco environment as a QOpenGLWidgetin my PyQT GUI. The Mujoco website offers example code for creating a Mujoco visualization in Python. Specifically, I am using the following visualization code from this GitHub issue, seen below:

import mujoco as mj


def main():
    max_width = 100
    max_height = 100
    #ctx = mj.GLContext(max_width, max_height)
    #ctx.make_current()

    cam = mj.MjvCamera()
    opt = mj.MjvOption()

    mj.glfw.glfw.init()
    window = mj.glfw.glfw.create_window(1200, 900, "Demo", None, None)
    mj.glfw.glfw.make_context_current(window)
    mj.glfw.glfw.swap_interval(1)

    mj.mjv_defaultCamera(cam)
    mj.mjv_defaultOption(opt)

    xml_path = "ball.xml"
    model = mj.MjModel.from_xml_path(xml_path)
    data = mj.MjData(model)

    scene = mj.MjvScene(model, maxgeom=10000)
    context = mj.MjrContext(model, mj.mjtFontScale.mjFONTSCALE_150.value)

    while not mj.glfw.glfw.window_should_close(window):
        simstart = data.time

        while (data.time - simstart < 1.0/60.0):
            mj.mj_step(model, data)

        #viewport = mj.MjrRect(0, 0, 0, 0)
        #mj.glfw.glfw.get_framebuffer_size(window)
        viewport = mj.MjrRect(0, 0, 1200, 900)

        #mj.mjv_updateScene(model, data, opt, None, cam, 0, scene)
        mj.mjv_updateScene(model, data, opt, None, cam, mj.mjtCatBit.mjCAT_ALL.value, scene)
        mj.mjr_render(viewport, scene, context)

        mj.glfw.glfw.swap_buffers(window)
        mj.glfw.glfw.poll_events()

    mj.glfw.glfw.terminate()


if __name__ == "__main__":
    main()

This code is for generating a new generic window that contains the Mujoco environment; in my case, I want to embed my Mujoco environment in the QOpenGLWidget. I have tried converting the above code to use PyOpenGL instead of glfw, however I am unsure of the equivalent functions.

I have considered figuring out how to use glfw in my PyQt GUI, however this StackOverflow post says that it's not optimal.

Does anyone have any advice on how I can embed the Mujoco environment in my PyQt GUI?

eyllanesc
  • 221,139
  • 17
  • 121
  • 189
tennis25
  • 59
  • 1
  • 11

0 Answers0