ROS2 and Gazebo: Creating a 3d world

# Creating a map

Initially, you are going to have some kind of a topo map:

Note that if you are going to follow step2 below (using Google maps), you will still need to do some post processing of what you got, there is no way to do it in a fully automated way. I would prefer to create my own landscape, rather than using Google maps. Probably, a compromise solution is to use "real" map with topo lines as a layer in an image editor, draw your own topo map on top, and then dispose the map layer.

Then you need to turn this map into a colored one, so that each color represents the height. You can do it by hand (like I did), or you can follow a greate guide here

Next step will be to turn it all into a point cloud, by moving the "topo-lines" up or down, according to their color:

Then we need to do some extrapolation, adding points in between:

Now as we have a nice surface, all we need to do (in a perfect world) is to turn it into a mesh. Unfortunately, we are not living in a pefrect world, and meshes created by libraries like o3d, pymesh, trimesh and so on, are either plain wrong or not waterproof (contain holes).

So the next step (in my algorithm) is to turn it into point cloud with points positioned in an X,Y grid (this is a fragment of the point cloud, zoomed in so you can see that points are at regular intervals along X and Y):

The reason we need it: for such a point cloud it is very easy to produce rectangles and then break them to triangles, and yes, I am going to generate mesh from my code, without 3rd party libraries (except some help from o3d).

Now, we have added some disturbancies, so the surface doesn't look that smooth anymore, so we need to run a (home made) smoothening algorithm on this point cloud:

Finally we can generate the mesh:

Now, I was not able to make o3d (the only mesh library that does a decent job out of all I have tried) to save UV mappings, so I have no choice but to add this code to the sequence. The idea is, our "landscape" if projected to the ground plane, is rectangular, so we can take a rectangular map (or at least pictures of roads, buildings, lawn, trees etc) and use as a texture:

This last screenshot was made in Gazebo simulator, if you zoom in, you can see the building and a robot from the previous section:

Finally, we can replace the "test" texture with the real one: