Implementation:Google deepmind Mujoco Engine Plugin
| Knowledge Sources | |
|---|---|
| Domains | Plugin Architecture, Physics Simulation, Dynamic Loading |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements the plugin registration, discovery, and dynamic loading system for extending MuJoCo with custom actuators, sensors, and resource providers.
Description
engine_plugin.cc provides MuJoCo's plugin infrastructure, implemented in C++ (unlike the rest of the engine) to leverage standard cross-platform mutex support for thread-safe access to the global plugin table. It manages three types of extensibility points: plugins (mjpPlugin) for custom physics elements like actuators and sensors, resource providers (mjpResourceProvider) for custom file/data loading, and decoders (mjpDecoder) for custom data format parsing. The system supports URI-scheme-based naming, attribute configuration per plugin instance, and dynamic loading of shared libraries from disk. Registration uses a global table with thread-safe access.
Usage
Plugin registration occurs at startup via mjp_registerPlugin(), mjp_registerResourceProvider(), or mjp_registerDecoder(). Plugins can be loaded dynamically from shared libraries using mj_loadPluginLibrary() or batch-loaded from a directory with mj_loadAllPluginLibraries(). Plugin configuration is queried at runtime via mj_getPluginConfig().
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/engine/engine_plugin.cc
- Lines: 1-631
Key Functions
// set default plugin definition
void mjp_defaultPlugin(mjpPlugin* plugin);
// register a plugin in the global table
int mjp_registerPlugin(const mjpPlugin* plugin);
// query registered plugins
const mjpPlugin* mjp_getPluginAtSlot(int slot);
const mjpPlugin* mjp_getPlugin(const char* name, int* slot);
int mjp_pluginCount();
// plugin configuration
const char* mj_getPluginConfig(const mjModel* m, int plugin_id, const char* attrib);
// resource provider registration and lookup
void mjp_defaultResourceProvider(mjpResourceProvider* provider);
int mjp_registerResourceProvider(const mjpResourceProvider* provider);
const mjpResourceProvider* mjp_getResourceProvider(const char* resource_name);
int mjp_resourceProviderCount();
// decoder registration and lookup
void mjp_defaultDecoder(mjpDecoder* decoder);
void mjp_registerDecoder(const mjpDecoder* decoder);
const mjpDecoder* mjp_findDecoder(const mjResource* resource, const char* content_type);
// dynamic library loading
void mj_loadPluginLibrary(const char* path);
void mj_loadAllPluginLibraries(const char* directory, mjfPluginLibraryLoadCallback callback);
Import
#include "engine/engine_plugin.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| plugin | const mjpPlugin* | Yes (register) | Plugin definition to register |
| provider | const mjpResourceProvider* | Yes (register) | Resource provider to register |
| decoder | const mjpDecoder* | Yes (register) | Decoder definition to register |
| name | const char* | Yes (lookup) | Plugin name (URI scheme format) |
| path | const char* | Yes (load) | Path to shared library file |
| directory | const char* | Yes (loadAll) | Directory to scan for plugin libraries |
| m | const mjModel* | Yes (config) | Model containing plugin instances |
| plugin_id | int | Yes (config) | Plugin instance index in model |
| attrib | const char* | Yes (config) | Attribute name to query |
Outputs
| Name | Type | Description |
|---|---|---|
| return (register) | int | Slot index of registered plugin, or -1 on failure |
| return (getPlugin) | const mjpPlugin* | Pointer to plugin definition, or NULL |
| return (getPluginConfig) | const char* | Attribute value string, or empty string |
| return (findDecoder) | const mjpDecoder* | Matching decoder, or NULL |