Skip to content

MjSpec: protocols for merging keyframes on attach #2102

Open
@hartikainen

Description

@hartikainen

The feature, motivation and pitch

When attaching bodies from one spec to another, it would be convenient to have some configurability on how the keyframes are handled as a result of the attachment. For example, I often have a "home" keyframe in both the attachment source and target specs and it would be convenient to be have a single "home" keyframe in the target spec after the attachment.

There's obviously no general solution that would magically always do the right thing, but the API could provide some pre-defined protocols that can be passed in as an argument to e.g. the MjsFrame.attach_body. For example my use cases would be largely covered by something like:

  • MjsFrame.attach_body(..., "by-name"), which would merge all the keyframes with the same name.
    • Example: when specs have <key name="home" qpos="1"/> and <key name="home" qpos="2"/>, the result would be <key name="home" qpos="1 2"/>.
  • MjsFrame.attach_body(..., "by-index"), which would merge all the keyframes with the same index.
    • Example: when specs have <key qpos="1"/><key qpos="2"/> and <key qpos="3"/><key qpos="4"/>, the result would be <key qpos="1 3"/><key qpos="2 4"/>.

There are obviously some details that would have to be figured out before implementing these. For example, what would happen if two specs have different number of key elements when attaching with by-index. Or if one key has an attribute and the other one does not.

Alternatives

The keyframes can currently be merged manually using the C- or Python-API.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions