Implementation:Google deepmind Mujoco Simulate Header
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Visualization, GUI, Concurrency |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Header declaring the Simulate class, which manages the MuJoCo interactive viewer state including model/data synchronization, rendering, history tracking, and GUI-driven actions.
Description
This header defines the mujoco::Simulate class that encapsulates all viewer state not contained in core MuJoCo structures. It provides thread-safe model loading and synchronization (via a recursive mutex), a render loop for the UI thread, history buffer management for state playback, control noise injection, and passive mode support where the viewer does not own the model and data. The class holds internal copies of model metadata (joint types, actuator ranges, equality names) and tracks pending GUI actions (save, reset, align, keyframe loading).
Usage
Instantiated by the simulate application with a PlatformUIAdapter, camera, options, and perturbation objects. The main thread calls RenderLoop while the physics thread calls Sync to exchange state. Model loading is requested via Load and executed on the render thread via LoadOnRenderThread.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: simulate/simulate.h
- Lines: 1-353
Key Functions
// Constructor: create viewer with platform adapter, camera, options, perturbation
Simulate(std::unique_ptr<PlatformUIAdapter> platform_ui_adapter,
mjvCamera* cam, mjvOption* opt, mjvPerturb* pert, bool is_passive);
// Synchronize state with UI inputs; optionally sync state only
void Sync(bool state_only = false);
// Update visualization resources
void UpdateHField(int hfieldid);
void UpdateMesh(int meshid);
void UpdateTexture(int texid);
// Model loading workflow
void LoadMessage(const char* displayed_filename);
void Load(mjModel* m, mjData* d, const char* displayed_filename);
void LoadMessageClear(void);
void LoadOnRenderThread();
// Render the UI to the window
void Render();
// Main render loop (must be called from main thread on macOS)
void RenderLoop();
// History and perturbation
void AddToHistory();
void InjectNoise(int key);
Import
#include "simulate.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| platform_ui_adapter | std::unique_ptr<PlatformUIAdapter> | Yes | Platform-specific window and input adapter (e.g., GLFW) |
| cam | mjvCamera* | Yes | Visualization camera parameters |
| opt | mjvOption* | Yes | Visualization options (rendering flags, groups) |
| pert | mjvPerturb* | Yes | Perturbation state for interactive object manipulation |
| is_passive | bool | Yes | If true, viewer does not own mjModel/mjData |
| m, d | mjModel*, mjData* | Yes (for Load) | Model and data to visualize |
Outputs
| Name | Type | Description |
|---|---|---|
| m_, d_ | mjModel*, mjData* | Internal model and data pointers used for rendering |
| history_ | std::vector<mjtNum> | History buffer storing simulation states for playback |
| (rendered output) | Window | Interactive 3D visualization rendered to the platform window |