Add body/simple attribute to control simple body optimization.

PiperOrigin-RevId: 942164766
Change-Id: I1e83bb99b6a1955917eb9b2e9bed0dc7b8e6a161
This commit is contained in:
Yuval Tassa
2026-07-03 09:08:42 -07:00
committed by Copybara-Service
parent 4ecfe5c1f3
commit 5618666a7d
19 changed files with 205 additions and 10 deletions
+36
View File
@@ -1590,5 +1590,41 @@ TEST_F(XMLWriterTest, WritesActuatorDelayHistory) {
EXPECT_THAT(saved_xml, HasSubstr("interp=\"cubic\""));
}
TEST_F(XMLWriterTest, BodySimpleRoundtrip) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body name="B1" simple="false">
<joint type="ball"/>
<geom size=".1"/>
</body>
</worldbody>
</mujoco>
)";
MjModelPtr model = LoadModelFromString(xml);
ASSERT_THAT(model.get(), NotNull());
std::string saved_xml = SaveAndReadXml(model.get());
EXPECT_THAT(saved_xml, HasSubstr("simple=\"false\""));
// auto should not be written
static constexpr char xml_auto[] = R"(
<mujoco>
<worldbody>
<body name="B1">
<joint type="ball"/>
<geom size=".1"/>
</body>
</worldbody>
</mujoco>
)";
MjModelPtr model_auto = LoadModelFromString(xml_auto);
ASSERT_THAT(model_auto.get(), NotNull());
std::string saved_auto = SaveAndReadXml(model_auto.get());
EXPECT_THAT(saved_auto, Not(HasSubstr("simple=")));
// nC should increase when simple is disabled
EXPECT_GT(model->nC, model_auto->nC);
}
} // namespace
} // namespace mujoco