add material properties to terrain and ground models
- Introduced `ambient`, `specular`, and `diffuse` attributes to `TerrainData` class. - Updated `Ground` class to accept and use material properties for ambient, specular, and diffuse values. - Modified the SDF generation to dynamically apply the provided material properties. - Integrated material property support in the `Scene` class for terrain setup.
This commit is contained in:
parent
5747057baf
commit
b71a2bdf55
3 changed files with 16 additions and 4 deletions
|
@ -27,4 +27,7 @@ class TerrainData:
|
|||
spawn_position: tuple[float, float, float] = field(default=(0, 0, 0))
|
||||
spawn_quat_xyzw: tuple[float, float, float, float] = field(default=(0, 0, 0, 1))
|
||||
size: tuple[float, float] = field(default=(1.5, 1.5))
|
||||
ambient: tuple[float, float, float, float] = field(default=(0.8, 0.8, 0.8, 1.0))
|
||||
specular: tuple[float, float, float, float] = field(default=(0.8, 0.8, 0.8, 1.0))
|
||||
diffuse: tuple[float, float, float, float] = field(default=(0.8, 0.8, 0.8, 1.0))
|
||||
model_rollouts_num: int = field(default=1)
|
||||
|
|
|
@ -20,6 +20,9 @@ class Ground(model_wrapper.ModelWrapper):
|
|||
size (tuple[float, float], optional): The size of the ground plane. Defaults to (1.5, 1.5).
|
||||
collision_thickness (float, optional): The thickness of the collision surface. Defaults to 0.05.
|
||||
friction (float, optional): The friction coefficient for the ground surface. Defaults to 5.0.
|
||||
ambient (tuple[float, float, float, float], optional): The ambient color of the material. Defaults to (0.8, 0.8, 0.8, 1.0).
|
||||
specular (tuple[float, float, float, float], optional): The specular color of the material. Defaults to (0.8, 0.8, 0.8, 1.0).
|
||||
diffuse (tuple[float, float, float, float], optional): The diffuse color of the material. Defaults to (0.8, 0.8, 0.8, 1.0).
|
||||
**kwargs: Additional keyword arguments for future extensions.
|
||||
|
||||
Raises:
|
||||
|
@ -35,6 +38,9 @@ class Ground(model_wrapper.ModelWrapper):
|
|||
size: tuple[float, float] = (1.5, 1.5),
|
||||
collision_thickness=0.05,
|
||||
friction: float = 5.0,
|
||||
ambient: tuple[float, float, float, float] = (0.8, 0.8, 0.8, 1.0),
|
||||
specular: tuple[float, float, float, float] = (0.8, 0.8, 0.8, 1.0),
|
||||
diffuse: tuple[float, float, float, float] = (0.8, 0.8, 0.8, 1.0),
|
||||
**kwargs,
|
||||
):
|
||||
# Get a unique model name
|
||||
|
@ -43,7 +49,7 @@ class Ground(model_wrapper.ModelWrapper):
|
|||
# Initial pose
|
||||
initial_pose = scenario_core.Pose(position, orientation)
|
||||
|
||||
# Create SDF string for the model
|
||||
# Create SDF string for the model with the provided material properties
|
||||
sdf = f"""<sdf version="1.9">
|
||||
<model name="{model_name}">
|
||||
<static>true</static>
|
||||
|
@ -75,9 +81,9 @@ class Ground(model_wrapper.ModelWrapper):
|
|||
</plane>
|
||||
</geometry>
|
||||
<material>
|
||||
<ambient>0.8 0.8 0.8 1</ambient>
|
||||
<diffuse>0.8 0.8 0.8 1</diffuse>
|
||||
<specular>0.8 0.8 0.8 1</specular>
|
||||
<ambient>{' '.join(map(str, ambient))}</ambient>
|
||||
<diffuse>{' '.join(map(str, diffuse))}</diffuse>
|
||||
<specular>{' '.join(map(str, specular))}</specular>
|
||||
</material>
|
||||
</visual>
|
||||
</link>
|
||||
|
|
|
@ -573,6 +573,9 @@ class Scene:
|
|||
position=self.terrain.spawn_position,
|
||||
orientation=quat_to_wxyz(self.terrain.spawn_quat_xyzw),
|
||||
size=self.terrain.size,
|
||||
ambient=self.terrain.ambient,
|
||||
diffuse=self.terrain.diffuse,
|
||||
specular=self.terrain.specular,
|
||||
)
|
||||
|
||||
# Enable contact detection
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue