Change row-flipping logic for heightfields.

Move row-flipping logic from `mjCModel::CopyBack` to `mjXWriter`.

PiperOrigin-RevId: 842220322
Change-Id: I6fb09db6c9e8689f6e435f82f58dd3e7c4314478
This commit is contained in:
Yuval Tassa
2025-12-09 07:01:16 -08:00
committed by Copybara-Service
parent 925c533580
commit c064abc3da
5 changed files with 43 additions and 10 deletions
+15 -3
View File
@@ -1585,11 +1585,23 @@ void mjXWriter::Asset(XMLElement* root) {
WriteAttrTxt(elem, "content_type", hfield->content_type_);
WriteAttrTxt(elem, "file", hfield->file_);
} else {
WriteAttrInt(elem, "nrow", hfield->nrow);
WriteAttrInt(elem, "ncol", hfield->ncol);
int nrow = hfield->nrow;
int ncol = hfield->ncol;
WriteAttrInt(elem, "nrow", nrow);
WriteAttrInt(elem, "ncol", ncol);
if (!hfield->get_userdata().empty()) {
// copy in reverse row order, so XML string is top-to-bottom
std::vector<float> flipped(nrow * ncol);
const std::vector<float>& userdata = hfield->get_userdata();
for (int i = 0; i < nrow; i++) {
int flip = nrow - 1 - i;
for (int j = 0; j < ncol; j++) {
flipped[i * ncol + j] = userdata[flip * ncol + j];
}
}
string text;
Vector2String(text, hfield->get_userdata(), hfield->ncol);
Vector2String(text, flipped, ncol);
WriteAttrTxt(elem, "elevation", text);
}
}