Add MjSpec.encode method.
PiperOrigin-RevId: 907177387 Change-Id: I65800298798037c4a0c0cd79ec86706be67db51e
This commit is contained in:
committed by
Copybara-Service
parent
ace90c00b9
commit
d92fe0810c
@@ -20,6 +20,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
@@ -143,6 +144,18 @@ mjSpec* mj_parse(const char* filename, const char* content_type,
|
||||
int mj_encode(const mjSpec* s, const mjModel* m, const char* filename,
|
||||
const char* content_type, const mjVFS* vfs, char* error,
|
||||
int error_sz) {
|
||||
// TODO(shaves) Move MJCF and URDF to encoders/decoders.
|
||||
auto filepath = mujoco::user::FilePath(filename);
|
||||
if (filepath.Ext() == ".xml" ||
|
||||
(content_type && std::strcmp(content_type, "text/xml") == 0)) {
|
||||
int result = mj_saveXML(s, filename, error, error_sz);
|
||||
if (result < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return std::filesystem::file_size(filename);
|
||||
}
|
||||
|
||||
const mjpEncoder* encoder = mjp_findEncoder(filename, content_type);
|
||||
if (!encoder) {
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user