Skip to content

Commit adc3cc0

Browse files
quaglacopybara-github
authored andcommitted
Change private->public spec for error checking in mjCSkin recompilation.
Fixes #2485. PiperOrigin-RevId: 735323174 Change-Id: Ifcc2055f6a74afaa18ad5228633f36f760adcffd
1 parent 4d024f9 commit adc3cc0

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

src/user/user_mesh.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -2526,16 +2526,15 @@ void mjCSkin::Compile(const mjVFS* vfs) {
25262526
// load file
25272527
if (!file_.empty()) {
25282528
// make sure data is not present
2529-
if (!vert_.empty() ||
2530-
!texcoord_.empty() ||
2531-
!face_.empty() ||
2532-
!bodyname_.empty() ||
2533-
!bindpos_.empty() ||
2534-
!bindquat_.empty() ||
2535-
!vertid_.empty() ||
2536-
!vertweight_.empty() ||
2537-
!bodyid.empty()) {
2538-
throw mjCError(this, "Data already exists, trying to load from skin file: %s", file_.c_str());
2529+
if (!spec_vert_.empty() ||
2530+
!spec_texcoord_.empty() ||
2531+
!spec_face_.empty() ||
2532+
!spec_bodyname_.empty() ||
2533+
!spec_bindpos_.empty() ||
2534+
!spec_bindquat_.empty() ||
2535+
!spec_vertid_.empty() ||
2536+
!spec_vertweight_.empty()) {
2537+
throw mjCError(this, "Both skin data and file were specified: %s", file_.c_str());
25392538
}
25402539

25412540
// remove path from file if necessary

test/user/testdata/cube.skn

504 Bytes
Binary file not shown.

test/user/testdata/cube.stl

684 Bytes
Binary file not shown.

test/user/testdata/cube_skin.xml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<mujoco>
2+
<asset>
3+
<mesh name="cube" file="cube.stl" scale=".05 .05 .05"/>
4+
<skin name="skin" file="cube.skn"/>
5+
</asset>
6+
7+
<worldbody>
8+
<body name="box">
9+
<geom type="box" mesh="cube"/>
10+
</body>
11+
12+
</worldbody>
13+
</mujoco>

test/user/user_mesh_test.cc

+15
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ static const char* const kDuplicateOBJPath =
6666
"user/testdata/duplicate.xml";
6767
static const char* const kMalformedFaceOBJPath =
6868
"user/testdata/malformed_face.xml";
69+
static const char* const kCubeSkinPath =
70+
"user/testdata/cube_skin.xml";
6971

7072
using ::testing::ElementsAre;
7173
using ::testing::HasSubstr;
@@ -1184,6 +1186,19 @@ TEST_F(MjCMeshTest, InvalidIndexInFace) {
11841186
mj_deleteModel(model);
11851187
}
11861188

1189+
TEST_F(MjCMeshTest, LoadSkin) {
1190+
const std::string xml_path = GetTestDataFilePath(kCubeSkinPath);
1191+
std::array<char, 1024> error;
1192+
mjSpec* spec = mj_parseXML(xml_path.c_str(), 0, error.data(), error.size());
1193+
EXPECT_THAT(spec, NotNull()) << error.data();
1194+
mjModel* m1 = mj_compile(spec, 0);
1195+
EXPECT_THAT(m1, NotNull());
1196+
mj_deleteModel(m1);
1197+
mjModel* m2 = mj_compile(spec, 0);
1198+
EXPECT_THAT(m2, NotNull());
1199+
mj_deleteModel(m2);
1200+
mj_deleteSpec(spec);
1201+
}
11871202

11881203

11891204
} // namespace

0 commit comments

Comments
 (0)