add support for non-rgb textures in xml_native_writer

PiperOrigin-RevId: 736221430
Change-Id: I83c19e06f0f7be054a88c3e894807e7b90ee012a
This commit is contained in:
Tom Power
2025-03-12 12:16:31 -07:00
committed by Copybara-Service
parent 5c3bab4d09
commit 8f4c5c4b16
5 changed files with 55 additions and 6 deletions
+1
View File
@@ -60,6 +60,7 @@ extern const mjMap jac_map[];
extern const mjMap solver_map[];
extern const mjMap equality_map[];
extern const mjMap texture_map[];
extern const mjMap texrole_map[];
extern const mjMap builtin_map[];
extern const mjMap mark_map[];
extern const mjMap dyn_map[];
+16 -6
View File
@@ -323,6 +323,7 @@ void mjXWriter::OneMaterial(XMLElement* elem, const mjCMaterial* material, mjCDe
}
// defaults and regular
// check if we have non-rgb textures
bool has_non_rgb = false;
for (int i=1; i<mjNTEXROLE; i++) {
if (!material->textures_[i].empty()) {
@@ -330,14 +331,23 @@ void mjXWriter::OneMaterial(XMLElement* elem, const mjCMaterial* material, mjCDe
has_non_rgb = true;
}
}
if (material->textures_[i] != def->Material().textures_[i]) {
WriteAttrTxt(elem, "texture", material->get_texture(i));
}
// if we have non-rgb textures, write them as layers
if (has_non_rgb) {
for (int i=1; i<mjNTEXROLE; i++) {
if (!material->textures_[i].empty()) {
XMLElement * child_elem = InsertEnd(elem, "layer");
WriteAttrTxt(child_elem, "texture", material->textures_[i]);
WriteAttrTxt(child_elem, "role", FindValue(texrole_map, 9, i));
}
}
} else {
if (material->textures_[mjTEXROLE_RGB] != def->Material().textures_[mjTEXROLE_RGB]) {
WriteAttrTxt(elem, "texture", material->get_texture(mjTEXROLE_RGB));
}
}
if (has_non_rgb) {
// // TODO elem = InsertEnd(section, "role");
throw mjXError(0, "no support for non-RGB textures.");
}
WriteAttrKey(elem, "texuniform", bool_map, 2, material->texuniform, def->Material().texuniform);
WriteAttr(elem, "texrepeat", 2, material->texrepeat, def->Material().texrepeat);
WriteAttr(elem, "emission", 1, &material->emission, &def->Material().emission);