From ad80a4625b3d7fd916709de3fab88d5e687b81e7 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Thu, 8 May 2025 09:45:43 -0700 Subject: [PATCH] Always generate a BVH in flex. The BVH is used also for computing normalized vertex coordinates in the trilinear interpolation, so we need to compute it also when the flex cannot collide. PiperOrigin-RevId: 756349244 Change-Id: Ib397c472e31251df5a7ea85850d83a62f3b2c949 --- src/user/user_mesh.cc | 3 ++- test/user/user_flex_test.cc | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index e03896ed..93c10004 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -3624,8 +3624,9 @@ void mjCFlex::CreateBVH() { elemaabb_[6*e+5] = 0.5*(xmax[2]-xmin[2]) + radius; // add bounding volume for this element + // contype and conaffinity are set to nonzero to force bvh generation const double* aabb = elemaabb_.data() + 6*e; - tree.AddBoundingVolume(e, contype, conaffinity, aabb, nullptr, aabb); + tree.AddBoundingVolume(e, 1, 1, aabb, nullptr, aabb); nbvh++; } diff --git a/test/user/user_flex_test.cc b/test/user/user_flex_test.cc index a43b93f0..492c4170 100644 --- a/test/user/user_flex_test.cc +++ b/test/user/user_flex_test.cc @@ -243,6 +243,27 @@ TEST_F(UserFlexTest, RigidFlex) { mj_deleteModel(m); mj_deleteData(d); } + +TEST_F(UserFlexTest, FlexNotCollide) { + static constexpr char xml[] = R"( + + + + + + + + )"; + std::array error; + mjModel* m = LoadModelFromString(xml, error.data(), error.size()); + ASSERT_THAT(m, NotNull()) << error.data(); + mjData* d = mj_makeData(m); + mj_step(m, d); + mj_deleteModel(m); + mj_deleteData(d); +} + TEST_F(UserFlexTest, BoundingBoxCoordinates) { static constexpr char xml[] = R"(