Part One deals with the creation of images that will be imported into Torque to create the terrain. The purpose of this process is to use real-world data such as contour maps, GIS data, satellite imagery, etc., to generate the terrains in Torque.
Part Two covers the creation of images used to texture the terrain.
Later sections will other explore in-world terrain creation and editing techniques.
There are two types of images that will be used in this process of terrain creation:
Step 1.
This first example uses an AutoCAD drawing of the contours for a section of land drawn at full scale (1:1) to create the terrain shape (heightfield) image. The default size for a terrain in Torque (when the squareSize parameter in the mission file equals 8) is 65536 world units (WU). One WU in Torque is equal to one unit in the QuArK or WorldCraft map editors. A WU is equal to one inch.
In AutoCAD, I created a line box around the section of land representing 1.034 square miles (65536 inches). Then I saved the display to a 24-bit TGA file. We'll resize the image to proper scale and convert to an 8-bit (256 color) greyscale image in the next steps.
Here is a little closer look at the result.
Step 2. Now, let's wrap our brains around some scale and unit numbers. Each terrain square (made of two terrain triangles) is 256 world units; the squareSize parameter equals 8 by default. The terrain has 256 of these squares on a side for a total of 65536 world units (inches) on a side.
256 WU x 256 squares = 65536 WU (inches)
65536 inches / 12 inches = 5461.33 feet
1 mile = 5280 feet
5461.33 feet / 5280 feet per mile = 1.034 miles
1 mile = 1609 meters
1664.6177 meters / 1609 meters per mile = 1.034 miles
The numbers 8 (for squareSize) and 65536 (for terrain size) are not accidental; they are powers of 2 which works nicely with our images (and with the software). The size for our heightfield image must be 256 x 256 pixels. This means that when the image is stretched to fit our 65536 inches x 65536 inches terrain, each texture pixel (texel) determines the horizontal distance of 256 inches (or 6.504 meters) of terrain. Since each terrain square is 256 WU, each heightfield texel is used to determine the height of one terrain square.
256 pixels x 256 WU (inches) = 65536 WU (inches) 256 inches / 39.37 inches per meter = 6.5024 meters 6.5024 meters x 256 pixels = 1664.6177 meters = 1.664 kilometers = 1.034 miles
So to get the equivalent area in the image, crop the image just inside the line box created in AutoCAD representing 1.034 square miles. Then resize the image to 256 x 256 pixels. Leave the image as a 24-bit TGA file for now so we can keep our original colors for the contours--we will change this in the next step.
Step 3. Now we are going to paint over this contour image using gray color values representing the heights of the contour lines. In this example, the contours range from 410 feet elevation to 485 feet elevation. The gray scale can be any sequence of gray RGB values within the 256 colors ranging from 0,0,0 (black) to 255,255,255 (white). Establish your scale keeping in mind that its best to have some separation between the incremental values so they can be easily seen as you paint the contours. I calculated I had 16 elevation increments in the contour range of 410 to 485, divided 256 colors for the greyscale range by 16, and created the table below to keep track. I started at the color (0,0,0) and worked up.
| Elevation | RGB | Inc |
| 485 | 240,240,240 | 1 |
| 480 | 224,224,224 | 2 |
| 475 | 208,208,208 | 3 |
| 470 | 192,192,192 | 4 |
| 465 | 176,176,176 | 5 |
| 460 | 160,160,160 | 6 |
| 455 | 144,144,144 | 7 |
| 450 | 128,128,128 | 8 |
| 445 | 112,112,112 | 9 |
| 440 | 96, 96, 96 | 10 |
| 435 | 80, 80, 80 | 11 |
| 430 | 64, 64, 64 | 12 |
| 425 | 48, 48, 48 | 13 |
| 420 | 32, 32, 32 | 14 |
| 415 | 16, 16, 16 | 15 |
| 410 | 0, 0, 0 | 16 |
Now set your RGB value in your paint program and fill in your image following the contour lines:
In the image above, notice that the gray value is the same at the edges. This is because I want the edges to match when the terrain repeats itself. The edges could be different values; just match them at the top and bottom or left and right sides. When you have finished the "paint-by-number" process, decrease the number of colors in the image to 256 and save or export (depending on which paint program you use) your image as an 8-bit, greyscale PNG (Portable Network Graphics format).
Step 4. The next step of the image creation process requires flipping the image around its X-axis. In PSP, this is the flip option. Save your change.
Step 5. Notice the stepping effect in the image above. If you import this into Torque as is, you will have a set of steps surfaces. If this is what you want you're ready to go. But for this example, let's go a step further. Make a copy of the image above to do this: in the filters menu of your paint program (I used PaintShop Pro for this procedure) select Gaussian Blur to smooth out the edges a bit. I used a radius of 4 for this example. Save your change to this new image. You can try them both out in Torque to see the different effects.
Step 6. Now let's import these images into Torque. Place the images in Torque's /example/common/editor/heightscripts folder.
Step 7. In Torque, run any existing mission to which you'd like to add this terrain or select New Mission. Then press F11 to open the World/Terrain Editor. Click the Window pull-down and select the Terrain Terraformer Editor.
On the right side of the screen in the General Settings area, set the Minimum Terrain Height and the Height Range in meters.
Now, this will cause a bit of confusion, but due to a code issue (as of 1/23/02), the maximum elevation should be used for the Minimum Terrain Height. The highest elevation is 485 feet; this translates to a Minimum Terrain Height setting of approximately 148 meters.
485 feet / 3.281 feet per meter = 147.8208 (148) meters
485 feet - 410 feet = 75 feet 240/256 x 75 feet = 70.3 feet (240 is our highest color in the table above) 70.3 feet / 3.281 feet per meter = 21.4 (21) meters
Now click on the Operation box to roll out the terraform options window:
Select Bitmap from this window which brings up a bitmap load window. Highlight the image you want translated to a new terrain and click the Load button.
Then click the Apply button at the right side menu. You will see the terrain change. The scene needs to be relighted; from the Edit pull-down, select Relight Scene (Alt-L).
In the lower left of the screen the overhead map view of the terrain will change also to show the contours imported from the heightfield image. Notice that the image has the same orientation as the original one before we flipped it around the X-axis.
The white line in the map represents the extents of your terrain before repeating. In the main view, this boundary is illustrated by a green box. The red box toward the interior represents the mission area and is modified by the mission editor.
Step 8. Pull-down the File menu and use the SAVE AS option to save your mission. Be sure to change the directory also to /fps/data/missions/.
Additional Notes:
1. It can be more difficult to locate your original contour features after smoothing with Gaussian Blur. Try reducing the radius or use the original image and smooth the terrain in Torque. A more time-consuming technique (but much more accurate and rewarding) is to create the terrain image at a much larger scale and reduce it to 256x256. For example, you might try constructing the image at around 2048x2048 or 4096x4096; this means a LOT more painting time but after reducing, the information is retained (although somewhat smoothed) by the resize algorithms. The resulting terrain is much more accurate than the gaussian blur process.
2. Once you have saved your mission, the terrain data is also saved as a .TER file in the missions directory. You can also import previously saved .TER files rather than recreating heightfields.
Reference to the newly created terrain file is stored in the mission file in a TerrainBlock that needs to be named "Terrain":
new TerrainBlock(Terrain) {
rotation = "1 0 0 0";
scale = "1 1 1";
detailTexture = "~/data/terrains/details/detail1";
terrainFile = "./test_terrain3.ter";
squareSize = "8";
locked = "true";
position = "-1024 -1024 0";
};
3. The units displayed in the mission editor map (x, y, w, h) represent the (x,y) distance of the upper left corner of the mission area (in red) from the image center and the (w,h) width and height of the area in terrain texture units. Note that the position parameter in the mission file also uses the terrain texture units to position one terrain repetition. There are 32 reps of the terrain textures (don't confuse these with the heightfield images) with each terrain texture image being 256x256 pixels.
32 reps x 256 pixels = 2048 texture units 65536 WU / 2048 texture units = 32 WU per texel
This information will be important in Part Two on creating terrain textures. Convert these values to inches by multiplying by 32. (The total area represented ranges from -1024 to +1024 when the terrain squareSize = 8 for a total 2048; 2048 x 32 = 65536.
4. If your contour area needs to be larger/smaller than 1.034 miles, it is possible to increase/decrease the terrain squareSize. This will increase/decrease the area available before the terrain repeats. Increase or decrease the squareSize parameter in powers of 2.
| Terrain squareSize | Texels +/-, total | Texels x 32 = WU | Feet | Miles | Meters |
| +-4096 = 8192 | 8192 x 32 = 262,144 | 21845.33 | 4.137 | 6658.13 | |
| +-2048 = 4096 | 4096 x 32 = 131,072 | 10922.66 | 2.068 | 3329.06 | |
| +-1024 = 2048 | 2048 x 32 = 65,536 | 5461.33 | 1.034 | 1664.53 | |
| +- 512 = 1024 | 1024 x 32 = 32,768 | 2730.66 | 0.517 | 832.26 | |
| +- 256 = 512 | 512 x 32 = 16,384 | 1365.33 | 0.258 | 416.13 |
Changing the terrain squareSize in the mission file also affects the control in the terrain editor and terrain material painter; you will have more control at smaller sizes. Be sure to change the position values of the terrain to correspond to the worldSize also. For example, if we want more control of the terrain editing, set the squareSize = 4 and the position to "-512 -512 0":
new TerrainBlock(Terrain) {
rotation = "1 0 0 0";
scale = "1 1 1";
detailTexture = "~/data/terrains/details/detail1";
terrainFile = "./test_terrain3.ter";
squareSize = "4";
locked = "true";
position = "-512 -512 0";
};
Note: The waterBlock entity may not work properly at sizes other than terrain squareSize = 8 (as of 1/21/2002) because of some hard-coded values in the engine. It has been reported that there are also some issues with the AI in this regard.
Please contact me if there are errors or areas that need more elaboration. Hope this helps.
|
Last Modified: September 22 2002 | Copyright 1997-2007 Desmond.Fletcher@usm.edu School of Construction | URL: http://holodeck.st.usm.edu/vrcomputing/vrc_t/tutorials/terrain/heightfields.shtml |