Skip to content

Conversation

ooctipus
Copy link
Collaborator

Description

This PR adds a demo that showcasing the advance composition of RigidObjectCollection and MultiAssetSpawner.
This allows spawning random number of objects and varying object per environment id in bin_packing example.

  • New feature (non-breaking change which adds functionality)

Screenshots

Please attach before and after screenshots of the change if applicable.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions bot added documentation Improvements or additions to documentation isaac-lab Related to Isaac Lab team labels Sep 26, 2025
@ooctipus
Copy link
Collaborator Author

There is a small physics bug after a feature update, don't merge :)))

@AntoineRichard
Copy link
Collaborator

Here is a fix :)

def reset_object_collections(scene: InteractiveScene, view_ids: torch.Tensor):
    if len(view_ids) == 0:
        return
    rigid_object_collection: RigidObjectCollection = scene["object_collection"]
    default_state_w = rigid_object_collection.data.default_object_state.clone()
    default_state_w[..., :3] = default_state_w[..., :3] + scene.env_origins.unsqueeze(1)
    default_state_w_view = rigid_object_collection.reshape_data_to_view(default_state_w)[view_ids]
    range_list = [POSE_RANGE.get(key, (0.0, 0.0)) for key in ["x", "y", "z", "roll", "pitch", "yaw"]]
    ranges = torch.tensor(range_list, device=scene.device)
    samples = math_utils.sample_uniform(ranges[:, 0], ranges[:, 1], (len(view_ids), 6), device=scene.device)

    positions = default_state_w_view[:, :3] + samples[..., 0:3]
    orientations_delta = math_utils.quat_from_euler_xyz(samples[..., 3], samples[..., 4], samples[..., 5])
    orientations = math_utils.quat_mul(default_state_w_view[:, 3:7], orientations_delta)
    # velocities
    range_list = [VELOCITY_RANGE.get(key, (0.0, 0.0)) for key in ["x", "y", "z", "roll", "pitch", "yaw"]]
    ranges = torch.tensor(range_list, device=scene.device)
    samples = math_utils.sample_uniform(ranges[:, 0], ranges[:, 1], (len(view_ids), 6), device=scene.device)

    new_velocities = default_state_w_view[:, 7:13] + samples
    new_poses = torch.concat((positions, orientations), dim=-1)

    new_poses[..., 3:] = math_utils.convert_quat(new_poses[..., 3:], to="xyzw")

    num_objects = rigid_object_collection.num_instances * rigid_object_collection.num_objects

    if len(view_ids) != num_objects:
        poses = torch.zeros((num_objects, 7), device=scene.device)
        poses[view_ids, :] = new_poses
        velocities = torch.zeros((num_objects, 6), device=scene.device)
        velocities[view_ids, :] = new_velocities
    else:
        poses = new_poses
        velocities = new_velocities

    rigid_object_collection.root_physx_view.set_transforms(poses, indices=view_ids.view(-1, 1))
    rigid_object_collection.root_physx_view.set_velocities(velocities, indices=view_ids.view(-1, 1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation infrastructure isaac-lab Related to Isaac Lab team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants