-
Notifications
You must be signed in to change notification settings - Fork 3k
Adds texture and scale randomization event terms #2121
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,12 +14,14 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import math | ||
| import torch | ||
| from typing import TYPE_CHECKING, Literal | ||
|
|
||
| import carb | ||
| import omni.physics.tensors.impl.api as physx | ||
| import omni.usd | ||
| from isaacsim.core.utils.extensions import enable_extension | ||
| from pxr import Gf, Sdf, UsdGeom, Vt | ||
|
|
||
| import isaaclab.sim as sim_utils | ||
|
|
@@ -274,6 +276,99 @@ def __call__( | |
| self.asset.root_physx_view.set_material_properties(materials, env_ids) | ||
|
|
||
|
|
||
| class randomize_visual_texture_material(ManagerTermBase): | ||
| """Randomize the visual texture of bodies on an asset using Replicator API. | ||
|
|
||
| This function randomizes the visual texture of the bodies of the asset using the Replicator API. | ||
| The function samples random textures from the given texture paths and applies them to the bodies | ||
| of the asset. The textures are projected onto the bodies and rotated by the given angles. | ||
|
|
||
| .. note:: | ||
| The function assumes that the asset follows the prim naming convention as: | ||
| "{asset_prim_path}/{body_name}/visuals" where the body name is the name of the body to | ||
| which the texture is applied. This is the default prim ordering when importing assets | ||
| from the asset converters in Isaac Lab. | ||
|
|
||
| .. note:: | ||
| When randomizing the texture of individual assets, please make sure to set | ||
| :attr:`isaaclab.scene.InteractiveSceneCfg.replicate_physics` to False. This ensures that physics | ||
| parser will parse the individual asset properties separately. | ||
| """ | ||
|
|
||
| def __init__(self, cfg: EventTermCfg, env: ManagerBasedEnv): | ||
| """Initialize the term. | ||
|
|
||
| Args: | ||
| cfg: The configuration of the event term. | ||
| env: The environment instance. | ||
| """ | ||
| super().__init__(cfg, env) | ||
|
|
||
| enable_extension("omni.replicator.core") | ||
|
|
||
| # we import the module here since we may not always need the replicator | ||
| import omni.replicator.core as rep | ||
|
|
||
| # read parameters from the configuration | ||
| asset_cfg: SceneEntityCfg = cfg.params.get("asset_cfg") | ||
| texture_paths = cfg.params.get("texture_paths") | ||
| event_name = cfg.params.get("event_name") | ||
| texture_rotation = cfg.params.get("texture_rotation", (0.0, 0.0)) | ||
|
|
||
| # check to make sure replicate_physics is set to False, else raise warning | ||
| if env.cfg.scene.replicate_physics: | ||
| raise ValueError( | ||
| "Unable to randomize visual texture material - ensure InteractiveSceneCfg's replicate_physics parameter" | ||
| " is set to False." | ||
| ) | ||
|
|
||
| # convert from radians to degrees | ||
| texture_rotation = tuple(math.degrees(angle) for angle in texture_rotation) | ||
|
|
||
| # obtain the asset entity | ||
| asset_entity = env.scene[asset_cfg.name] | ||
| # join all bodies in the asset | ||
| body_names = asset_cfg.body_names | ||
| if isinstance(body_names, str): | ||
| body_names_regex = body_names | ||
| elif isinstance(body_names, list): | ||
| body_names_regex = "|".join(body_names) | ||
| else: | ||
| body_names_regex = ".*" | ||
|
|
||
| # Create the omni-graph node for the randomization term | ||
| def rep_texture_randomization(): | ||
| prims_group = rep.get.prims(path_pattern=f"{asset_entity.cfg.prim_path}/{body_names_regex}/visuals") | ||
|
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. Hmm since "visuals" is something hardcoded, I think it isn't great as we asume asset structure here. Should we make an attribute For example:
|
||
|
|
||
| with prims_group: | ||
| rep.randomizer.texture( | ||
| textures=texture_paths, project_uvw=True, texture_rotate=rep.distribution.uniform(*texture_rotation) | ||
| ) | ||
|
|
||
| return prims_group.node | ||
|
|
||
| # Register the event to the replicator | ||
| with rep.trigger.on_custom_event(event_name=event_name): | ||
| rep_texture_randomization() | ||
|
|
||
| def __call__( | ||
| self, | ||
| env: ManagerBasedEnv, | ||
| env_ids: torch.Tensor, | ||
| event_name: str, | ||
| asset_cfg: SceneEntityCfg, | ||
| texture_paths: list[str], | ||
| texture_rotation: tuple[float, float] = (0.0, 0.0), | ||
| ): | ||
| # import replicator | ||
| import omni.replicator.core as rep | ||
|
|
||
| # only send the event to the replicator | ||
| # note: This triggers the nodes for all the environments. | ||
| # We need to investigate how to make it happen only for a subset based on env_ids. | ||
| rep.utils.send_og_event(event_name) | ||
|
|
||
|
|
||
| def randomize_rigid_body_mass( | ||
| env: ManagerBasedEnv, | ||
| env_ids: torch.Tensor | None, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.