1

My current .sdf file looks like the following. my goal is to set the background to a specific colour by changing this sdf file. Found online "solutions" state that this can be done by setting the background variable in the scene tag. However I can't see any changes when this is done. The only thing i can think of is maybe its being overridden by some other value, but the verbose output seems fine.

<?xml version="1.0" ?>
<sdf version='1.9'>
<world name='default'>
    <physics name='1ms' type='ignored'>
    <max_step_size>0.001</max_step_size>
    <real_time_factor>1</real_time_factor>
    <real_time_update_rate>1000</real_time_update_rate>
    </physics>
&lt;scene&gt;
  &lt;ambient&gt;0 0 0 0&lt;/ambient&gt;
  &lt;background&gt;0 0 0 0&lt;/background&gt;
  &lt;shadows&gt;true&lt;/shadows&gt;
  &lt;grid&gt;true&lt;/grid&gt;
&lt;/scene&gt;



&lt;light name='sun' type='directional'&gt;
&lt;pose&gt;0 0 10 0 -0 0&lt;/pose&gt;
&lt;cast_shadows&gt;true&lt;/cast_shadows&gt;
&lt;intensity&gt;1&lt;/intensity&gt;
&lt;direction&gt;-0.5 0.1 -0.9&lt;/direction&gt;
&lt;diffuse&gt;0.8 0.8 0.8 1&lt;/diffuse&gt;
&lt;specular&gt;0.2 0.2 0.2 1&lt;/specular&gt;
&lt;attenuation&gt;
    &lt;range&gt;1000&lt;/range&gt;
    &lt;linear&gt;0.01&lt;/linear&gt;
    &lt;constant&gt;0.90000000000000002&lt;/constant&gt;
    &lt;quadratic&gt;0.001&lt;/quadratic&gt;
&lt;/attenuation&gt;
&lt;spot&gt;
    &lt;inner_angle&gt;0&lt;/inner_angle&gt;
    &lt;outer_angle&gt;0&lt;/outer_angle&gt;
    &lt;falloff&gt;0&lt;/falloff&gt;
&lt;/spot&gt;
&lt;/light&gt;

</world> </sdf>

Picture of simulation without correct background colour

1 Answers1

2

This is one of the strange (undocumented?) things of Gazebo Sim: there is an element <background> in the <scene> element in the SDF, but also a <background_color> element in the configuration of the MinimalScene plugin.

I don't know when the former is used, but the latter does set the background color:

To set from the SDF

Have a look at the empty_gui.sdf example world:

If you follow instructions 1. and 2. you will see that the scene initially loads with background color as specified by the MinimalScene <background_color>. Try changing it: the numbers represent RGB, with value between 0.0 and 1.0.

Upon load of the Scene Manager plugin per instruction 2., the background color is replaced by a sky texture, which can be avoided by removing this line. So strangely, the <sky> setting of the <scene> entry does have an effect, whereas the <background> setting does not.

To set from the gui config file

Alternatively, the same <background_color> setting can be done in the gui config file. The default file is located at ${HOME}/.gz/sim/7/gui.config. A custom config file can be loaded by starting Gazebo Sim with:

gz sim --gui-config <path_to_config_file>

The current config can be saved from Gazebo Sim by clicking the horizontal lines icon at the top left and choosing Save client configuration as.

To set programmatically

If you'd want to change the background color programmatically, take a look at this tutorial and corresponding source code. Note the difference between the server-side scene (used by Gazebo Sim sensors) and the gui-side scene.

JRTG
  • 1,654
  • 2
  • 2
  • 11