Add option to mjspec for creating a texture directly from a buffer.

PiperOrigin-RevId: 662186527
Change-Id: I469c876681d52964ac971c0bb2ec3517224d3a3d
This commit is contained in:
Alessio Quaglino
2024-08-12 12:26:39 -07:00
committed by Copybara-Service
parent 20cae556ee
commit 851bb6eef4
16 changed files with 267 additions and 95 deletions
+9 -1
View File
@@ -318,7 +318,7 @@ void mjXWriter::OneMaterial(XMLElement* elem, const mjCMaterial* pmat, mjCDef* d
}
if (has_non_rgb) {
// // TODO elem = InsertEnd(section, "role");
mju_error("mjXWriter: no support for non-RGB textures.");
throw mjXError(0, "no support for non-RGB textures.");
}
WriteAttrKey(elem, "texuniform", bool_map, 2, pmat->texuniform, def->Material().texuniform);
WriteAttr(elem, "texrepeat", 2, pmat->texrepeat, def->Material().texrepeat);
@@ -1452,6 +1452,14 @@ void mjXWriter::Asset(XMLElement* root) {
WriteAttrInt(elem, "height", ptex->height);
}
// write buffer
else if (ptex->get_cubefiles()[0].empty() && ptex->get_cubefiles()[1].empty() &&
ptex->get_cubefiles()[2].empty() && ptex->get_cubefiles()[3].empty() &&
ptex->get_cubefiles()[4].empty() && ptex->get_cubefiles()[5].empty() &&
ptex->get_file().empty() && ptex->gridsize[0] == 1 && ptex->gridsize[1] == 1) {
throw mjXError(0, "no support for buffer textures.");
}
// write textures loaded from files
else {
// write single file