Don't save body pos if "0 0 0".
PiperOrigin-RevId: 520598416 Change-Id: I5bb6ffaec386f228ac7a5fa221822000635900ae
This commit is contained in:
committed by
Copybara-Service
parent
3f9defa8d0
commit
1d6a9e09bb
@@ -1321,7 +1321,11 @@ void mjXWriter::Body(XMLElement* elem, mjCBody* body) {
|
||||
if (body!=model->GetWorld()) {
|
||||
WriteAttrTxt(elem, "name", body->name);
|
||||
WriteAttrTxt(elem, "childclass", body->classname);
|
||||
WriteAttr(elem, "pos", 3, body->locpos);
|
||||
|
||||
// write pos if it's not {0, 0, 0}
|
||||
if (body->locpos[0] || body->locpos[1] || body->locpos[2]) {
|
||||
WriteAttr(elem, "pos", 3, body->locpos);
|
||||
}
|
||||
WriteAttr(elem, "quat", 4, body->locquat, unitq);
|
||||
if (body->mocap) {
|
||||
WriteAttrKey(elem, "mocap", bool_map, 2, 1);
|
||||
|
||||
@@ -601,6 +601,23 @@ TEST_F(XMLWriterTest, WritesGravComp) {
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, WritesBodyPos) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
<worldbody>
|
||||
<body pos="1 2 3"/>
|
||||
<body pos="0 0 0"/>
|
||||
</worldbody>
|
||||
</mujoco>
|
||||
)";
|
||||
mjModel* model = LoadModelFromString(xml);
|
||||
ASSERT_THAT(model, NotNull());
|
||||
std::string saved_xml = SaveAndReadXml(model);
|
||||
EXPECT_THAT(saved_xml, HasSubstr("pos=\"1 2 3\""));
|
||||
EXPECT_THAT(saved_xml, Not(HasSubstr("pos=\"0 0 0\"")));
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, UndefinedMassDensity) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
|
||||
Reference in New Issue
Block a user