Tuesday, June 26, 2018

Blender: Environment Creation

Blender is a "free and open source 3D creation suite" and is often used for animations or 3D modeling for 3D printers.  In our case, we use a special plugin to import a DEM file into Blender and turn it into a 3D mesh.  From there, we will export the mesh as both an .stl file, and a collada (.dae) file.


BlenderGIS Plugin


The plugin we use, and many great tutorials on how to use it can be found here: 
https://github.com/domlysz/BlenderGIS

Follow the tutorial on how to add the plugin to Blender


Getting the DEM file into Blender


Once the plugin is in your copy of Blender, we want to File>Import>Georeferenced raster.  From there, see the options on the bottom left of the import screen.  We want to select the option Import raster "As DEM".  Be sure to NOT click the box "Apply on existing mesh".  Then, import your dem file.  You should see an image corresponding to your terrain and might look something like this:

Attaching Image to DEM mesh


Now, you will need to attach that Google Earth picture to the mesh you've just created.  You do this by looking to the right hand side of the screen for the icons that represent a camera, pictures, the earth, and others.  Scroll through those icons till you reach material and texture tabs (represented by a checkered sphere and checkered board respectively).  Add a material to the mesh, and make its texture the image you've got from Google earth.  You may need to find some Blender tutorials if you struggle on this part.

Be sure to select the 'shadeless' option in Materials>Shading, and to select the Viewport Shading>Material at the bottom middle part of the screen to see what it looks like in the preview window.


Lining up the Image


You will probably notice that the image is not perfectly lined up with your DEM heightmap.  Unfortunately, this cannot be fixed within Blender (as far as I could tell), so I had to use MATLAB to shift the image until it lined up correctly.  The Matlab script I used is below:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
image = imread('uofu_texture_labeless.PNG');
shifted_im = circshift(image,[0,40,0]);
imshow(shifted_im);
imwrite(shifted_im, 'uofu_texture_labeless_off40.PNG');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Other file formats might work too.  I worked primarily with png files personally.

Anyways, you can use Matlab, Photoshop or whatever you want to line it up.  My guess and check through Matlab method only too 4 tries to get it right, but is probably not the cleanest way to line this up, and presents a serious problem when trying to automate this process.


Exporting the Mesh


Once you have lined up your image, you should save this blender file.  It will allow you to return and modify it.  Additionally, you can return to it if you discover that north in Gazebo doesn't line up with north in the mesh.  This solves the problem we had previously when trying to import the dem file directly into Gazebo. 

Once you have all of this done, export the mesh to .stl and .dae collada files.  These will be used within your .world file in Gazebo to import the mesh into your environment. 

No comments:

Post a Comment