Store model paths in assets.

This enables to preserve the paths of the child spec during `attach`.

PiperOrigin-RevId: 673349237
Change-Id: Ibf075c7ec037ff5d540bc60d6e77c12f60269791
This commit is contained in:
Alessio Quaglino
2024-09-11 05:19:08 -07:00
committed by Copybara-Service
parent cf721def3a
commit 567793c26f
5 changed files with 136 additions and 12 deletions
+43
View File
@@ -17,6 +17,7 @@
#include <array>
#include <cmath>
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
@@ -502,5 +503,47 @@ TEST_F(LengthRangeTest, LengthRangeThreading) {
mj_deleteSpec(spec);
}
// ----------------------------- test modeldir --------------------------------
TEST_F(MujocoTest, Modeldir) {
static constexpr char cube[] = R"(
v -1 -1 1
v 1 -1 1
v -1 1 1
v 1 1 1
v -1 1 -1
v 1 1 -1
v -1 -1 -1
v 1 -1 -1)";
auto vfs = std::make_unique<mjVFS>();
mj_defaultVFS(vfs.get());
mj_addBufferVFS(vfs.get(), "meshdir/cube.obj", cube, sizeof(cube));
// child with the asset
mjSpec* child = mj_makeSpec();
mjsMesh* mesh = mjs_addMesh(child, 0);
mjsFrame* frame = mjs_addFrame(mjs_findBody(child, "world"), 0);
mjsGeom* geom = mjs_addGeom(mjs_findBody(child, "world"), 0);
mjs_setString(child->meshdir, "meshdir");
mjs_setString(mesh->file, "cube.obj");
mjs_setString(mesh->name, "cube");
mjs_setString(geom->meshname, "cube");
mjs_setFrame(geom->element, frame);
geom->type = mjGEOM_MESH;
// parent attaching the child
mjSpec* spec = mj_makeSpec();
mjs_setString(spec->meshdir, "asset");
mjs_attachFrame(mjs_findBody(spec, "world"), frame, "_", "");
mjModel* model = mj_compile(spec, vfs.get());
EXPECT_THAT(model, NotNull());
mj_deleteSpec(child);
mj_deleteSpec(spec);
mj_deleteModel(model);
mj_deleteVFS(vfs.get());
}
} // namespace
} // namespace mujoco