-
Notifications
You must be signed in to change notification settings - Fork 8
export usd #168
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
export usd #168
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -629,6 +629,24 @@ def __init__( | |||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_max_effort = self._data.qf_limits.clone() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_max_velocity = self._data.qvel_limits.clone() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Write the USD properties back to cfg | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usd_drive_pros = self.cfg.drive_pros | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usd_drive_pros.stiffness = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_stiffness[0].cpu().numpy().tolist() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usd_drive_pros.damping = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_damping[0].cpu().numpy().tolist() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usd_drive_pros.friction = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_friction[0].cpu().numpy().tolist() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usd_drive_pros.max_effort = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_max_effort[0].cpu().numpy().tolist() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| usd_drive_pros.max_velocity = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.default_joint_max_velocity[0].cpu().numpy().tolist() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+632
to
+648
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
631
to
+649
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Write the USD properties back to cfg | |
| usd_drive_pros = self.cfg.drive_pros | |
| usd_drive_pros.stiffness = ( | |
| self.default_joint_stiffness[0].cpu().numpy().tolist() | |
| ) | |
| usd_drive_pros.damping = ( | |
| self.default_joint_damping[0].cpu().numpy().tolist() | |
| ) | |
| usd_drive_pros.friction = ( | |
| self.default_joint_friction[0].cpu().numpy().tolist() | |
| ) | |
| usd_drive_pros.max_effort = ( | |
| self.default_joint_max_effort[0].cpu().numpy().tolist() | |
| ) | |
| usd_drive_pros.max_velocity = ( | |
| self.default_joint_max_velocity[0].cpu().numpy().tolist() | |
| ) | |
| # NOTE: | |
| # We intentionally do not write these per-DOF USD properties back into | |
| # `self.cfg.drive_pros`, because `JointDrivePropertiesCfg` fields such | |
| # as `stiffness`, `damping`, etc. are expected to be either a scalar | |
| # float or a Dict[str, float], not a list. The tensors above should | |
| # be used directly wherever the full per-DOF information is required. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,6 +216,15 @@ def __init__( | |
| for entity in entities: | ||
| entity.set_body_scale(*cfg.body_scale) | ||
| entity.set_physical_attr(cfg.attrs.attr()) | ||
| else: | ||
| # Read current properties from USD-loaded entities and write back to cfg | ||
| # Use first entity as reference | ||
| first_entity: MeshObject = entities[0] | ||
|
|
||
|
Comment on lines
+219
to
+223
|
||
| cfg.body_scale = tuple(first_entity.get_body_scale()) | ||
| cfg.attrs = RigidBodyAttributesCfg().from_dict( | ||
| first_entity.get_physical_attr().as_dict() | ||
| ) | ||
|
Comment on lines
+225
to
+227
|
||
|
|
||
| if device.type == "cuda": | ||
| self._world.update(0.001) | ||
|
|
@@ -872,8 +881,7 @@ def reset(self, env_ids: Sequence[int] | None = None) -> None: | |
| local_env_ids = self._all_indices if env_ids is None else env_ids | ||
| num_instances = len(local_env_ids) | ||
|
|
||
| if not self.cfg.use_usd_properties: | ||
| self.set_attrs(self.cfg.attrs, env_ids=local_env_ids) | ||
| self.set_attrs(self.cfg.attrs, env_ids=local_env_ids) | ||
|
|
||
| pos = torch.as_tensor( | ||
| self.cfg.init_pos, dtype=torch.float32, device=self.device | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1705,6 +1705,23 @@ def reset_objects_state( | |
| if uid not in excluded_uids: | ||
| sensor.reset(env_ids) | ||
|
|
||
| def export_usd(self, fpath: str) -> bool: | ||
| """Export the current simulation scene to a USD file. | ||
|
|
||
| Args: | ||
| fpath (str): The file path to save the USD file. | ||
|
|
||
| Returns: | ||
| bool: True if export is successful, False otherwise. | ||
| """ | ||
| try: | ||
| self._env.export_to_usd_file(fpath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should support exclusive uid list. (eg, remove ground plane from export)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After discussion, this commit will not include this change |
||
| logger.log_info(f"Simulation scene exported to USD file: {fpath}") | ||
| return True | ||
| except Exception as e: | ||
| logger.log_error(f"Failed to export simulation scene to USD: {e}") | ||
| return False | ||
|
|
||
| def destroy(self) -> None: | ||
| """Destroy all simulated assets and release resources.""" | ||
| # Clean up all gizmos before destroying the simulation | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from joint drive properties, we also have link physics properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion, this commit will not include this change