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:
committed by
Copybara-Service
parent
7e16ecaa25
commit
6320b95957
@@ -16,6 +16,7 @@
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
from etils import epath
|
||||
import pickle
|
||||
import sys
|
||||
|
||||
@@ -1658,6 +1659,16 @@ Euler integrator, semi-implicit in velocity.
|
||||
model = mujoco.MjModel.from_xml_string(TEST_XML_TEXTURE)
|
||||
self.assertEqual(model.tex('tex').data.shape, (512, 512, 3))
|
||||
|
||||
def test_xml_dependencies(self):
|
||||
model_path = str(epath.resource_path("mujoco") / "testdata" / "msh.xml")
|
||||
msh_path =str(epath.resource_path("mujoco") / "testdata" / "abdomen_1_body.msh")
|
||||
|
||||
model_path = model_path.replace('\\', '/')
|
||||
msh_path = msh_path.replace('\\', '/')
|
||||
dependencies = mujoco.mju_getXMLDependencies(model_path)
|
||||
self.assertIn(model_path, dependencies)
|
||||
self.assertIn(msh_path, dependencies)
|
||||
|
||||
def _assert_attributes_equal(self, actual_obj, expected_obj, attr_to_compare):
|
||||
for name in attr_to_compare:
|
||||
actual_value = getattr(actual_obj, name)
|
||||
|
||||
@@ -99,6 +99,14 @@ PYBIND11_MODULE(_functions, pymodule) {
|
||||
return std::string(buffer.get(), out_length);
|
||||
});
|
||||
|
||||
DEF_WITH_OMITTED_PY_ARGS(traits::mju_getXMLDependencies,
|
||||
"dependencies")(
|
||||
pymodule, [](const char* filename){
|
||||
mjStringVec dependencies;
|
||||
InterceptMjErrors(::mju_getXMLDependencies)(filename, &dependencies);
|
||||
return dependencies;
|
||||
});
|
||||
|
||||
// Main simulation
|
||||
pymodule.def(
|
||||
"mj_step",
|
||||
|
||||
@@ -3925,6 +3925,26 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
),
|
||||
doc='Intersect ray with skin, return nearest distance or -1 if no intersection, and also output nearest vertex id.', # pylint: disable=line-too-long
|
||||
)),
|
||||
('mju_getXMLDependencies',
|
||||
FunctionDecl(
|
||||
name='mju_getXMLDependencies',
|
||||
return_type=ValueType(name='void'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='filename',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='char', is_const=True),
|
||||
),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='dependencies',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjStringVec'),
|
||||
),
|
||||
),
|
||||
),
|
||||
doc='Given MJCF filename, fills dependencies with a list of all other files it depends on.', # pylint: disable=line-too-long
|
||||
)),
|
||||
('mjv_defaultCamera',
|
||||
FunctionDecl(
|
||||
name='mjv_defaultCamera',
|
||||
|
||||
Reference in New Issue
Block a user