Add support for loading 1D flex components from OBJ line segments.

The obj_decoder plugin is updated to parse line segments ('l') from OBJ files and represent them as degenerate triangles. The user_flexcomp compiler now supports flex dimensions of 1, using these parsed line segments to define the 1D flex elements. The compile sample's error reporting is also improved.

PiperOrigin-RevId: 928566870
Change-Id: I6920729d1b1d5aeb391401c3245ebb1d4784c190
This commit is contained in:
Alessio Quaglino
2026-06-08 08:03:04 -07:00
committed by Copybara-Service
parent ac7f198536
commit 7a7dc7ccad
6 changed files with 107 additions and 33 deletions
+5
View File
@@ -0,0 +1,5 @@
<mujoco>
<worldbody>
<flexcomp name="line" type="mesh" file="line.obj" dim="1" radius="0.1"/>
</worldbody>
</mujoco>
+6
View File
@@ -0,0 +1,6 @@
v 0 0 0
v 2 0 0
v 1 0 0
v 3 0 0
l 1 3 2
l 2 4
+12
View File
@@ -1399,6 +1399,18 @@ TEST_F(UserFlexTest, Vert0RotationInvariant) {
mj_deleteModel(m2);
}
TEST_F(UserFlexTest, Load1DFlexFromOBJ) {
const std::string xml_path =
GetTestDataFilePath("user/testdata/flex_line_obj.xml");
std::array<char, 1024> error;
mjModel* m = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size());
ASSERT_THAT(m, NotNull()) << error.data();
EXPECT_EQ(m->nflexvert, 4);
EXPECT_EQ(m->nflexelem, 3);
EXPECT_EQ(m->flex_dim[0], 1);
mj_deleteModel(m);
}
} // namespace
} // namespace mujoco