b07 b02 b03 b04 b05 b06 b01 en11

3dNemo Tutorials

     
  t01  
Google Earth to Unity - KAUAI ISLAND

A tutorial on how to extract data from Google Earth to use as a reference for creation of realistic terrains in Unity. This example is the Kauai Island from the Hawaiian archipelago.

Image from Unity game engine using Terrain object.
 
  ge1  
Extracting data from Google Earth:

First in order to extract terrain data from Google Earth you need SketchUp Pro (another App. from Google). There is a trial version (it seems full functional) for 8 hours of usage.

1- Open Google Earth and go to your target location.
2- You must be about 500 m of altitude.
3- Open SketchUp Pro and select "Tools:Google Earth:Get current view" or something like that (sorry, I work mainly in spanish)
4- Select now "Tools:Google Earth:Togle terrain"

Kauai Island as shown in Google Earth
 
  ge2  
 

At this moment you have a mesh with a b/w texture of the terrain in it, in order to get the colour texture, switch back to Google Earth and select "File:Save:Save Image", if you make it carefully, the image saved is the exact texture for the terrain.

But ...

As said you must be about 500m above the terrain to get a good mesh, you can capture at higher altitudes but you'll get a very low resolution mesh.

Sketch Up pro captured pieces from Google Earth
 
  ge3  
 

So, you must capture a piece of terrain and the image in Google Earth, move slightly and capture again and so on. Even if you don't move at exact increments, SketchUp Pro will place the pieces of terrain in a correct way.

At the end you will have a 3d model of the terrain made of several overlaping meshes that you can export as 3ds format. Then you will stitch the meshes in 3DStudio or your favorite 3D program, don't worry about the UVs (texture coordinates) at this moment.

Sketch Up pro mesh captured at about 3 km altitude above the Google Earth window
 
  ge4  
 

About the texture, take the several images you got from Google Earth, compose a single image in Photoshop, with of all them. You can now make a "planar" projection of the texture over the terrain.

Maybe you'll have to tweak a little but, although a tedious process it is possible to get good results.

Tip: As the texture UVs are not important, you can trace roughly a square route around the area you are interested and if you have a very big monitor you can get larger images in less steps to get the whole area texture. Anyway the elevation data must be made in 500 square meter pieces.

 
 
  ge5  
Conforming Terrain Object in Unity:

Look for:

"Physics.RaycastAll" in Unity scripting manual, you must set a "Mesh collider" for your 3DS terrain model.

Then use "terrainData.GetHeights" and "terrainData.SetHeights" in a "for" loop.

So, place the 3DS terrain mesh over a Unity Terrain the same size (is better to make a square mesh in 3DS, because the Unity terrain is always square), cast a ray downwards over the mesh, get the "y" coordinate, and set the Unity terrain height.

 
 
  ge6  
 

Then you can cast the texture in the terrain setting "Tile size x" and "Tile size y" the same as "Terrain Resolution" in meters.

Now you can texture the terrain and place trees and details in it.



NEW*

"Conform_Terrain.js" script available included in a demo project, download here.
by Fran Galvez and Iñaki Lauret (3dnemo).

 


The only things to know for a correct setup:

Import a mesh and add a mesh collider to it.
Place over a Unity Terrain object of the same size.
Add the "Conform_Terrain" script to the Unity Terrain.
Click play.

The demo project is ready and you only need to click play to see the Unity Terrain conformed. Stop, hide the "terrainMesh" object, and deactivate the script, that's all.

Also, you can check the Reset Terrain var to flatten the terrain again.

WARNING: The script is slow (several seconds depending on machine) so it is executed in a Start function and must be deactivated after it makes the work.