Save <compiler {boundmass/boundinertia}> if nonzero.
Fixes #928 PiperOrigin-RevId: 560967976 Change-Id: Idc8c043278362d8925ce41061c65f3e678ad50ce
This commit is contained in:
committed by
Copybara-Service
parent
8ba3291365
commit
55173e58f9
@@ -768,6 +768,12 @@ void mjXWriter::Compiler(XMLElement* root) {
|
||||
if (model->exactmeshinertia) {
|
||||
WriteAttrTxt(section, "exactmeshinertia", "true");
|
||||
}
|
||||
if (model->boundmass) {
|
||||
WriteAttr(section, "boundmass", 1, &model->boundmass);
|
||||
}
|
||||
if (model->boundinertia) {
|
||||
WriteAttr(section, "boundinertia", 1, &model->boundinertia);
|
||||
}
|
||||
// always enable autolimits. limited attributes will be written appropriately
|
||||
// TODO(b/245077553): Remove this when the default is true.
|
||||
WriteAttrTxt(section, "autolimits", "true");
|
||||
|
||||
@@ -208,6 +208,34 @@ TEST_F(XMLWriterTest, NotAddsInertial) {
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, KeepsBoundMassInertia) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
<compiler boundmass="0.1" boundinertia="0.2"/>
|
||||
</mujoco>
|
||||
)";
|
||||
mjModel* model = LoadModelFromString(xml);
|
||||
ASSERT_THAT(model, NotNull());
|
||||
std::string saved_xml = SaveAndReadXml(model);
|
||||
EXPECT_THAT(saved_xml, HasSubstr("boundmass=\"0.1\""));
|
||||
EXPECT_THAT(saved_xml, HasSubstr("boundinertia=\"0.2\""));
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, DropsZeroBoundMassInertia) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
<compiler boundmass="0" boundinertia="0"/>
|
||||
</mujoco>
|
||||
)";
|
||||
mjModel* model = LoadModelFromString(xml);
|
||||
ASSERT_THAT(model, NotNull());
|
||||
std::string saved_xml = SaveAndReadXml(model);
|
||||
EXPECT_THAT(saved_xml, Not(HasSubstr("boundmass")));
|
||||
EXPECT_THAT(saved_xml, Not(HasSubstr("boundinertia")));
|
||||
mj_deleteModel(model);
|
||||
}
|
||||
|
||||
TEST_F(XMLWriterTest, DropsInertialIfFromGeom) {
|
||||
static constexpr char xml[] = R"(
|
||||
<mujoco>
|
||||
|
||||
Reference in New Issue
Block a user