-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Intro
Hi!
My setup
Version: mujoco==3.5.0
API: Python
Architecture: macos_arm64
What's happening? What did you expect?
The MjSpec.to_zip documentation says that:
The
MjSpecobject can be serialized with all of its assets using the functionspec.to_zip(file)...
I was expecting that I could serialize a model that references external assets (like meshes, textures, etc.) in the spec, e.g. loaded from XML via <assets> tag. However, MjSpec.to_zip only includes assets that are explicitly present in spec.assets dictionary. It does not iterate over the model elements (meshes, textures, skins, hfields) to check for file references and include those files. This makes the zip file unusable for most of my use cases.
mujoco/python/mujoco/__init__.py
Lines 93 to 109 in 2efca34
| def to_zip(spec: _specs.MjSpec, file: Union[str, IO[bytes]]) -> None: | |
| """Converts an MjSpec to a zip file. | |
| Args: | |
| spec: The mjSpec to save to a file. | |
| file: The path to the file to save to or the file object to write to. | |
| """ | |
| files_to_zip = spec.assets | |
| files_to_zip[spec.modelname + '.xml'] = spec.to_xml() | |
| if isinstance(file, str): | |
| directory = os.path.dirname(file) | |
| os.makedirs(directory, exist_ok=True) | |
| file = open(file, 'wb') | |
| with zipfile.ZipFile(file, 'w') as zip_file: | |
| for filename, contents in files_to_zip.items(): | |
| zip_info = zipfile.ZipInfo(filename) | |
| zip_file.writestr(zip_info, contents) |
Steps for reproduction
Load any model with "external" assets defined e.g. in the .xml <assets> tag. Dump the model with spec.to_zip(...) and try loading it.
Minimal model for reproduction
No response
Code required for reproduction
No response
Confirmations
- I searched the latest documentation thoroughly before posting.
- I searched previous Issues and Discussions, I am certain this has not been raised before.