Specify is volume is too small or negative in mesh error messages. Fixes #799.
PiperOrigin-RevId: 525151156 Change-Id: Ia0e9d8b900b8c372e9229da934a4eb7aeb1a3b7a
This commit is contained in:
committed by
Copybara-Service
parent
d7ec409eb6
commit
94c4f72907
@@ -124,7 +124,7 @@ mjCMesh::mjCMesh(mjCModel* _model, mjCDef* _def) {
|
|||||||
invalidorientation.first = -1;
|
invalidorientation.first = -1;
|
||||||
invalidorientation.second = -1;
|
invalidorientation.second = -1;
|
||||||
validarea = true;
|
validarea = true;
|
||||||
validvolume = true;
|
validvolume = 1;
|
||||||
valideigenvalue = true;
|
valideigenvalue = true;
|
||||||
validinequality = true;
|
validinequality = true;
|
||||||
processed = false;
|
processed = false;
|
||||||
@@ -1060,7 +1060,7 @@ void mjCMesh::Process() {
|
|||||||
|
|
||||||
// require positive volume
|
// require positive volume
|
||||||
if (GetVolumeRef(type) < mjMINVAL) {
|
if (GetVolumeRef(type) < mjMINVAL) {
|
||||||
validvolume = false;
|
validvolume = GetVolumeRef(type) < 0 ? -1 : 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1196,6 +1196,8 @@ void mjCMesh::CheckMesh() {
|
|||||||
name.c_str(), invalidorientation.first, invalidorientation.second);
|
name.c_str(), invalidorientation.first, invalidorientation.second);
|
||||||
if (!validarea)
|
if (!validarea)
|
||||||
throw mjCError(this, "mesh surface area is too small: %s", name.c_str());
|
throw mjCError(this, "mesh surface area is too small: %s", name.c_str());
|
||||||
|
if (validvolume<0)
|
||||||
|
throw mjCError(this, "mesh volume is negative (misoriented triangles): %s", name.c_str());
|
||||||
if (!validvolume)
|
if (!validvolume)
|
||||||
throw mjCError(this, "mesh volume is too small: %s", name.c_str());
|
throw mjCError(this, "mesh volume is too small: %s", name.c_str());
|
||||||
if (!valideigenvalue)
|
if (!valideigenvalue)
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ class mjCMesh: public mjCBase {
|
|||||||
// mesh properties that indicate a well-formed mesh
|
// mesh properties that indicate a well-formed mesh
|
||||||
std::pair<int, int> invalidorientation; // indices of invalid edge; -1 if none
|
std::pair<int, int> invalidorientation; // indices of invalid edge; -1 if none
|
||||||
bool validarea; // false if the area is too small
|
bool validarea; // false if the area is too small
|
||||||
bool validvolume; // false if the volume is too small
|
int validvolume; // 0: volume is too small, -1: volume is negative
|
||||||
bool valideigenvalue; // false if inertia eigenvalue is too small
|
bool valideigenvalue; // false if inertia eigenvalue is too small
|
||||||
bool validinequality; // false if inertia inequality is not satisfied
|
bool validinequality; // false if inertia inequality is not satisfied
|
||||||
bool processed; // false if the mesh has not been processed yet
|
bool processed; // false if the mesh has not been processed yet
|
||||||
|
|||||||
@@ -464,7 +464,29 @@ TEST_F(MjCMeshTest, VolumeTooSmall) {
|
|||||||
EXPECT_THAT(error.data(), HasSubstr("mesh volume is too small"));
|
EXPECT_THAT(error.data(), HasSubstr("mesh volume is too small"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MjCMeshTest, VolumeTooSmallAllowedWorld) {
|
TEST_F(MjCMeshTest, VolumeNegative) {
|
||||||
|
static constexpr char xml[] = R"(
|
||||||
|
<mujoco>
|
||||||
|
<compiler exactmeshinertia="true"/>
|
||||||
|
<asset>
|
||||||
|
<mesh name="example_mesh"
|
||||||
|
vertex="0 0 0 1 0 0 0 1 0 0 0 1"
|
||||||
|
face="3 0 2 0 3 1 1 3 2 0 1 2" />
|
||||||
|
</asset>
|
||||||
|
<worldbody>
|
||||||
|
<body>
|
||||||
|
<geom type="mesh" mesh="example_mesh"/>
|
||||||
|
</body>
|
||||||
|
</worldbody>
|
||||||
|
</mujoco>
|
||||||
|
)";
|
||||||
|
std::array<char, 1024> error;
|
||||||
|
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
|
||||||
|
EXPECT_THAT(model, testing::IsNull());
|
||||||
|
EXPECT_THAT(error.data(), HasSubstr("mesh volume is negative"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(MjCMeshTest, VolumeTooSmallAllowedWorld) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<asset>
|
<asset>
|
||||||
|
|||||||
Reference in New Issue
Block a user