Add mju_getXMLDependencies that given an MJCF file returns filepaths to all of it's dependencies.

PiperOrigin-RevId: 814203235
Change-Id: Ib5c2e2f4dd42224a768c88d76473544190c72bc0
This commit is contained in:
Sam Haves
2025-10-02 06:13:59 -07:00
committed by Copybara-Service
parent 7e16ecaa25
commit 6320b95957
15 changed files with 342 additions and 1 deletions
+2
View File
@@ -16,6 +16,8 @@ mujoco_test(xml_api_test)
mujoco_test(xml_native_reader_test)
mujoco_test(xml_utils_test)
mujoco_test(
xml_native_writer_test
ADDITIONAL_LINK_LIBRARIES
+21
View File
@@ -0,0 +1,21 @@
<mujoco>
<include file="child.xml"/>
<compiler meshdir="meshes"/>
<asset>
<model name="other" file="parent_model.xml"/>
<mesh name="mesh1" file="mesh1.obj"/>
</asset>
<worldbody>
<body name="my_parent">
<geom name="my_geom" size="2"/>
<flexcomp type="mesh" file="flex.obj" name="flex" rigid="true"/>
</body>
<body name="box">
<geom type="box" mesh="mesh1"/>
</body>
</worldbody>
<deformable>
<skin name="skin" file="cube.skn"/>
</deformable>
</mujoco>
Binary file not shown.
+39
View File
@@ -0,0 +1,39 @@
# Simple Cube - OBJ File
# Vertices (v)
# 8 corners of the cube
# Back Face
v -1.0 -1.0 -1.0
v 1.0 -1.0 -1.0
v 1.0 1.0 -1.0
v -1.0 1.0 -1.0
# Front Face
v -1.0 -1.0 1.0
v 1.0 -1.0 1.0
v 1.0 1.0 1.0
v -1.0 1.0 1.0
# Faces (f)
# A cube has 6 faces. Each face is a quad, defined by 4 vertices.
# The vertices are numbered according to their order of appearance above, starting from 1.
# The order defines the face normal (front-facing) based on the right-hand rule.
# Back Face (v1, v2, v3, v4)
f 1 2 3 4
# Right Face (v2, v6, v7, v3)
f 2 6 7 3
# Front Face (v5, v8, v7, v6) - Note the ordering for correct normal
f 5 8 7 6
# Left Face (v1, v4, v8, v5)
f 1 4 8 5
# Top Face (v4, v3, v7, v8)
f 4 3 7 8
# Bottom Face (v1, v5, v6, v2)
f 1 5 6 2
+39
View File
@@ -0,0 +1,39 @@
# Simple Cube - OBJ File
# Vertices (v)
# 8 corners of the cube
# Back Face
v -1.0 -1.0 -1.0
v 1.0 -1.0 -1.0
v 1.0 1.0 -1.0
v -1.0 1.0 -1.0
# Front Face
v -1.0 -1.0 1.0
v 1.0 -1.0 1.0
v 1.0 1.0 1.0
v -1.0 1.0 1.0
# Faces (f)
# A cube has 6 faces. Each face is a quad, defined by 4 vertices.
# The vertices are numbered according to their order of appearance above, starting from 1.
# The order defines the face normal (front-facing) based on the right-hand rule.
# Back Face (v1, v2, v3, v4)
f 1 2 3 4
# Right Face (v2, v6, v7, v3)
f 2 6 7 3
# Front Face (v5, v8, v7, v6) - Note the ordering for correct normal
f 5 8 7 6
# Left Face (v1, v4, v8, v5)
f 1 4 8 5
# Top Face (v4, v3, v7, v8)
f 4 3 7 8
# Bottom Face (v1, v5, v6, v2)
f 1 5 6 2
+11
View File
@@ -0,0 +1,11 @@
<mujoco>
<asset>
<model name="other" file="child.xml"/>
</asset>
<worldbody>
<body name="parent">
<geom name="geom" size="2"/>
<attach model="other" body="body" prefix="other"/>
</body>
</worldbody>
</mujoco>
+1
View File
@@ -1388,6 +1388,7 @@ TEST_F(XMLWriterTest, WriteReadCompare) {
// exclude files that fail the comparison test
absl::StrContains(p.path().string(), "tactile") ||
absl::StrContains(p.path().string(), "makemesh") ||
absl::StrContains(p.path().string(), "many_dependencies") ||
absl::StrContains(p.path().string(), "usd") ||
absl::StrContains(p.path().string(), "torus_maxhull") ||
absl::StrContains(p.path().string(), "fitmesh_") ||
+46
View File
@@ -0,0 +1,46 @@
// Copyright 2025 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <set>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include <mujoco/mujoco.h>
#include "test/fixture.h"
namespace mujoco {
namespace {
TEST_F(MujocoTest, GetXMLDependenciesTest) {
static const std::vector<std::string> kModelPaths = {
GetTestDataFilePath("xml/testdata/many_dependencies.xml"),
GetTestDataFilePath("xml/testdata/parent_model.xml"),
GetTestDataFilePath("xml/testdata/child.xml"),
GetTestDataFilePath("xml/testdata/meshes/mesh1.obj"),
GetTestDataFilePath("xml/testdata/meshes/flex.obj"),
GetTestDataFilePath("xml/testdata/meshes/cube.skn"),
};
mjStringVec dependencies;
mju_getXMLDependencies(kModelPaths[0].c_str(), &dependencies);
std::set<std::string> dependency_set{dependencies.begin(),
dependencies.end()};
std::set<std::string> expected_dependency_set{kModelPaths.begin(),
kModelPaths.end()};
EXPECT_EQ(dependency_set, expected_dependency_set);
}
} // namespace
} // namespace mujoco