From cd67b481547fe987a4cae2faf08c3b286011ff6a Mon Sep 17 00:00:00 2001 From: yuecideng Date: Thu, 29 Jan 2026 17:28:21 +0800 Subject: [PATCH 1/2] wip --- configs/gym/pour_water/gym_config.json | 9 ++++-- configs/gym/pour_water/gym_config_simple.json | 6 ++-- .../gym/envs/managers/randomization/visual.py | 30 ++++++++++++++++--- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/configs/gym/pour_water/gym_config.json b/configs/gym/pour_water/gym_config.json index 8b490ad6..3e0bcafb 100644 --- a/configs/gym/pour_water/gym_config.json +++ b/configs/gym/pour_water/gym_config.json @@ -359,7 +359,8 @@ "uid": "table", "shape": { "shape_type": "Mesh", - "fpath": "CircleTableSimple/circle_table_simple.ply" + "fpath": "CircleTableSimple/circle_table_simple.ply", + "compute_uv": true }, "attrs" : { "mass": 10.0, @@ -378,7 +379,8 @@ "uid":"cup", "shape": { "shape_type": "Mesh", - "fpath": "PaperCup/paper_cup.ply" + "fpath": "PaperCup/paper_cup.ply", + "compute_uv": true }, "attrs" : { "mass": 0.01, @@ -397,7 +399,8 @@ "uid":"bottle", "shape": { "shape_type": "Mesh", - "fpath": "ScannedBottle/kashijia_processed.ply" + "fpath": "ScannedBottle/kashijia_processed.ply", + "compute_uv": true }, "attrs" : { "mass": 0.01, diff --git a/configs/gym/pour_water/gym_config_simple.json b/configs/gym/pour_water/gym_config_simple.json index c4d55b9d..ddde2e4d 100644 --- a/configs/gym/pour_water/gym_config_simple.json +++ b/configs/gym/pour_water/gym_config_simple.json @@ -149,7 +149,7 @@ "interval_step": 10, "params": { "entity_cfg": {"uid": "table"}, - "random_texture_prob": 0.0, + "random_texture_prob": 0.5, "texture_path": "CocoBackground/coco", "base_color_range": [[0.2, 0.2, 0.2], [1.0, 1.0, 1.0]] } @@ -160,7 +160,7 @@ "interval_step": 10, "params": { "entity_cfg": {"uid": "cup"}, - "random_texture_prob": 0.0, + "random_texture_prob": 0.5, "texture_path": "CocoBackground/coco", "base_color_range": [[0.2, 0.2, 0.2], [1.0, 1.0, 1.0]] } @@ -171,7 +171,7 @@ "interval_step": 10, "params": { "entity_cfg": {"uid": "bottle"}, - "random_texture_prob": 0.0, + "random_texture_prob": 0.5, "texture_path": "CocoBackground/coco", "base_color_range": [[0.2, 0.2, 0.2], [1.0, 1.0, 1.0]] } diff --git a/embodichain/lab/gym/envs/managers/randomization/visual.py b/embodichain/lab/gym/envs/managers/randomization/visual.py index d0c25d76..8fc24c2a 100644 --- a/embodichain/lab/gym/envs/managers/randomization/visual.py +++ b/embodichain/lab/gym/envs/managers/randomization/visual.py @@ -440,6 +440,24 @@ def __init__(self, cfg: FunctorCfg, env: EmbodiedEnv): self.entity_cfg.link_names = link_names self.entity.set_visual_material(mat, link_names=link_names) + @staticmethod + def gen_random_base_color_texture(width: int, height: int) -> torch.Tensor: + """Generate a random base color texture. + + Args: + width: The width of the texture. + height: The height of the texture. + + Returns: + A torch tensor representing the random base color texture with shape (height, width, 4). + """ + # Generate random RGB values + rgb = torch.ones((height, width, 3), dtype=torch.float32) + rgb *= torch.rand((1, 1, 3), dtype=torch.float32) + rgba = torch.cat((rgb, torch.ones((height, width, 1))), dim=2) + rgba = (rgba * 255).to(torch.uint8) + return rgba + def _randomize_texture(self, mat_inst: VisualMaterialInst) -> None: if len(self.textures) > 0: # Randomly select a texture from the preloaded textures @@ -453,18 +471,22 @@ def _randomize_mat_inst( random_texture_prob: float, idx: int = 0, ) -> None: - # randomize texture or base color based on the probability. if random.random() < random_texture_prob and len(self.textures) != 0: - self._randomize_texture(mat_inst) - else: - # randomize the material instance pbr properties based on the plan. for key, value in plan.items(): if key == "base_color": mat_inst.set_base_color(value[idx].tolist()) else: getattr(mat_inst, f"set_{key}")(value[idx].item()) + self._randomize_texture(mat_inst) + else: + # set a random base color instead. + random_color_texture = ( + randomize_visual_material.gen_random_base_color_texture(2, 2) + ) + mat_inst.set_base_color_texture(texture_data=random_color_texture) + def __call__( self, env: EmbodiedEnv, From c5f4b9578b3a3cb692aeadfa872d9db8b4d9e0ee Mon Sep 17 00:00:00 2001 From: yuecideng Date: Thu, 29 Jan 2026 15:40:53 +0000 Subject: [PATCH 2/2] wip --- embodichain/lab/gym/envs/managers/randomization/__init__.py | 2 +- embodichain/lab/gym/utils/gym_utils.py | 3 --- embodichain/lab/sim/sim_manager.py | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/embodichain/lab/gym/envs/managers/randomization/__init__.py b/embodichain/lab/gym/envs/managers/randomization/__init__.py index 16520976..1fa15f68 100644 --- a/embodichain/lab/gym/envs/managers/randomization/__init__.py +++ b/embodichain/lab/gym/envs/managers/randomization/__init__.py @@ -17,7 +17,7 @@ from .physics import * # noqa: F401, F403 from .visual import * # noqa: F401, F403 from .spatial import * # noqa: F401, F403 -from .scale import * # noqa: F401, F403 +from .geometry import * # noqa: F401, F403 """ Randomization are all implemented as Event functors. diff --git a/embodichain/lab/gym/utils/gym_utils.py b/embodichain/lab/gym/utils/gym_utils.py index 123331e0..1cc1ba1e 100644 --- a/embodichain/lab/gym/utils/gym_utils.py +++ b/embodichain/lab/gym/utils/gym_utils.py @@ -437,8 +437,6 @@ class ComponentCfg: env_cfg.sim_steps_per_control = config["env"].get("sim_steps_per_control", 4) env_cfg.extensions = deepcopy(config.get("env", {}).get("extensions", {})) - # TODO: support more env events, eg, grasp pose generation, mesh preprocessing, etc. - env_cfg.dataset = ComponentCfg() if "dataset" in config["env"]: # Define modules to search for dataset functions @@ -483,7 +481,6 @@ class ComponentCfg: "embodichain.lab.gym.envs.managers.randomization", "embodichain.lab.gym.envs.managers.record", "embodichain.lab.gym.envs.managers.events", - "embodichain.lab.gym.envs.managers.real2sim", ] # parser env events config diff --git a/embodichain/lab/sim/sim_manager.py b/embodichain/lab/sim/sim_manager.py index 464fb0de..d13350bd 100644 --- a/embodichain/lab/sim/sim_manager.py +++ b/embodichain/lab/sim/sim_manager.py @@ -158,7 +158,6 @@ class SimulationManager: - physics simulation management, eg. time step, manual update, etc. - interactive control via gizmo and window callbacks events. - Args: sim_config (SimulationManagerCfg, optional): simulation configuration. Defaults to SimulationManagerCfg(). """