Create mjpDecoder, mj_parse, and mju_decodeResource
- plugin system similar to mjpResourceProvider, but instead of loading a resource it converts an existing mjResource into an mjSpec. - The returned spec is then composed into the referencing spec. - This enables different file types to generate arbitrary specs, and allows us to separate format parsing from compilation code. Follow up CLs will move some of the logic in src/engine for PNG, USD, KTX, OBJ loading into decoders. The mj_parse function MjSpec from a given file, it's a more generic version of mj_parseXML. In it's implementation, mj_parse as opposed to mj_parseXML will look for any registered decoder and not assume we are striclty dealing with MJCF. PiperOrigin-RevId: 826149497 Change-Id: I0ece26904280cb94bd5ded6dd5a565c539d60254
This commit is contained in:
committed by
Copybara-Service
parent
f2badc05ac
commit
57f7145806
@@ -48,6 +48,17 @@ Parse spec from XML string.
|
||||
|
||||
*Nullable:* ``vfs``, ``error``
|
||||
|
||||
.. _mj_parse:
|
||||
|
||||
`mj_parse <#mj_parse>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mj_parse
|
||||
|
||||
Parse spec from a file.
|
||||
|
||||
*Nullable:* ``vfs``, ``error``
|
||||
|
||||
.. _mj_compile:
|
||||
|
||||
`mj_compile <#mj_compile>`__
|
||||
@@ -2926,6 +2937,39 @@ Look up a resource provider by slot number returned by mjp_registerResourceProvi
|
||||
|
||||
If invalid slot number, return NULL.
|
||||
|
||||
.. _mjp_registerDecoder:
|
||||
|
||||
`mjp_registerDecoder <#mjp_registerDecoder>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mjp_registerDecoder
|
||||
|
||||
Globally register a decoder. This function is thread-safe.
|
||||
|
||||
If an identical mjpDecoder is already registered, this function does nothing.
|
||||
|
||||
If a non-identical mjpDecoder with the same name is already registered, an mju_error is raised.
|
||||
|
||||
.. _mjp_defaultDecoder:
|
||||
|
||||
`mjp_defaultDecoder <#mjp_defaultDecoder>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mjp_defaultDecoder
|
||||
|
||||
Set default resource decoder definition.
|
||||
|
||||
.. _mjp_findDecoder:
|
||||
|
||||
`mjp_findDecoder <#mjp_findDecoder>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mjp_findDecoder
|
||||
|
||||
Return the resource provider with the prefix that matches against the resource name.
|
||||
|
||||
If no match, return NULL.
|
||||
|
||||
.. _Thread:
|
||||
|
||||
Threads
|
||||
|
||||
@@ -1563,6 +1563,16 @@ struct mjpResourceProvider {
|
||||
void* data; // opaque data pointer (resource invariant)
|
||||
};
|
||||
typedef struct mjpResourceProvider mjpResourceProvider;
|
||||
struct mjpDecoder {
|
||||
const char* content_type;
|
||||
const char* extension;
|
||||
// user-facing functions
|
||||
mjfCanDecode can_decode; // quickly check if this decoder can handle the resource
|
||||
mjfDecode decode; // main decoding function
|
||||
// the caller takes ownership of the spec returned by decode and is responsible
|
||||
// for cleaning it up
|
||||
};
|
||||
typedef struct mjpDecoder mjpDecoder;
|
||||
typedef enum mjtPluginCapabilityBit_ {
|
||||
mjPLUGIN_ACTUATOR = 1<<0, // actuator forces
|
||||
mjPLUGIN_SENSOR = 1<<1, // sensor measurements
|
||||
@@ -3014,6 +3024,8 @@ void mj_clearCache(mjCache* cache);
|
||||
mjModel* mj_loadXML(const char* filename, const mjVFS* vfs, char* error, int error_sz);
|
||||
mjSpec* mj_parseXML(const char* filename, const mjVFS* vfs, char* error, int error_sz);
|
||||
mjSpec* mj_parseXMLString(const char* xml, const mjVFS* vfs, char* error, int error_sz);
|
||||
mjSpec* mj_parse(const char* filename, const char* content_type,
|
||||
const mjVFS* vfs, char* error, int error_sz);
|
||||
mjModel* mj_compile(mjSpec* s, const mjVFS* vfs);
|
||||
int mj_copyBack(mjSpec* s, const mjModel* m);
|
||||
int mj_recompile(mjSpec* s, const mjVFS* vfs, mjModel* m, mjData* d);
|
||||
@@ -3431,6 +3443,9 @@ int mjp_registerResourceProvider(const mjpResourceProvider* provider);
|
||||
int mjp_resourceProviderCount(void);
|
||||
const mjpResourceProvider* mjp_getResourceProvider(const char* resource_name);
|
||||
const mjpResourceProvider* mjp_getResourceProviderAtSlot(int slot);
|
||||
void mjp_registerDecoder(const mjpDecoder* decoder);
|
||||
void mjp_defaultDecoder(mjpDecoder* decoder);
|
||||
const mjpDecoder* mjp_findDecoder(const mjResource* resource, const char* content_type);
|
||||
mjThreadPool* mju_threadPoolCreate(size_t number_of_threads);
|
||||
void mju_bindThreadPool(mjData* d, void* thread_pool);
|
||||
void mju_threadPoolEnqueue(mjThreadPool* thread_pool, mjTask* task);
|
||||
|
||||
Reference in New Issue
Block a user