Tutorial Index

Creating Roads In Freeworld3D

In this tutorial you will learn how to create roads with the new Roads System in Freeworld3D v2.1.  The following are the topics covered in this tutorial.

Introduction

Creating a basic road

Creating a closed loop road

Painting A Terrain Layer Underneath The Road

Editing and Deleting Control Points

Reading exported road data

 

Introduction

Freeworld3D v2.1 now supports an extremely powerful yet easy to use road creation system.  By simply clicking points on the terrain in the 3D viewport and then clicking a single button an entire road can now be created.  Each point plotted on the terrain is termed a Control Point and the road is interpolated between each point using "Hermite Interpolation" to give a smoother more realistic rendering.

With the new road system, once a road has been laid out the terrain under the road can be "leveled" or "smoothed" out to match the shape and contour of the road.  This is done with the Level Terrain command button.  The road's Fadeoff property value also dictates how smooth the terrain around the edges of the road are when leveled off.

After plotting road points, you can also then restrict dips and hills in the road to a maximum slope increase or decrease.  If no part of the road should have a slope greater than some given value, entering this value into the MaxSlope property value then clicking Apply Slope automatically adjusts each point in the road to conform to the correct slope and steepness.

The road's triangle count may also be controlled through the Step property value.  Increasing this value will increase the number of points and vertices between each Control Point laid out on the terrain.  The curvature of the road between each Control Point can be controlled by setting the road's Curvature property value.  Default value is 0.5.  Setting this to 0 will lead to straight lines in between Control Points.

After plotting the Control Points for the road, the ends can be connected by setting the Connect Ends property value to true.

The road system also allows for painting terrain layers underneath the road.  Selecting an Alpha Layer then clicking the Paint Layer command button performs this function.  This feature is useful for painting a dirt or cracked rock texture underneath the road and also so that it sticks out from the sides.  This provides a good transition from grass to dirt to road.


Creating a basic road

  1. Create a custom terrain


     
  2. Navigate to the Terrain Tools drop box in the Terrain tab.
  3. Click New Road then select the newly created item in the list box.
  4. Set the Width, in this tutorial a value of 6 is chosen.
  5. Click Add Points
  6. Begin plotting the road's Control Points by Left Clicking in the viewport.
  7. When finished adding points, uncheck the Add Points button.


     
  8. Click the Level Terrain button.  This will smooth the terrain underneath the road.  The Undo/Redo system is enabled for this function.

     
    before                                                                     after

     
  9. Change the Width to 4, which will ensure the actual road geometry sits correctly on the leveled terrain.
  10. Choose a texture by clicking the button next to the Texture property item
  11. Set Tile UV appropriately depending on the orientation of the road texture.
  12. Click Generate Geometry.
  13. You should have something that looks like this.







 

Creating a closed loop road

  1. Follow the instructions above.
  2. Before clicking Generate Geometry, set the Connect Ends property value to true.
  3. Now click Generate Geometry.

Painting a terrain layer underneath the road

  1. After setting up a road, set the Terrain Layer property value.  The selection should be the name of an existing Terrain Alpha Layer in the Terrain Layers list box.
  2. Click Paint Layer.  This will cause the selected Terrain Layer to be painted directly underneath the road.
  3. Setting the Falloff property value will also affect the edge smoothness of the painted terrain layer.
  4. The Undo/Redo system is enabled for this function.

Editing and deleting road points

Translating Control Points works the same way as translating scene meshes.  Click the Select Object toolbar button and select the points in the viewport.  You can then translate the points by clicking the Translate Object toolbar button.

Deleting Control Points is done the same way as deleting scene meshes.  After selecting one or more control points, simply click Edit - Cut or use the shortcut keys, Ctrl-X.

To insert control points in between existing control points, select the control point you wish to add new points after, then click the Add Points command button.  Then simply click to add the new points in the viewport.  Each new control point will be added after the previously selected point.

Reading exported road data

When you export to ASCII or XML, all that is contained about the road data is the name of the text file containing the actual geometry. There will be a "roads" folder created, inside this will be all the associated textures and the main geometry text file.

Here's a sample geometry text file.
 

1
Default
roadTexture.bmp
1.000000
30
18.090612 0.002139 11.153298 0.000000 0.000000 0.045882 0.998857 0.013426
17.950195 0.050000 11.633176 0.000000 0.500000 0.045882 0.998857 0.013426
17.809778 0.002139 12.113053 0.000000 1.000000 0.045882 0.998857 0.013426
17.445873 0.050000 10.964640 0.615384 0.000000 0.027453 0.999591 0.008033
17.305456 0.050000 11.444518 0.615384 0.500000 0.027453 0.999591 0.008033
17.165039 0.050000 11.924397 0.615384 1.000000 0.027453 0.999591 0.008033
16.559355 0.050000 10.705235 1.461540 0.000000 0.014272 0.999889 0.004176
16.418938 0.050000 11.185114 1.461540 0.500000 0.014272 0.999889 0.004176
16.278521 0.050000 11.664992 1.461540 1.000000 0.014272 0.999889 0.004176
15.491507 0.050000 10.392772 2.480769 0.000000 0.006756 0.999975 0.001977
15.351089 0.050000 10.872650 2.480769 0.500000 0.006756 0.999975 0.001977
15.210672 0.050000 11.352529 2.480769 1.000000 0.006756 0.999975 0.001977
14.302769 0.050000 10.044935 3.615384 0.000000 0.003018 0.999995 0.000883
14.162352 0.050000 10.524814 3.615384 0.500000 0.003018 0.999995 0.000883
14.021935 0.050000 11.004692 3.615384 1.000000 0.003018 0.999995 0.000883
13.053585 0.050000 9.679411 4.807693 0.000000 0.001311 0.999999 0.000384
12.913168 0.050000 10.159289 4.807693 0.500000 0.001311 0.999999 0.000384
12.772751 0.050000 10.639168 4.807693 1.000000 0.001311 0.999999 0.000384
11.804403 0.050000 9.313888 6.000000 0.000000 0.000570 1.000000 0.000167
11.663986 0.050000 9.793766 6.000000 0.500000 0.000570 1.000000 0.000167
11.523569 0.050000 10.273644 6.000000 1.000000 0.000570 1.000000 0.000167
10.615664 0.050000 8.966050 7.134615 0.000000 0.000255 1.000000 0.000074
10.475247 0.050000 9.445929 7.134615 0.500000 0.000255 1.000000 0.000074
10.334830 0.050000 9.925807 7.134615 1.000000 0.000255 1.000000 0.000074
9.547814 0.050000 8.653586 8.153847 0.000000 0.000120 1.000000 0.000035
9.407397 0.050000 9.133465 8.153847 0.500000 0.000120 1.000000 0.000035
9.266980 0.050000 9.613343 8.153847 1.000000 0.000120 1.000000 0.000035
8.661299 0.050000 8.394182 9.000000 0.000000 0.000063 1.000000 0.000018
8.520882 0.050000 8.874061 9.000000 0.500000 0.000063 1.000000 0.000018
8.380465 0.050000 9.353939 9.000000 1.000000 0.000063 1.000000 0.000018
108
0 3 1 1 3 4 1 5 2 1 4 5 3 6 4 4 6 7 4 8 5 4 7 8 6 9 7 7 9 10 7 11 8 7 10 11 9 12 10 10 12 13 10 14 11 10 13 14 12 15 13 13 15 16 13 17 14 13 16 17 15 18 16 16 18 19 16 20 17 16 19 20 18 21 19 19 21 22 19 23 20 19 22 23 21 24 22 22 24 25 22 26 23 22 25 26 24 27 25 25 27 28 25 29 26 25 28 29

Using the example above, here is the format for the file.
 

Road Count
     Road Name
     Road Texture
     Opacity
     Vertex Count
            x y z u v nx ny nz            // first vertex
            x y z u v nx ny nz            // second vertex
     Indice Count
            index0, index1, index2, ....          // every 3 indices is a single triangle

That's it. It should be very easy to parse and read into your engine or demo. Here's what the ordering of the vertices in the export file correspond to in the actual road geometry.

 


Copyright 2005 Soconne Inc.

terrain editor world editor terrain heightmap opengl directx game programming C++ terrain generator terrain editor editor farcry games developmen