Route Building Tutorial 10: Starting A Tunnel

In previous tutorials, we concentrated on building an operational route with very few scenic elements. It is now time to add some of these, starting off with a tunnel,. Over the next few parts, I will describe how to build this (in CSV format – Once again refer to http://bve.altervista.org/guide.html by Luigi Cartello if you wish to follow this). The tunnel will be placed in a landscape which will require the use of several commands not yet introduced, including pitch, height, brightness and fog.

In this tutorial, we will start making our tunnel object by creating the portal and the tunnel walls. It is possible to use structure viewer (available from Mackoys site) to check the progress of objects being built. However, it is sometimes difficult to correlate this view with the cab view. To overcome this, I tend to view objects which are being developed positioned correctly on the route. When relatively few objects are present, loading times are minimal and not a problem. However, when loading times become excessive, it may be necessary to develop the object on a short, cut-down section of the route.

When constructing a fictional route (as we are), it is important that the landscape being created is believable – in practice, tunnels are generally very expensive to construct and are only used to overcome serious obstacles. Embankments and cuttings are usually the preferred means of overcoming uneven terrain and observing real life railways will soon reveal where these occur.

On our route, the context of the tunnel will be that it passes through a very steep sided high hill, climbing away from a seaside or lakeside location to run inland. Considering this in more detail, we will start the route on an embankment but as the surrounding ground level rises, we will run in a cutting before entering the tunnel, all the time climbing at a reasonable gradient. All will become clear as construction progresses.

Time to get to work…

What better way to start building a tunnel than by constructing the entrance portal.

All BVE objects require two fundamental features;
1. The texture (picture) to be displayed. Photorealistic textures are to be preferred for the very reason intimated by their name. Their use is not always necessary (or indeed possible) but for dominant features such as portals, their use certainly preferred. Any texture obtained from a photograph should be from the correct perspective and preferably not feature shadows which do not fit in with the general lighting scheme of the route.
2. construction of the faces displaying the texture. Distortion of the texture to a significant degree is best avoided. Faces of the object should meet with no visible gaps and superimposition of textures must be avoided to prevent ’flickering’.

The tunnel portal we are going to create is based on one located in the Avon Gorge on the Portbury branch. The original image looks like this:

The starting image for this object

The starting image for this object


A bit of ‘photoshopping’ is needed to make this suitable for using as a BVE object. The main modifications made were to crop, rotate and stretch it horizontally (to ensure it fits over our two tracks rather than the single line present in real life).

The sign on the left hand side was removed and the limited clearance warning modified to a more reasonable size. Brightness and contrast have also been adjusted.

To ensure the final file size is not excessive, the image was resized to 512×256. When deciding on the size of images to be used for transparencies, ideally the smaller the better (as the route will load faster and run at a faster frame rate). It is also important not to lose detail or introduce pixellation as this somewhat defeats the point of using photorealistic objects. A compromise is normally necessary based on these factors and for a large object where the detail will be visible, it is better to use a relatively large image. If problems are encountered with slow or jerky running, we can always reduce the image size further.

An important point to note regarding image sizes is that to display correctly, they must be sized to a number of pixels which fit the ^2 series. Acceptable image dimensions are therefore 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 (including combination of these where square images are not used).

After resizing tunnel mouth was filled in black (0,0,0 – any other colour can be used as the transparent colour although if the object is to be converted to a .x file, black is the only acceptable colour).

A useful point to remember when selecting a transparent colour is to ensure that it is not present in the part of the texture you wish to leave visible (otherwise the texture will appear to have holes in it!).

The image was finally converted to an 8 bit indexed colour image. This is desirable to reduce the file size and also to overcome potential transparency colour issues which may arise with some graphics cards. When converting 16 bit images to 8 bit, it is best to avoid dithering as this may affect the borders of transparent regions (leading to coloured fringes), and now looks like this:

The completed image

The completed image


Now that we have a photorealistic texture, it is time to create the tunnel portal. Using the methods outlined in the object coding guide, the code for the tunnel entrance is (in a new .CSV file):

Notice how the width / height ratio of the object is very similar to that of the bitmap being displayed.

Save this object file as ‘TUNNEL ENTRANCE.CSV’ in the objects directory and index as free object 50. The tunnel entrance should be positioned on the route at 250m.

The next job is to start constructing the tunnel walls. For the first 25m of wall, we will include these as part of the tunnel entrance object. The first task is to position the vertices which make up the corners of the individual faces.

By studying tunnels on other routes, the number of separate faces required becomes evident, with 9 being typical. The choice of number of faces used for tunnels (and bridges) where the alls are curved depends on two factors;

1. Appearance; the greater the number of faces present, the less ‘angular’ and more rounded the walls will appear, so the more faces, the better.
2. Loading and running speed constraints; the greater the number of faces, the larger the file size with increased loading times and the possibility of reduced frame rates occurring.

There are two conflicting requirements and as usual, a compromise must be found. It is worth considering the fact that where a tunnel exists, there will be no requirement for external scenery to be drawn and excessively high frame rates may be encountered when running in tunnels. To overcome this, I would suggest that use of the maximum number of faces conveniently possible is desirable.

For our tunnel wall, we will use 19 faces; ideally each vertex should be equally spaced around the tunnel wall. There are several ways by which this way be achieved, only one of which will be described. Stuttering of frame rates should not be a problem as the tunnel will be drawn immediately on loading the route.

A scale printout of the portal bitmap is produced where 1cm on the printout = 1m on the final BVE object (the dimensions of this were defined in the code for the portal). Points are then marked at 1cm intervals around the perimeter of the transparent area and the x and y distances measured from the bottom left of the image.

When performing the measurements, it is best to err onto the non-transparent side of the image as in practice the wall will be drawn as a straight line between the vertices being defined; this may result in some gaps being visible around the mid point between the two vertices if insufficient ‘clearance’ is given).

Using a spreadsheet to assist data entry, these are then coded into the object file after adjusting the x and y values for the offset of the portal (-5.75 and -0.3 metres respectively) like this:

These vertices make up the corners of the faces we are going to add and are ordered clockwise around the portal from the bottom left, vertices 0-19 at the front (0metres) and 20-39 at the far end (25.1metres).

Now, to display the faces, we need to use the addface command – for each face displayed we need to state which four vertices are to be used as corners of that face, remembering that they should be ordered clockwise. Vertices 0 and 1 are to be used for the bottom and top front respectively and 21 and 20 for the top and bottom rear respectively. In the object file we therefore need to add this:

The next job is to specify which bitmap image is being used for the wall. The texture we will use for the wall might seem excessively large but it is again photorealistic and the lighting method which is going to be employed requires a single image to form the entire wall.

Finally, we need to specify how this is to be displayed:

Here, the first number after the settexturecoordinates statement defines the vertices being used (again arranged in a clockwise direction) and the remaining two parameters how the bitmap is to be orientated and repeated (10x in the x direction in this case). As we have 19 faces forming our tunnel wall, each face must dsiplay 1/19 of the image in the y direction, hence the inclusion of 0.052631579 as a parameter – the maths would have been simpler had we used 20 faces!!

The settexturecoordintes command is fully described in the BVE object coding guide although one of the best ways to learn is to have a fiddle with the parameters and see what happens!

Given that the vertices we have positioned are based on measurements from a printed image, it is best to check that the section of tunnel wall we have just constructed is in the correct position with no gaps visible between the portal and wall. If on loading the route with the tunnel object correctly sited, gaps between the portal and walls are evident, move the vertices outwards slightly until no gaps remain (checking your work after each adjustment).

Now we are ready to add the second face – vertices 1 and 2 are to be used for the bottom and top front respectively and 22 and 21 for the top and bottom rear respectively. In the object file we therefore need to add this before our texture section:

Then, use the settexturecoordinates command to correctly display it by adding this at the end of our texture section:

Notice that in the y direction, the texture coordinates are increasing by 0.052631579 = 1/19 to allow for the fact that we need to fit this over 19 separate faces.

We can carry on building the left hand side of the tunnel wall by continuing the pattern we have started and adding this to before our texture section:

Similarly, add texture co-ordinates for our new faces like this:

If we stop and inspect our work at this stage, it is apparent that vertices 6 and 26 (the topmost visible ones) are incorrectly positioned with a gap being evident between the portal and wall. This is a result of inaccurate measurements being made on the original printed image but can easily be corrected by relocating these vertices slightly to the left, changing

To:

These changes remove the gap, so we can now continue by adding the remaining faces of the tunnel wall, using the pattern we have established:

Add the texture co-ordinates for these faces like this:

As the remaining faces are added (note the patterns of the faces and texture coordinates), you will see another slight measurement error has occurred towards the top right hand side of the tunnel. I have left this in my version of the final object but the offending vertices can be repositioned if you are not happy with the result.

In this tutorial, we have started constructing our tunnel entrance by using a photorealistic texture for the portal and constructing a multi-faced wall to fit the profile of the portal. The technique described is equally applicable to bridges and there is no reason why the portal itself could not be used as a bridge face.

In the next tutorial, we will start adding lighting effects and extend the length of the tunnel.

Leave a Reply

Your email address will not be published. Required fields are marked *