Introduce mjpEncoder plugin architecture

Add a new mjpEncoder plugin type mirroring the existing mjpDecoder pattern.
Encoders serialize an mjSpec + mjModel to an mjResource for a given format.

New API functions:
- mjp_registerEncoder: globally register an encoder
- mjp_defaultEncoder: zero-initialize an encoder struct
- mjp_findEncoder: look up an encoder by filename extension or content type

The mjfEncode callback takes (mjSpec*, mjModel*, mjVFS*, mjResource*) and
returns 0 on success. Writing to mjResource keeps symmetry with the decoder
reading from mjResource and leaves the door open for writable resource providers.

PiperOrigin-RevId: 889187898
Change-Id: I180771b2255b91dea188ac5e2cdc3a8f0fb85364
This commit is contained in:
Sam Haves
2026-03-25 05:34:48 -07:00
committed by Copybara-Service
parent 2d33b50243
commit f5d3ce3451
15 changed files with 617 additions and 0 deletions
+9
View File
@@ -71,6 +71,15 @@ MJAPI void mjp_defaultDecoder(mjpDecoder* decoder);
// find a decoder that can process a given resource
MJAPI const mjpDecoder* mjp_findDecoder(const mjResource* resource, const char* content_type);
// registers a resource encoder
MJAPI void mjp_registerEncoder(const mjpEncoder* encoder);
// set default encoder definition
MJAPI void mjp_defaultEncoder(mjpEncoder* encoder);
// find an encoder that can write a given format
MJAPI const mjpEncoder* mjp_findEncoder(const char* filename, const char* content_type);
// =================================================================================================
// MuJoCo-internal functions beyond this point.
// "Unsafe" suffix indicates that improper use of these functions may result in data races.