Importing terrain from Google Earth into Unity3D in 5 Steps

Using real terrain in games is just pretty darn cool. The idea of pulling an actual mountain peak which I’ve never skied before into a video game so that I can actually ski it was just too hard for me to resist.  And thanks to Google Earth, it is now possible to pull a 3D mesh of actual terrain into Unity 3D.  Once you are good at this, this can be done in under 10 minutes, and if you know a little about Unity, you can plop a skier onto your new terrain and hit the slopes.

In this example, I pulled a sample skier from Google’s 3D Warehouse, and just added some basic physics to it (which I’ll do a tutorial on shortly).  There is no animation (yet) on this skier, but you get the idea.

To get started All you need to do this is these 3 free apps;

- Google Earth (free)
- Google SketchupPro 8 (they have an 8 hour free trial)
- Unity 3D (free, V3.3 is what I’m using)


Step 1 – Boot up Sketchup Pro

When you go into Google Sketchup Pro 8, first find the button at the top that says “Add Location…”.  Then type in a location in the search bar that you want to map terrain from.  Once it comes up, it maybe a little fuzzy, so click on the minus sign to zoom out about 4 or 5 times.  This will bring you up to around 3 or 4,000 feet above your terrain, which is about right.  Then select the region and click “Grab” to pull in a flat file of terrain data.  Then click a button just to the right of the “Add Location…” button, called “Toggle Terrain”.

 

Step 2 – Export and Save as a FBX file

Once clicked, then boom, you should have a 3D terrain image (e.g. mountain) looking at you. Excited yet?!  I certaintly was the first time I did this. You now need to got to “File” / “Export” / “3D Model…” to save this as a .fbx file.

Note, you may need to try a few locations and altitudes to get all of the terrain that you want.  Also, I suggest importing a square foot-print of terrain so that you have enough playing surface in your game before your character falls off it.

Step 3 – Import Terrain into Unity

OK, now you are ready to open up Unity and view your new fancy terrain mesh. Note, a mesh is a series of triangles that makes up your terrain.  When importing from Google Earth via Sketchup, you won’t be able to get any textures or details, just the mesh itself. Trees, rocks etc you’ll have to “paint” on yourself using Unity’s terrain tools (which are pretty easy and spectacular).

Now go to “Assets” menu (top menu bar), and select “Import New Assets…” and select your .fbx file you saved from Sketchup.  Once done, you will notice that it was plopped into your “Projects” window.  You then can simply drag and drop it into your scene view in Unity. If you left click on it, you will see the mesh made up of thousands of triangles.

Step 4 – Convert your Mesh to a Terrain

You are not quite done yet, but it won’t be long.  You now need to convert your mesh to a “Terrain” object which unity can recognize (so you can paint trees etc onto it).  You’ll need to first import a fancy javascript file to add a menu item to the Terrain menu at the top of Unity.  Save this file: Object2Terrain.js to a folder called “Editor” in your Unity Assets folder.

It must be named exactly like this to work (the folder name is case sensitive).  Once this is done correctly, you will see a new menu item under the “Terrain” pull-down menu at the top called “Object to Terrain”.  But first, you need to go to “Terrain” and click on “Create Terrain” to create a terrain object in the Hierarchy view.  Then click on the actual mesh from the Hierachy view and drag it into the new “Terrain” folder created.  You will see a warning saying “Losing prefab?” or similar, and simply press “OK”.

Now you must click on the actual mesh in the Hierarchy viewing area that is within your new “Terrain” folder, and NOT a parent folder called “Google_Earth_Terrain” or the filename parent folder.  Once you have selected the child mesh in the Hierarchy view, go ahead and select the new “Object to Terrain” menu from the “Terrain” pull-down menu at the top.

Step 5 – Make your Terrain Pretty

Now that you have your newly created terrain, click on the “Terrain” folder in the Hierarchy view.  You will now see a number of options in the “Inspector” tab for painting the terrain with a texture, or adding trees and so on.  When you click on the child mesh itself under your Terrain folder in the Hierarchy view, you will also be able to assign a material (e.g. like snow) to your new terrain.  You can then move onto adding a light source via “Game Object” / “Create Other” / “Directional Light” so you can see textures and trees etc better.  You will likely also want to add a “skybox” so show a sky, add other meshes and so on… until you have created (or recreated) the landscape you are looking for.

PLAY MY HACK!

OK, just look at the terrain…this is Ymir Peak from Whitewater Ski Resort in Nelson, B.C. Canada. OK, just ignore the lack of animation in the skier, the fact that you can ski uphill, bounce off the snow etc.  Just use arrow keys to move around and space to jump.  Again, yes, it’s just a hack for demo purposes so stop laughing… ok, well keep laughing then and go find the cabin at the bottom of the mountain. :)

www.alpenglowgames.com/ymir

 YouTube Tutorial

Comments

  1. admin :

    Show us some love, and ask some questions or make a comment. :)

    • nab :

      Cool dude. I just jacked your script. I can’t understand some of it, but that will change once I take a C++ class and a java class .! can’t wait. Meanwhile, I ll try to tweak this script to make it work for a snowboarder. (if tweaking the script becomes too complicated, I think all i have to do is rotate the snowboarder character 90 degrees and it will seem like he’s riding).

      thanks a lot dude.

      • admin :

        You are welcome, hope it helps. Note, it’s not the best physics script, but it will get you started. Note also that Unity Javascript is slightly different from regular web javascript.
        Chris

  2. errdog :

    Did you have to adjust the x y z values of the mesh before you did object to terrain? When I do it the height of my newly create terrain object is vastly out of proportion to my original mesh. What are the beginning values for resolution and size of the terrain before you create object to terrain?

    • admin :

      No, I left the xyz values at 0. Did you adjust the size of the mesh prior to import possibly? I suggest you don’t, and import a square bit of terrain… mine was 2,000 x 2,000 units. If you change the height/resolution etc after importing to Unity, you lose data and your terrain will likely not be functional. Hope that helps.

      • Alex :

        Fantastic stuff Chris – thank you. However, I got the same effect as ERRDOG. I imported my neighborhood which has some nice rolling hills and I eneded up with gigantic Afghani peaks when I used objectoterrain. Is there any scaling necessary between the imported mesh and the new terrain before I run the java script?

    • admin :

      Errdog – Ski Game Starter Kit is now live on the Asset store! :)
      http://u3d.as/content/alpenglow-games/ski-game-starter-kit/2FM

  3. nab :

    What up man :) have you made any progress? ever since I started reading about c++ I have not been able to stop . I’m now coding in c# in unity . I encountered TONS of brick walls while rigging my snowboarder take a look http://www.youtube.com/watch?v=Oucdva51Pu8 I stopped trying to make a snowboarding game (for a while). I m working on smaller projects: 2 side scrolling game. car game, galaga type game… I keep learning new tricks. I hope to get back to the MAIN PROJECT (snowboarder game) soon .

  4. tom :

    Have you considered doing this with more detailed terrain maps?

    By getting really detailed information like a 1m contour dataset, running it thorough arcscene to create a heightmap, then blending it in unity, you can get some real to scale terrain. Im currently working on a project based around this but applied to the Mount Seymour backcountry area and I would love to see it done for whitewater!

    Another thing worth checking out is a company named slingshot who created a snowboarding game very similar to your ski game several years back, for stratton, breckenridge, and jay peak: http://soulride.com/products/breckenridge.html
    From what I can tell they used very similar workflow to what I’m suggesting and it turned out pretty amazingly, I sunk a lot of hours into this game as a kid.

    All the best with your project!

Speak Your Mind

*