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
@@ -3404,25 +3404,24 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
||||
|
||||
// model sub-element
|
||||
else if (name == "model") {
|
||||
string content_type;
|
||||
if (!ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
content_type = "text/xml";
|
||||
}
|
||||
std::string content_type;
|
||||
ReadAttrTxt(elem, "content_type", content_type);
|
||||
|
||||
// parse the child
|
||||
mjSpec* child = nullptr;
|
||||
std::array<char, 1024> error;
|
||||
auto filename = modelfiledir_ + ReadAttrFile(elem, "file", vfs).value();
|
||||
|
||||
if (content_type == "text/xml") {
|
||||
child = mj_parseXML(filename.c_str(), vfs, error.data(), error.size());
|
||||
#ifdef mjUSEUSD
|
||||
} else if (content_type == "text/usd") {
|
||||
if (content_type == "text/usd") {
|
||||
child = mj_parseUSD(filename.c_str(), vfs, error.data(), error.size());
|
||||
#endif // mjUSEUSD
|
||||
} else {
|
||||
throw mjXError(elem, "unsupported content_type: %s", content_type.c_str());
|
||||
#endif // mjUSEUSD
|
||||
child = mj_parse(filename.c_str(), content_type.c_str(), vfs,
|
||||
error.data(), error.size());
|
||||
#ifdef mjUSEUSD
|
||||
}
|
||||
#endif // mjUSEUSD
|
||||
|
||||
if (!child) {
|
||||
throw mjXError(elem, "could not parse model file with error: %s", error.data());
|
||||
|
||||
Reference in New Issue
Block a user