Another alternative is to load an empty world, and spawn objects through the create
service.
E.g. world.sdf
:
<?xml version="1.0" ?>
<sdf version="1.9">
<world name="empty_world">
<!-- Light Source -->
<light type="directional" name="sun">
<cast_shadows>true</cast_shadows>
<pose>0 0 10 0 0 0</pose>
<diffuse>0.8 0.8 0.8 1</diffuse>
<specular>0.2 0.2 0.2 1</specular>
<attenuation>
<range>1000</range>
<constant>0.9</constant>
<linear>0.01</linear>
<quadratic>0.001</quadratic>
</attenuation>
<direction>-0.2 0.5 -0.9</direction>
</light>
<!-- Included model -->
<include>
<uri>https://fuel.gazebosim.org/1.0/OpenRobotics/models/Ground Plane</uri>
</include>
</world>
</sdf>
Load above sdf with gz sim world.sdf
and then in another terminal call the create service (or call it from a script, varying the <pose>
, if you want to spawn many):
gz service -s /world/empty_world/create \
--reqtype gz.msgs.EntityFactory \
--reptype gz.msgs.Boolean \
--timeout 300 \
--req 'sdf: '\
'"<?xml version=\"1.0\" ?>'\
'<sdf version=\"1.6\">'\
'<include>'\
'<pose>1.6 0.15 0 0 0 0</pose>'\
'<name>Model1</name>'\
'<uri>model.sdf</uri>'\
'</include>'\
'</sdf>" '\
'allow_renaming: true'
model.sdf
needs to be an sdf without world, e.g.:
<?xml version="1.0" ?>
<sdf version="1.9">
<model name="rock">
...
</model>
</sdf>