Change private->public spec for error checking in mjCSkin recompilation.

Fixes #2485.

PiperOrigin-RevId: 735323174
Change-Id: Ifcc2055f6a74afaa18ad5228633f36f760adcffd
This commit is contained in:
Alessio Quaglino
2025-03-10 04:18:32 -07:00
committed by Copybara-Service
parent 4d024f9421
commit adc3cc06fa
5 changed files with 37 additions and 10 deletions
+9 -10
View File
@@ -2526,16 +2526,15 @@ void mjCSkin::Compile(const mjVFS* vfs) {
// load file
if (!file_.empty()) {
// make sure data is not present
if (!vert_.empty() ||
!texcoord_.empty() ||
!face_.empty() ||
!bodyname_.empty() ||
!bindpos_.empty() ||
!bindquat_.empty() ||
!vertid_.empty() ||
!vertweight_.empty() ||
!bodyid.empty()) {
throw mjCError(this, "Data already exists, trying to load from skin file: %s", file_.c_str());
if (!spec_vert_.empty() ||
!spec_texcoord_.empty() ||
!spec_face_.empty() ||
!spec_bodyname_.empty() ||
!spec_bindpos_.empty() ||
!spec_bindquat_.empty() ||
!spec_vertid_.empty() ||
!spec_vertweight_.empty()) {
throw mjCError(this, "Both skin data and file were specified: %s", file_.c_str());
}
// remove path from file if necessary
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
<mujoco>
<asset>
<mesh name="cube" file="cube.stl" scale=".05 .05 .05"/>
<skin name="skin" file="cube.skn"/>
</asset>
<worldbody>
<body name="box">
<geom type="box" mesh="cube"/>
</body>
</worldbody>
</mujoco>
+15
View File
@@ -66,6 +66,8 @@ static const char* const kDuplicateOBJPath =
"user/testdata/duplicate.xml";
static const char* const kMalformedFaceOBJPath =
"user/testdata/malformed_face.xml";
static const char* const kCubeSkinPath =
"user/testdata/cube_skin.xml";
using ::testing::ElementsAre;
using ::testing::HasSubstr;
@@ -1184,6 +1186,19 @@ TEST_F(MjCMeshTest, InvalidIndexInFace) {
mj_deleteModel(model);
}
TEST_F(MjCMeshTest, LoadSkin) {
const std::string xml_path = GetTestDataFilePath(kCubeSkinPath);
std::array<char, 1024> error;
mjSpec* spec = mj_parseXML(xml_path.c_str(), 0, error.data(), error.size());
EXPECT_THAT(spec, NotNull()) << error.data();
mjModel* m1 = mj_compile(spec, 0);
EXPECT_THAT(m1, NotNull());
mj_deleteModel(m1);
mjModel* m2 = mj_compile(spec, 0);
EXPECT_THAT(m2, NotNull());
mj_deleteModel(m2);
mj_deleteSpec(spec);
}
} // namespace