Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systematic asset reuse for attached models #2526

Open
jjyyxx opened this issue Mar 24, 2025 · 4 comments
Open

Systematic asset reuse for attached models #2526

jjyyxx opened this issue Mar 24, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@jjyyxx
Copy link
Contributor

jjyyxx commented Mar 24, 2025

The feature, motivation and pitch

asset/model + <attach> and the mjs_attachBody, mjs_attachFrame equivalent in model editing API is the most systematic and convenient way to combine components into a complex scene. But a potential limitation is that: when a model is attached multiple times, or in any other case that assets (mainly meshes) are effectively shared by multiple child models, the assets are unconditionally duplicated in the main model.

In our use case, the model size quickly grows to over 300MiB with over 1M mesh faces. The major sources of bloating are several child models with SDF collision geom (SDF marching cube resolution is hard-coded) attached several times. If we further scale up the scene (only by attaching the existing child models more times), the model size would surely exceed 1GiB. The bloating model size would not cause significant problem for "single model, multiple data" simulation on its own, but:

  1. We are trying to store MJB binary for archiving and exact reproducibility;
  2. We plan to experiment with certain domain randomization that goes beyond the scope of MjData, necessitating one model for each parallel worker.

Alternatives

  1. Refactor the namespacing/scoping mechanism. The current prefix/suffix mechanism is somewhat inflexible.
  2. Centralized asset management and asset sharing across models: It is theoretically possible with current mjModel interface, by changing asset pointers currently pointing to the main buffer to external buffers.

Additional context

No response

@jjyyxx jjyyxx added the enhancement New feature or request label Mar 24, 2025
@yuvaltassa
Copy link
Collaborator

This is a valuable feature request, thanks.

I think there are two separate but related requests:

  1. Stop copying assets unconditionally during attach, only copy assets which are actually referenced in the child.
  2. Detect duplicate assets and merge them. This is obviously valuable during attach, but could potentially happen much later in the compilation step, for any model, whether created using attach or not.

Is this a correct reflection of your request, or did I miss something?

@jjyyxx
Copy link
Contributor Author

jjyyxx commented Mar 24, 2025

Indeed, I agree. Though 1 would not improve the situation significantly for us, since our components are fairly "atomic".

@demoncoder-crypto
Copy link

I have done a very rough implementation of this, let me know if it works, i will refine it iteratively

@demoncoder-crypto
Copy link

#2540 Find it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants