in robogym/envs/rearrange/common/base.py [0:0]
def _randomize_lighting(self):
"""
Randomizes the position and direction of all lights, and randomizes the ambient and diffuse
headlight intensities.
"""
# Controls the fraction of valid positions for the light which are able to be sampled.
range_fraction = self.mujoco_simulation.simulation_params.light_pos_range
positions = []
directions = []
n_lights = len(self.mujoco_simulation.get_light_positions())
for i in range(n_lights):
# Randomly sample (x, y, z) coordinates for position independently, uniformly randomly
# from their valid range (which is modulated by `range_fraction`). Given these
# coordinates, we then normalize the resulting position vector and scale it such that
# the light is always 4m away from the origin. You can view these coordinates as points
# on a surface of the sphere centered at the origin with radius 4m; this surface
# initially is just the point (0, 0, 4) and then expands outwards according to
# `range_fraction`.
x = self._random_state.uniform(
-0.25 * range_fraction, 0.75 * range_fraction
)
y = range_fraction * self._random_state.uniform(-4.0, 4.0)
z = self._random_state.uniform(4.0 - (range_fraction * 4.0), 4.0)
raw_pos = np.array([x, y, z])
pos_norm = np.linalg.norm(raw_pos)
# Keep the light 4 m away from the origin.
pos = (raw_pos / pos_norm) * 4.0
# Direction is unit-norm of the negative position vector
direction = -raw_pos / pos_norm
positions.append(pos)
directions.append(direction)
# Randomize the intensity of diffuse and ambient headlights.
diffuse_intensity = (
self.mujoco_simulation.simulation_params.light_diffuse_intensity
)
ambient_intensity = (
self.mujoco_simulation.simulation_params.light_ambient_intensity
)
self.mujoco_simulation.set_lighting(
np.array(positions),
np.array(directions),
diffuse_intensity,
ambient_intensity,
)