Save flex node coordinates in the new nodecoord attribute.

Interpolated flexes with pinned nodes could not be reloaded after saving:
pinned nodes share their parent body, and their positions within it lived
only in mjsFlex.node, which had no MJCF attribute. On reload the pinned
nodes collapsed onto the parent body origin, degenerating the trilinear
interpolation grid ("flex grid rotation R0 is not orthonormal"). This
made model/flex/strain.xml and gripper_trilinear.xml fail to round-trip.

Add flex/nodecoord, real(3*nnode), the node analog of flex/vertex: local
node coordinates within the corresponding body frames. The reader picks
it up from the regenerated schema tables; the writer emits it with the
precision-aware WriteVector, since VectorToString ignores the XML
precision setting and truncating node coordinates to 6 digits while body
positions carry 17 fails the R0 orthonormality check at full precision.

Add a WritesPinnedFlexNodes round-trip regression test, and remove the
two write-read sweep exclusions documenting this bug. The removed
substring filter "strain" was also matching core_constraint, silently
excluding that entire testdata directory from the sweep; its ~40 models
are now covered and pass.

PiperOrigin-RevId: 959025281
Change-Id: I2fed28c01491c5a8431e813102a423d12b659911
This commit is contained in:
Yuval Tassa
2026-08-04 08:03:25 -07:00
committed by Copybara-Service
parent 574b6bd6bf
commit 9553926158
11 changed files with 56 additions and 4 deletions
+29
View File
@@ -936,6 +936,35 @@ TEST_F(XMLWriterTest, WritesSkin) {
EXPECT_THAT(mtemp->nskin, 1);
}
TEST_F(XMLWriterTest, WritesPinnedFlexNodes) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body name="parent">
<flexcomp name="soft" type="box" count="3 3 3" spacing=".03 .01 .01" mass=".5" dof="trilinear">
<contact selfcollide="none" internal="false"/>
<edge equality="true"/>
<pin id="4 5 6 7"/>
</flexcomp>
</body>
</worldbody>
</mujoco>
)";
MjModelPtr model = LoadModelFromString(xml);
ASSERT_THAT(model.get(), NotNull());
// pinned nodes have no body of their own: their coordinates in the parent
// body frame must be saved or the interpolation grid degenerates on reload
std::string saved_xml = SaveAndReadXml(model.get());
EXPECT_THAT(saved_xml, HasSubstr("nodecoord"));
char error[1024];
MjModelPtr mtemp = LoadModelFromString(saved_xml, error, sizeof(error));
ASSERT_THAT(mtemp.get(), NotNull()) << error;
EXPECT_EQ(SaveAndReadXml(mtemp.get()), saved_xml);
}
TEST_F(XMLWriterTest, WritesHfield) {
static constexpr char xml[] = R"(
<mujoco>
-3
View File
@@ -67,9 +67,6 @@ std::vector<std::string> GetWriteReadTestModels() {
absl::StrContains(xml, "cube_3x3x3") ||
// flex_stiffness: stretch amplifies geometry XML rounds on save
absl::StrContains(xml, "flex/bag") ||
// exclude files that fail since we do not save pinned flex nodes
absl::StrContains(xml, "gripper_trilinear") ||
absl::StrContains(xml, "strain") ||
// exclude conflict tests (known option conflict warnings/errors)
absl::StrContains(xml, "xml/testdata/parent_")) {
continue;