Skip to content

Commit 292441d

Browse files
committed
Merge branch 'yueci/add-sim-docs' of https://github.com/DexForce/EmbodiChain into yueci/add-sim-docs
2 parents 57365bf + 0079f59 commit 292441d

3 files changed

Lines changed: 67 additions & 23 deletions

File tree

docs/source/overview/sim/sim_assets.md

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
# Simulation Assets
22

3-
Simulation assets in EmbodiChain are configured using Python dataclasses. This approach provides a structured and type-safe way to define properties for physics, materials, objects and sensors in the simulation environment.
3+
Simulation assets in EmbodiChain are configured using Python dataclasses. This approach provides a structured and type-safe way to define properties for physics, materials, objects and sensors in the simulation environment.
44

5-
## Physics Configuration
5+
## Visual Materials
66

7-
The `PhysicsCfg` class controls the global physics simulation parameters.
8-
9-
| Parameter | Type | Default | Description |
10-
| :--- | :--- | :--- | :--- |
11-
| `gravity` | `np.ndarray` | `[0, 0, -9.81]` | Gravity vector for the simulation environment. |
12-
| `bounce_threshold` | `float` | `2.0` | The speed threshold below which collisions will not produce bounce effects. |
13-
| `enable_pcm` | `bool` | `True` | Enable persistent contact manifold (PCM) for improved collision handling. |
14-
| `enable_tgs` | `bool` | `True` | Enable temporal gauss-seidel (TGS) solver for better stability. |
15-
| `enable_ccd` | `bool` | `False` | Enable continuous collision detection (CCD) for fast-moving objects. |
16-
| `enable_enhanced_determinism` | `bool` | `False` | Enable enhanced determinism for consistent simulation results. |
17-
| `enable_friction_every_iteration` | `bool` | `True` | Enable friction calculations at every solver iteration. |
18-
| `length_tolerance` | `float` | `0.05` | The length tolerance for the simulation. Larger values increase speed. |
19-
| `speed_tolerance` | `float` | `0.25` | The speed tolerance for the simulation. Larger values increase speed. |
20-
21-
## Materials
22-
23-
### Visual Materials
7+
### Configuration
248

259
The `VisualMaterialCfg` class defines the visual appearance of objects using Physically Based Rendering (PBR) properties.
2610

@@ -38,13 +22,43 @@ The `VisualMaterialCfg` class defines the visual appearance of objects using Phy
3822
| `normal_texture` | `str` | `None` | Path to normal map. |
3923
| `ao_texture` | `str` | `None` | Path to ambient occlusion map. |
4024
| `ior` | `float` | `1.5` | Index of refraction for ray tracing materials. |
41-
| `material_type` | `str` | `"BRDF"` | material type. |
25+
26+
### Visual Material and Visual Material Instance
27+
28+
A visual material is defined using the `VisualMaterialCfg` class. It is actually a material template that can be used to create multiple instances with different parameters.
29+
30+
A visual material instance is created from a visual material using the method `create_instance()`. User can set different properties for each instance. For details API usage, please refer to the [VisualMaterialInst](https://dexforce.github.io/EmbodiChain/api_reference/embodichain/embodichain.lab.sim.html#embodichain.lab.sim.material.VisualMaterialInst) documentation.
31+
32+
For batch simualtion scenarios, when user set a material to a object (eg, a rigid object), the material instance will be created for each simulation instance automatically.
33+
34+
### Code
35+
36+
```python
37+
# Create a visual material with base color white and low roughness.
38+
mat: VisualMaterial = sim.create_visual_material(
39+
cfg=VisualMaterialCfg(
40+
base_color=[1.0, 1.0, 1.0, 1.0],
41+
roughness=0.05,
42+
)
43+
)
44+
45+
# Set the material to a rigid object.
46+
object: RigidObject
47+
object.set_visual_material(mat)
48+
49+
# Get all material instances created for this object in the simulation. If `num_envs` is N, there will be N instances.
50+
mat_inst: List[VisualMaterialInst] = object.get_visual_material_inst()
51+
52+
# We can then modify the properties of each material instance separately.
53+
mat_inst[0].set_base_color([1.0, 0.0, 0.0, 1.0])
54+
```
55+
4256

4357
## Objects
4458

4559
All objects inherit from `ObjectBaseCfg`, which provides common properties.
4660

47-
**Base Properties (`ObjectBaseCfg`)**
61+
**Base Properties**
4862

4963
| Parameter | Type | Default | Description |
5064
| :--- | :--- | :--- | :--- |
@@ -85,6 +99,13 @@ The `RigidBodyAttributesCfg` class defines physical properties for rigid bodies.
8599
| `dynamic_friction` | `float` | `0.5` | Dynamic friction coefficient. |
86100
| `static_friction` | `float` | `0.5` | Static friction coefficient. |
87101

102+
For Rigid Object tutorial, please refer to the [Create Scene](https://dexforce.github.io/EmbodiChain/tutorial/create_scene.html).
103+
104+
## Rigid Object Groups
105+
106+
`RigidObjectGroupCfg` allows initializing multiple rigid objects, potentially from a folder.
107+
108+
88109
## Soft Object
89110

90111
Configured via `SoftObjectCfg`.
@@ -123,6 +144,8 @@ Soft bodies require both voxelization and physical attributes.
123144
| `mass` | `float` | `-1.0` | Total mass. If negative, density is used. |
124145
| `density` | `float` | `1000.0` | Material density in kg/m^3. |
125146

147+
For Soft Object tutorial, please refer to the [Soft Body Simulation](https://dexforce.github.io/EmbodiChain/tutorial/create_softbody.html).
148+
126149

127150
### Articulations & Robots
128151

@@ -152,6 +175,4 @@ Configured via `MarkerCfg` for debugging and visualization.
152175
| `axis_len` | `float` | `0.005` | Length of axis arms. |
153176
| `line_color` | `list` | `[1, 1, 0, 1.0]` | RGBA color for lines. |
154177

155-
### Rigid Object Groups
156178

157-
`RigidObjectGroupCfg` allows initializing multiple rigid objects, potentially from a folder.

docs/source/overview/sim/sim_manager.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ sim_config = SimulationManagerCfg(
4343
| `physics_config` | `PhysicsCfg` | `PhysicsCfg()` | The physics configuration parameters. |
4444
| `gpu_memory_config` | `GPUMemoryCfg` | `GPUMemoryCfg()` | The GPU memory configuration parameters. |
4545

46+
### Physics Configuration
47+
48+
The `PhysicsCfg` class controls the global physics simulation parameters.
49+
50+
| Parameter | Type | Default | Description |
51+
| :--- | :--- | :--- | :--- |
52+
| `gravity` | `np.ndarray` | `[0, 0, -9.81]` | Gravity vector for the simulation environment. |
53+
| `bounce_threshold` | `float` | `2.0` | The speed threshold below which collisions will not produce bounce effects. |
54+
| `enable_ccd` | `bool` | `False` | Enable continuous collision detection (CCD) for fast-moving objects. |
55+
| `length_tolerance` | `float` | `0.05` | The length tolerance for the simulation. Larger values increase speed. |
56+
| `speed_tolerance` | `float` | `0.25` | The speed tolerance for the simulation. Larger values increase speed. |
57+
58+
For more parameters and details, refer to the [PhysicsCfg](https://dexforce.github.io/EmbodiChain/api_reference/embodichain/embodichain.lab.sim.html#embodichain.lab.sim.cfg.PhysicsCfg) documentation.
59+
60+
4661
## Initialization
4762

4863
Initialize the manager with the configuration object:

embodichain/lab/sim/material.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def __init__(self, cfg: VisualMaterialCfg, mat: Material):
116116
self.uid = cfg.uid
117117
self.cfg = copy.deepcopy(cfg)
118118
self._mat = mat
119+
self._mat_inst_list: list[str] = []
119120

120121
self._default_mat_inst = self.create_instance(self.uid)
121122

@@ -127,6 +128,10 @@ def is_rt_enabled(self) -> bool:
127128
def mat(self) -> Material:
128129
return self._mat
129130

131+
@property
132+
def inst(self) -> VisualMaterialInst:
133+
return self._default_mat_inst
134+
130135
def set_default_properties(
131136
self, mat_inst: VisualMaterialInst, cfg: VisualMaterialCfg
132137
) -> None:
@@ -164,6 +169,7 @@ def create_instance(self, uid: str) -> VisualMaterialInst:
164169
# TODO: Support change default properties for material.
165170
# This will improve the instance creation efficiency.
166171
self.set_default_properties(inst, self.cfg)
172+
self._mat_inst_list.append(uid)
167173
return inst
168174

169175
def get_default_instance(self) -> VisualMaterialInst:
@@ -183,6 +189,8 @@ def get_instance(self, uid: str) -> VisualMaterialInst:
183189
Returns:
184190
VisualMaterialInst: The material instance.
185191
"""
192+
if uid not in self._mat_inst_list:
193+
logger.log_error(f"Material instance with uid '{uid}' does not exist.")
186194
return VisualMaterialInst(uid, self._mat)
187195

188196

0 commit comments

Comments
 (0)