Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions configs/gym/pour_water/gym_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions configs/gym/pour_water/gym_config_simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}
Expand All @@ -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]]
}
Expand All @@ -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]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 26 additions & 4 deletions embodichain/lab/gym/envs/managers/randomization/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,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
Expand All @@ -502,18 +520,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,
Expand Down
3 changes: 0 additions & 3 deletions embodichain/lab/gym/utils/gym_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion embodichain/lab/sim/sim_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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().
"""
Expand Down
Loading