TGE/WorldBuilding/Real World Terrain

From TDN

Contents

Introduction



This tutorial shows you how to use real-world terrain data freely available from the U.S. Geological Survey to create terrain







Overview



Before diving in, let's take a look at the tools we will need and the general steps we're going to follow to make our real world terrain


First, we will need to get some terrain data from http://seamless.usgs.gov.


Next, we'll need to process that data into an image. 3DEM is a great freeware tool that does just that: http://www.visualizationsoftware.com/3dem.html. Go ahead and install this now.


Then, we'll need to convert the bmp created using 3DEM to a PNG file. I use: http://www.batchconverter.com, but any image editor that can convert BMP files to PNG will work just fine. Go ahead and install this now.


Finally, we will import our image into Torque and use the World Editor to tweak our terrain. If you haven't yet installed the Torque Engine, go here to learn how to do so: http://www.garagegames.com/docs/tge/general/apb.php






Getting Real-World Terrain Data



We are going to use what's called the Digital Elevation Model to represent our raw real-world terrain. Go ahead and open http://seamless.usgs.gov


Click on the U.S. map on the right hand side in the frame that says: View and Download U.S. Data.


You should see the viewer open up with a map in the middle of the screen and a tool bar on the left.


Down towards the bottom of the toolbar on the left, you should see a red bar that says "Download"


There are four buttons under that. Float over the second button and it should show a tool tip that says "Single template download" Click that button and make sure it's red to indicate it's active.


At the bottom middle of the page, you should see a dropdown box called "Template" which is currently set to "NONE"


Click the drop-down box to get its list and select "7.5 minute Grid Cells - CONUS" You should see a message dialog that asks if you want to auto zoom. Click "OK"


What we're doing here is setting up an overlay that shows each and every 7.5' grid the USGS has on file. We are going to use one of these for our terrain data.


Now, here's where we run into a little glitch. The zoom doesn't go in far enough to actually see the map sections, so we need to zoom in a bit more ourselves. We can do this one of two ways:


1. Select the zoom in icon under the Zoom bar in the left hand tool bar. Make sure it's red to indicate it's active. Now, whenever we click the map, it will zoom in. We will need to click in several times until we see our square grid cells. If you use this method, you will need to reselect the Single Template Donwload button under the donwload section and reslect the 7.5 minute Grid Cells - CONUS option in the downloads section of the toolbar when you're ready to download. (Trust me, that was harder to write about than it is to do!)


2. OR - Use the zoom scale in the upper right hand corner of the page. This lets you zoom in and out without having to select the zoom tool and re-selct the template download tool. A bit more straight forward. You want to select the zoom level that gives you about a 300,000:1 scale so you can clearly see the square grid cells.


Note: You can scroll around the map by clicking on the outside borders.'

Once youv'e found the grid cell you like and have made sure the single template download tool is active with the template set to to 7.5 minute grids - CONUS, click anywhere in the grid cell to open the download dialog.


By default, the download data is set to ArcGRID. We need to change that. In the download dialog, click "Modify Data Request" at the top of the page.


You should see the SDDS Request Options Page open up. The fifth item down (National Elevation Dataset (NED) 1 Arc Second) will be checked with the arcGrid option selected in the Data Format dropdown box.


Click the Data Format dropdown box and select BIL.


Note: 3DEM, the freeware we will use to process our data, does not understand arcGRID data. It works just fine with BIL data.'


Now, go all the way to the bottom of the page and click the "Save Changes and Return to Summary" button.


Double check the SDDS Request Summary Page and make sure your data format is BIL.


Note: This page also shows you other interesting information like the latitude and longitude boundaries of your cell. This is helpful for organizing multiple cells into a master map which might represent your world in game while each cell would be an individual level.


Finally, click the Download button to get your data. The download page may say "Adding Request to Queue" before it actually starts. At some point, it will say "Extracting Data" and then you will get your download dialog. Don't panic if it takes a minute or so to get going.


After the download is complete, unzip its contents and go get some coffee. You deserve it!









Processing DEM Data




Initial Conversion using 3DEM


Now that we have some terrain data to work with, we need to convert it to something usable in the Torque World Editor. Using 3DEM, we are going to make our base heightfield graphic that represents the terrain elevations with varying shades of black, gray and white.


Start 3DEM and select File/Load Terrain Model.


In the DEM File Type Dialog, select the second option: SRTM Data (hgt, bil)


Click OK.


Browse to where you extracted the data you downloaded in the previous section and open the .bil file


What you will see next is a very cool Shaded relief map of your cell grid.


Now, I need to stop for a minute and talk about scale. As mentioned in the previous section, we are working with 7.5 minute gride cells. What this means is our grid is 7.5 minutes square. A minute is a very small measurement of latitude or longitude. There are 360 degrees of longitude arond the Earth, each divided into 60 minutes. It works just the way you learned in high school geometry. And, yes, in each of those minutes is 60 seconds. So, our grid contains roughly 1/10th of a degree of landscape. This corresponds to about 13,500 meters. So, our square is 13.5 square Km in size. But, our terrain grid in Torque is only 2 square Km. There are two ways we can deal with this:


1. Don't worry about it. You can use all 13.5 square Km worth of land and squeeze it into your 2 squre Km Torque terrain and it will work just fine and give you some very interesting and natural looking terrain.


2. Worry about it. If you really want to be accurate with scaling, then you'll need to cut out a piece of the map before converting it to a height field. Doing some math, we find that 2Km corresponds to .0185 degrees. so, to cut out a 2Km square piece of our grid, we need to cut out a piece .0185 degrees square.


If you look at the map in 3DEM, you will notice that when you move your mouse around, it shows you the current latitude and longitude location of your mouse pointer down to four decimal places. Pretty convenient, huh?


So, let's do an example. Let's pretend our map starts in the lower left hand corner at 34.0000 latitude and -107.5000 longitude. to select a 2Km piece, do this:


a. press the F8 key to start the area selection operation. b. Line up the mouse precisely in the lower left hand corner so the latitude is exactly 34.000 and the longitude is exactly -107.5000 c. Click and hold the left mouse button. d. Carefully drag up until the latitude reades 34.0186. Notice that we can't get exactly 34.0185 - the mouse position moves in .0002 increments. So, we'll be off by .0001 degrees. Close enough. e. Now, drag carefully to the right until the longitude reads -107.4815. (We get this number by subtracting 0.0185 from -107.5000) f. Check to make sure both the latitude and longitude read correctly as 34.0184,-107.4815 and let go of the mouse button g. Press the enter key and voila, you have a 2Km square grid.


This procedure may seem tedious at first. If you are really gung ho about scale accuracy, just play with it for a while until you get the hang of it Just remember you need a square that is .0185 degrees on a side.

Next, we need to convert the graphic to a grayscale height field.


a. Select Color Scale/Modify Scale from the menu bar to open the Terrain Color dialog. b. Along the left side you will see the original color gradient scale. c. Select the lowest elevation button and set it's color to black by setting all three color sliders to 0. d. Click the highest elevation button and set its color to white by setting all three color sliders to 255.


Note: Setting the color gradient wide from black to white or narrow from dark gray to light gray doesn't seem to effect the color depth of the final heightfield Torque generates when we import the final PNG image. Either way, the terrain elevation gradient is the same in Torque. So, I just use black and white as my endpoints for simplicity.


e. Go back and click the lowest elevation button. f. Click the "Spread To" button just below and to the right of the lowest elevation button. g. Click the highest elevation button.


At this point, you should see a nice gradient from black to white going up.


Click OK to close the Terrain Colors dialog.


Our last modification in 3DEM is to get rid of the shaded relief shadows to get a true heightfield.


a. Select Color Scale/Shaded Relief from the munu bar to open the Lighting Parameters dialog. b. Set the Shade Depth (%) setting to 0 to remove all shadows.


The end result is a pretty boring blob.


Next, we need to turn off the coordinate grid. If we don't, it will remain in our graphic and break our terrain. From the Geo Coordinates menu, select Coordinate Grid Off and verify the grid and latitude/longitude numbers are gone. Don't worry about the little notched square. This won't show up in the saved file.


Finally, save it out as a BMP file using the File/Save Map Image option from the menu bar.


Final Conversion Using Advanced Batch Converter


Our final step in getting a usable heightfield is to adjust its size and convert it to a PNG file. As noted in the Introduction, you can use any image editor that will do these two things. I use Advanced Batch Converter because it's the first thing I found that does what I need.


Start Advanced Batch Converter and open the graphic you saved out from 3DEM.


First, we need to resize our graphic so it is usable in Torque.


From the Image menu, select the Resize option to open the Resize Image dialog.


Set both width and height to exactly 256. If necessary, turn off the Preserve aspect ration check box. It is important that our graphic is exactly 256 pixels square. If we need to give up some accuracy in scale, that's just the way it is. One pixel corresponds to 7.8 meters, so a few pixels really won't matter that much.


Next, we need to convert our image to a PNG file.


From the File menu, select Convert.


In the file dialog, either select the PNG file format from the dropdown box or simply rename your file with a .PNG extension and click save.


And that's it for final conversion.









Importing Heightfield and Terrain Tweaking



Finally, we're ready to put our heightfield to work and see the results.


To make our heightfield available to the Terraform editor, we need to copy it to:


Torque/SDK/example/common/editor/heightscripts


Note: You may have to create this folder yourself if you haven't used heightfields before.


Next, launch your favorite Torque workspace. For example: torquedemo -game tutorial.base


Once in game, press F11 to bring up the Editor and select Terraform Editor from the Window menu.


You will notice a greenish looking box in the lower lefthand corner. This is the current heightfield for the existing terrain. We are going to replace this.


Click the Operation button in the right hand panel and select Bitmap from the pop-up menu to bring up the Load File dialog. You should see your heightfield fiel in the list. If you don't, go back and make sure it's in the heightscript folder described above. You'll need to completely quit Torque and relaunch for it to read this directory again.


Once you see your heightfield file in the list, select it and click the Load button.


In order for our heighfield to be applied, you next need to click the apply button in the right hand panel.


Note: When you click apply, it applies everything in the list of operations. This can be handy when you need to back up. For example, ifyou apply smoothing and don't like the results, simply remove smoothing from the list of operations you've performed and click Apply to get back to the terrain as it was prior to smoothing. This makes for some very handy non-destructive editing.''


At this point, you can see your new terrain. If you used a scale heightfield (one adjusted to represent 2Km of terrain), it should look pretty good right off the bat. If you used a non-scale heightfield (one with 7.5 Km squeezed in to 2 Km), it will look very pointy and jagged and need some tweaking.


In either case, smoothing will make your terrain look better. For scaled terrain, use a small amount of smoothing to make your terrain more natural looking


Click Operation and select Smoothing from the pop-up menu. Set Iterations to 5 and Aggresiveness to 0.25. Click Apply to see the results. Play around with the parameters to get a feel for the appropriate amount of smoothing for your particular terrain. Remember, you can always start over by deleting your smoothing operation from the operations list.


With non-scale terrain, you will need more aggressive smoothing. Start with about 25 Iterations at 0.25 Aggressiveness to make the terrain reasonable.


In general, scale terrain is natural and "realistic" while non-scale terrain tends to be more "interesting".


Finally, if you find yourself dropping into space when you change your terrain, simply select the exterior camera (ALT-C), move the camera well above ground and then select Drop Player at Camera from the Camera menu. You will find yourself underground a lot as you make dramatic changes to terrain.






{{Template:ContentStandard|

Summary


By using freely available Digital Elevation Model data, easy-to-find tools and Torque's built-in Terraform Editor, you can create realistic and natural looking terrain based on real-world data.


Here's a scaled 2Km image ready for import you can use to see the effects of using real-world DEM data for terrain:


Image:2k_Demo.png

This link shows a screenshot in-game using this heightfield


Image:2KDemoInGameOne.jpg

Here's a non-scaled 7.5 minute (about 13.5Km) image ready for import you can use to see th effects of using real-world DEM data for terrain. It will require a lot of smoothing to be useful and has a less natural appearance. It is more varied and "interesting" though.


Image:85628646.png


And this is what this one looks like ingame:

Image:13KDemoInGame.jpg



--Mike Lawrence 01:06, 14 Oct 2005 (PST)