Mujoco Renderingのロゴ

Mujoco Rendering

コミュニティ
eust-w
mujoco-rendering

MuJoCo offscreen image rendering using mujoco.Renderer in Python and the MuJoCo C/C++ rendering pipeline (mjrContext, mjvScene, mjr_render, mjr_readPixels): RGB, metric depth maps, segmentation masks (mjtObj), MJCF offwidth/offheight framebuffer sizing, MUJOCO_GL (osmesa, egl), MuJoCo cameras (fixed, tracking, free, MjvCamera), and mjvOption flags/geomgroup. Use only for headless camera rendering, dataset recording, and visual observations in MuJoCo simulations. Don't use for generic OpenGL/EGL/OSMesa offscreen rendering, glReadPixels depth/segmentation post-processing, or synthetic dataset pipelines that do not use the `mujoco` library, or for interactive viewers/Studio (mujoco-studio) or ImGui controls (mujoco-gui).

概要

公開者eust-w
リポジトリopen-robotics-plugin
スキル名mujoco-rendering
スター
245
フォーク
0
同梱ファイル
指示のみ
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    eust-wがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Mujoco Rendering」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/eust-w/open-robotics-plugin/tree/main/skills/mujoco-rendering
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/eust-w/open-robotics-plugin.git /tmp/open-robotics-plugin
mkdir -p .claude/skills
cp -r /tmp/open-robotics-plugin/skills/mujoco-rendering .claude/skills/mujoco-rendering
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでMujoco Renderingを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にMujoco Renderingを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Mujoco Renderingは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

MuJoCo Rendering: Cameras, Contexts & Offscreen Buffers

[!TIP]

Official MuJoCo documentation (doc/*.rst): Read ../../programming/rendering.rst (.. _Rendering:, .. _FilamentRendering:, .. _ClassicRendering:) and ../../programming/visualization.rst (.. _Visualization:) directly when in a MuJoCo checkout; for large reference files like ../../python.rst (.. _PyRender:), ../../XMLreference.rst, and ../../APIreference/functions.rst, grep the literal .. _Label: anchor. Outside a checkout, the same doc/*.rst tree ships offline in pip install mujoco at pathlib.Path(mujoco.__file__).parent / 'doc'; otherwise fetch https://mujoco.readthedocs.io/en/latest/<path>.html (or /en/stable/ for released pages; functions.rst renders inside APIreference/APIfunctions.html, and Sphinx anchors lowercase the label, e.g. .. _PyRender: → #pyrender) and browse repo paths (../../../) under https://github.com/google-deepmind/mujoco/tree/main/.

Related skills:

  • mujoco-python — Core physics simulation, stepping, and state management.
  • mujoco-studio — Interactive simulation, Studio viewer apps, and plugin architecture.
  • mujoco-gui — Dear ImGui UI design and custom controls.

1. Overview: Rendering Backends & Workflows

MuJoCo provides two built-in 3D rendering backends (compared side-by-side in programming/rendering.rst, .. _Rendering:):

  • Classic OpenGL (mujoco.Renderer / C mjr): Immediate-mode OpenGL 1.5 renderer (mjv_updateScene -> mjr_render -> mjr_readPixels), now in maintenance mode. Bundled out of the box in pip install mujoco, making mujoco.Renderer the simplest single-class helper for headless RGB, depth, and segmentation capture. See programming/rendering.rst (.. _ClassicRendering:) and python.rst (.. _PyClassicRender:).
  • Filament PBR (mujoco.mjrf & mujoco.rendering.filament / C mjrf): Retained-mode, asynchronous physically-based renderer supporting OpenGL, Vulkan, Metal, and WebGL (owns its own headless or windowed GPU context and arbitrary-size mjrfRenderTarget buffers). Recommended for PBR materials, image-based/photometric lighting, and new C++/Studio applications; see §7 and programming/rendering.rst (.. _FilamentRendering:).
  • Interactive Viewers (mujoco.studio / mujoco.viewer): Desktop or web-streamed interactive viewers; use mujoco-studio instead.

2. Headless Contexts on Linux: MUJOCO_GL

On headless Linux systems (servers, containers), configure the OpenGL context provider via the MUJOCO_GL environment variable before importing mujoco:

python
import os
os.environ['MUJOCO_GL'] = 'egl'      # Hardware-accelerated offscreen on NVIDIA GPUs
# os.environ['MUJOCO_GL'] = 'osmesa' # Portable CPU software rasterization

import mujoco  # Must import AFTER setting MUJOCO_GL

Or from the command line:

bash
MUJOCO_GL=egl python3 my_script.py

3. The Python Renderer Class (RGB, Depth & Segmentation)

mujoco.Renderer manages GL context creation, scene geometry synchronization, and buffer readback. Always use it as a context manager:

python
import mujoco
import numpy as np

model = mujoco.MjModel.from_xml_path('scene.xml')
data = mujoco.MjData(model)

with mujoco.Renderer(model, height=480, width=640) as renderer:
  mujoco.mj_forward(model, data)

  # 1. RGB Rendering
  renderer.update_scene(data, camera='overhead_cam')
  rgb = renderer.render()  # Shape: (480, 640, 3), dtype: uint8

  # 2. Metric Depth Rendering (distance in meters)
  renderer.enable_depth_rendering()
  renderer.update_scene(data, camera='overhead_cam')
  depth = renderer.render()  # Shape: (480, 640), dtype: float32
  renderer.disable_depth_rendering()

  # 3. Semantic Segmentation Rendering
  renderer.enable_segmentation_rendering()
  renderer.update_scene(data, camera='overhead_cam')
  seg = renderer.render()  # Shape: (480, 640, 2), dtype: int32
  # seg[:, :, 0] = object ID (-1 for background)
  # seg[:, :, 1] = object type (mjtObj enum, e.g. mjOBJ_GEOM)
  renderer.disable_segmentation_rendering()

Rendering Inside Simulation Loops

Creating a Renderer allocates GPU framebuffers. In RL or evaluation loops, create the renderer once outside the loop:

python
with mujoco.Renderer(model, height=84, width=84) as renderer:
  for step in range(1000):
    mujoco.mj_step(model, data)
    if step % render_interval == 0:
      renderer.update_scene(data, camera='agent_cam')
      # Call .copy() because the renderer's internal buffer is reused
      frame = renderer.render().copy()

4. C++ Offscreen Rendering Pipeline (mjr & mjv)

In C++, offscreen rendering is performed using the mjvScene and mjrContext APIs:

cpp
#include <mujoco/mujoco.h>

// 1. Initialize visualization structures
mjvCamera cam;
mjv_defaultCamera(&cam);
cam.type = mjCAMERA_FIXED;
cam.fixedcamid = mj_name2id(m, mjOBJ_CAMERA, "overhead_cam");

mjvOption opt;
mjv_defaultOption(&opt);

mjvScene scn;
mjv_makeScene(m, &scn, 2000);  // Buffer up to 2000 geoms

// 2. Initialize offscreen rendering context
mjrContext con;
mjr_defaultContext(&con);
mjr_makeContext(m, &con, mjFONTSCALE_100);

// 3. Render frame
mjrRect viewport = {0, 0, 640, 480};
mjv_updateScene(m, d, &opt, nullptr, &cam, mjCAT_ALL, &scn);
mjr_render(viewport, &scn, &con);

// 4. Read pixels into user buffers
unsigned char rgb[640 * 480 * 3];
float depth[640 * 480];
mjr_readPixels(rgb, depth, viewport, &con);

// 5. Clean up
mjr_freeContext(&con);
mjv_freeScene(&scn);

5. Camera Definition & Placement

MuJoCo cameras look down their negative Z-axis:

  • -Z: Viewing forward direction
  • +X: Right
  • +Y: Up

Defining Cameras in MjSpec

python
# Fixed camera pointing down at ground plane
cam = spec.worldbody.add_camera(
    name='overhead',
    pos=[0, 0, 3.0],
    quat=[0.707, 0.707, 0, 0],  # 90 deg rotation around X
    fovy=60,
)

# Camera attached to robot wrist
wrist_cam = wrist_body.add_camera(
    name='wrist_cam',
    pos=[0.05, 0, 0],
    xyaxes=[0, -1, 0, 0, 0, -1],
    fovy=75,
)

Free Camera (MjvCamera)

For custom interactive or orbital viewpoints:

python
cam = mujoco.MjvCamera()
cam.type = mujoco.mjtCamera.mjCAMERA_FREE
cam.lookat[:] = [0, 0, 0.5]
cam.distance = 2.5
cam.azimuth = 90.0
cam.elevation = -20.0

renderer.update_scene(data, camera=cam)

6. Framebuffers & Scene Options

Offscreen Framebuffer Resolution

The offscreen rendering resolution cannot exceed the dimensions pre-allocated in the model. Adjust the buffer limit in the spec before compilation:

python
spec.visual.global_.offwidth = 1920
spec.visual.global_.offheight = 1080
model = spec.compile()

The Single <visual> Block Rule

MuJoCo uses only the last <visual> block defined in an XML file. Multiple visual blocks will silently overwrite earlier settings:

xml
<!-- ❌ WRONG — second visual block silently resets offwidth/offheight to default -->
<visual><global offwidth="1920" offheight="1080"/></visual>
<visual><headlight ambient="0.3 0.3 0.3"/></visual>

<!-- ✅ RIGHT — consolidate into one visual block -->
<visual>
  <global offwidth="1920" offheight="1080"/>
  <headlight ambient="0.3 0.3 0.3"/>
</visual>

Geom Group Visibility & Visualization Flags

Control rendering layers via MjvOption:

python
opt = mujoco.MjvOption()
opt.geomgroup[:] = False   # Hide all groups
opt.geomgroup[0] = True    # Show primary geometry (default group)
opt.geomgroup[1] = True    # Show secondary visuals

# Toggle visual debugging flags
opt.flags[mujoco.mjtVisFlag.mjVIS_CONTACTFORCE] = True
opt.flags[mujoco.mjtVisFlag.mjVIS_TRANSPARENT] = True

renderer.update_scene(data, camera='overhead', scene_option=opt)

7. Filament Physically-Based Rendering (mjrf)

MuJoCo's Filament backend (mjrfilament.h in C/C++, from mujoco import mjrf and mujoco.rendering.filament in Python) provides retained-mode PBR with OpenGL, Vulkan, Metal, and WebGL support, arbitrary mjrfRenderTarget sizes (independent of <global offwidth offheight/>), and asynchronous mjrfReadRequest pixel readback:

  • Python (ModelScene + Renderer): Create an mjrf.Context, bind model lights and renderables once via mujoco.rendering.filament.model_scene.ModelScene, update in place with ms.update(data), and render into a NumPy target buffer via mujoco.rendering.filament.renderer.Renderer — see the complete example in python.rst (.. _PyFilamentRender:).
  • C/C++ & CMake: Build with -DMUJOCO_USE_FILAMENT=ON (or -DMUJOCO_USE_FILAMENT_MJR_COMPAT=ON for drop-in mjr_ compatibility) and consult programming/rendering.rst (.. _reProgramming:, .. _reSupport:).
  • Photometric light-intensity gotcha: If any <light> has positive intensity, Filament switches the entire scene from classic headlight + default environment lighting to photometric mode (turning off the headlight and darkening zero-intensity lights). For PBR materials, textures, and lighting authoring, read programming/rendering.rst (.. _reAuthoring:, .. _reMaterials:, .. _reLighting:) and inspect the reference PBR/IBL test scenes in ../../../test/render/testdata/ (pbr.xml, lighting.xml, emissive_bloom.xml, reflect_pbr.xml, ibl.ktx) and ../../../model/mug/mug.xml.

8. Common Gotchas & Best Practices

  1. GL context leaks: Always close mujoco.Renderer or use a with block. Failing to free renderers in loops exhausts GL contexts.
  2. Destruction order: In C++, mjr_freeContext must be called before the underlying OpenGL context is destroyed (see programming/rendering.rst, .. _reContext:).
  3. Buffer re-use: renderer.render() returns an internal buffer view. Call .copy() if storing frames in a list.
  4. Camera lookup by name: Pass camera='camera_name' or the integer ID. Avoid passing raw string IDs that are not present in the model.

9. Key References

Documentation

Source Code & Model Examples

よくある質問

AIスキル「Mujoco Rendering」では何ができますか?

MuJoCo offscreen image rendering using mujoco.Renderer in Python and the MuJoCo C/C++ rendering pipeline (mjrContext, mjvScene, mjr_render, mjr_readPixels): RGB, metric depth maps, segmentation masks (mjtObj), MJCF offwidth/offheight framebuffer sizing, MUJOCO_GL (osmesa, egl), MuJoCo cameras (fixed, tracking, free, MjvCamera), and mjvOption flags/geomgroup. Use only for headless camera rendering, dataset recording, and visual observations in MuJoCo simulations. Don't use for generic OpenGL/EGL/OSMesa offscreen rendering, glReadPixels depth/segmentation post-processing, or synthetic dataset...

TypingMindでMujoco Renderingを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Mujoco Renderingはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにMujoco Renderingをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/eust-w/open-robotics-plugin/tree/main/skills/mujoco-renderingを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Mujoco Renderingを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Mujoco Renderingで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもMujoco Renderingを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Mujoco Rendering」は無料ですか?

はい。eust-wがApache-2.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇