HomeTutorials Creating Trees for MSTS

Creating A Tree for MSTS 
Starting From an Existing Tree and Photo

By Phil Voxland


This document gives procedures, hints, and guidelines to create tree texture files from photographs.  It does not explain in detail how to use any of the software tools in the following list.  Much of this has to be learned from experience, trial and error.

Software Tools required:

Assumptions:

Procedure

  1. Copy the shape and texture files for an existing tree into a temporary working folder, then rename the tree's shape and definition files.  "Tree1" is one of the MSTS standard trees which you can use as a source for the shape files  that your new tree will redeploy.  Use a file search to locate the "Tree1" files in on of your existing route folders.
  2. Copy and rename: tree1.s  to newtree.s;  tree1.sd  to newtree.sd; and tree1.ace to newtree.ace.

  3.  
  4. Using a Text Editor, open "newtree.sd" and changing references in the file from  "Tree1.s" to "newtree.s", and change the value of "252" in the Alternative Texture line to "0".  The value of "0" indicates that this tree is a year-round tree, with no seasonal variants.  Initially this is what the file will contain:

  5.  

     

    SIMISA@@@@@@@@@@JINX0t1t______
    shape ( Tree1.s
    ESD_Detail_Level ( 4 )
    ESD_Alternative_Texture ( 252 )
    ESD_Bounding_Box ( -11.1867 0 -9.70905 11.0482 18.12 8.9793 )
    )
     

  6. Using Shape File Manager, uncompress "newtree.s", and then edit that file with Wordpad so that the references to "tree1.ace" is changed to "newtree.ace".  Recompress the edited file "newtree.s".
  7. Using your Graphics Editor, load the picture of the tree which you want to use in MSTS. Ideally the original image should be larger than 512 pixels in both x and y directions. Eventually the image will be fit within an area of 512 by 512 pixels but hold off on resizing down to that size for the moment.

  8. Editing your tree photo takes time, especially to isolate the tree from its background (sky, other trees, buildings). The goal is to have everything but the tree itself set to a uniform black background color. If your graphics editor does not allow you to return to the previous edit state after you have made some editing changes, be sure to save your work from time to time.

    A black background will allow you to see light coloration at the edges of tree branches that need to be edited. A white background makes it hard to spot subtly light edge areas that should definitely not be part of the tree.

Steps to follow include:

      1. Cropping the photo so that it only includes the tree, from its base to the top and from the left to right side;
      2. Using an erasing tool to crudely clear out large areas within the photo that are not part of the tree itself. Be aggressive in erasing orphan branches or leaves that are barely connected, if at all, to the body of the tree and larger branches. They end up being visual clutter;
      3. Using an area/color selection tool ("Magic wand" in Photoshop) to select areas which have a more or less similar color, then clear those areas.  This goes more quickly when the tool is allowed to select areas that are not contiguous;
      4. Using an area tracing tool ("Lasso" in Photoshop)  to surround areas that should be cleared out. It is essential to use this when the tree is near other trees or objects and selecting by would select parts of the tree itself. For example, if there is a blue sky background, select all those pixels that have approximately that color, and clear ("delete") them. Continue with the lighter or darker blue shades that were not selected already;

      5. Hint: Watch the tree itself so that you don't accidentally delete leaves or branches or colors within the trunk.

        Hint: Watch the trunk and major branches or very dark foliage area, if any. These should always be kept "brighter than black". If necessary, do a little painting to keep these areas visible. This is so that in the final steps, transparent holes and gaps do not appear in the tree structure.

        Hint: Skinny trees are an abomination to MSTS; it might be wise to stretch the trunk a little so that it has a solid look when finally displayed.

      6. The default trees for routes in MSTS have a flat, cartoonish look with little contrast, detail, or color variation in a given tree. A digital photo of a real tree is apt to have the opposites: too much contrast, detail and variation. If this remains the trees will appear to shimmer (especially when placed as individual objects and not as forest trees).
      7. To help reduce this, try using editor filters that blur the image, or tools that reduce "dust and scratches". These cause adjacent pixel colors to blend together. Although this seems to loose a great deal of picture quality, it is seldom visible as MSTS executes.
      8. Another technique is to reduce the brightness and contrast of the tree. Indeed, it seems as though a tree texture may appear dark in a photo editor, by the time it makes its way into MSTS it lightens quite a bit.
      9. Even after blurring there may be pixels at the edge of a leaf or branch that are too light, they can be leftovers from where a sky or light background was in the original photo. Using the tool that can pour a selected color into a pixel or group of pixels, replacing those colors with a darker (often MUCH darker) color clears up those spotty areas. The tool to select similar colored pixels can also be used to delete those pixels (setting them to the background color), but that may cause too much shrinkage of the branches and foliage.
      10. This phase will be complete when every area except for the tree itself is a uniform black.

      11. NOW save your image!

      12. The standard tree texture is 512 x 512 pixels, so the next step will be to resize your current image so that it is 512 pixels in height. For "your typical tree", which is taller than wide, your image will be narrower than 512.



      13. A brief side-track: To start, even with a narrow tree, it is simpler to work with the original image height-to-width ratio. Thus a skinny tree will span all the distance from the top to bottom of the image, but will take relatively less of the left to right area of the image. Yet some trees distributed with MSTS use the entire image space, left to right and top to bottom. A tree that is skinny in real life will look squashed in such a texture image.

        Why do they do this? The answers may be that it does store more 'information' about what the tree looks like (colors and shapes) and when the image is used as a FOREST object, it allows for more trees to appear within a given forest object's rectangular space).

        Why is that? Because it appears that what controls the spacing of forest tree objects is the width value that is given in the FOREST.DAT file. So a forest tree texture is reshaped from the 512 x 512 image into a tree that is of a given number of meters wide and tall. Imagine a tree which us 10 meters wide by 20 meters tall in nature. If your 512 x 512 image shows the tree twice as tall as it is wide, to get the right look in a forest, you would have to specify in your FOREST.DAT file that the width of the tree is 20 meters, and so is its height. As a result, when you try to pack more of these trees into a given area, the "tree planter" will only allocate as many as it's method will fit using the 20 meter tree diameter.

        HOWEVER, if your tree image texture uses the entire width and height of the 512 x 512 area AND your FOREST.DAT file states that for that tree the prototypical diameter is 10 meters with a height of 20 meters, then the texture will be stretched, with all the pixel information used to depict the tree in it's proper natural shape.

        BUT, this also implies that for the same tree texture to be used as a single "vegetation" object ... for trees planted one by one ... then the tree shape file has to account for the ratio of width to height in the texture image. Fortunately, the Shape File Manager tool allows selective scaling of x,y, and z axes of an tree. So you can later on make a tree larger or smaller, and you can make it thinner or fatter as you please.

        I mention this now because if you get deeper into the forest for the trees, you may want more control over their spacing.


      14. So, now resize your image so that it is 512 pixels tall, and save the resulting image, this time as .TGA file "working.tga". (TGA files are much larger usually than .JPG files, but they have advantages for maintaining information from one editing session to another, as well as saving information about image transparency).
      15. Chances are good that your image, while it is 512 pixels tall is narrower due to cropping of the image which was earlier recommended.
      16. Yet another way to reduce the shimmering of individually placed trees (or for that matter, any scenery object) requires another editing of the "newtree.s' file. This edit causes trees seen at a distance to appear with less detail, in the same way that trees which are placed as a forest object are also displayed with less detail. Whether this is necessary depends on your the range of contrast and color detail in your original picture, and the filtering and blurring already completed.
      17. Using Shape File Manager, uncompress "newtree.s". Edit the file with Wordpad, searching until you find a section similar to this:

      18. textures ( 1
        texture ( 0 0 -3 ff000000 )

        Change the value of -3 to 0, save the file, and let Shape File Manager compress "newtree.s."
         

      19. Using Tgatool2, load the file "Newtree.ace", which initially will show the image of an existing MSTS tree. A smaller window will open on the right which will show a silhouette of the "alpha channel" for the tree.

      20.  
      21. Select the Image menu option to send the main image to the graphics editor.
      Now you are back in the Graphics Editor!
       
      1. The intial MSTS tree now appears in a 512 x 512 area. This tree is no longer interesting for us, so select all the image, and then clear (or delete it). Ideally, the background remains, and is a uniform black. If not, make it so.
      2. Staying within the graphics editing program, open the "working.tga" file saved in the previous step. Select the entire image, and copy the image into the clipboard.
      3. Return to the original tree window, which should still be uniformly black, and paste the image you just copied onto the clipboard into the original window.
      4. IMPORTANT. This isn't just a hint; it's the difference between a good tree and a hopeless tree. The base of the trunk of our prototypically straight tree must be centered on the center of the 512 pixel wide axis. If it isn't the tree will look like it is split depending on the angle from which it is viewed in MSTS. So, if necessary, select the tree and move it left or right until the center of the trunk is lined up with pixel 256. The base of the trunk should also be within a pixel or two of the bottom of the image. If it isn’t that close, the tree may appear to be ‘floating’ above the terrain when first put in position by the route editor.
      5. Verify that, except for the tree itself, there is a uniform black color to every other area in the image. If not, make it so.
      6. Using the color selection tool, select all non-contiguous area which have the uniform black color. This should also select areas between and surrounded by branches which should end up being transparent. The tree itself will not be selected. Copy the selection to the clipboard.
      7. Save the file (allowing the editor to use the name which it used when it launched the tree image to the graphics editor)
      8. Return to the Tgatool2 window, but do not close the graphics editor window.

      9.  
    1. Select the Tgatool2 image menu item to reload the image after editing. This should cause the old tree image to be replaced by the new tree.
    2. Save the file in Tgatool2 as a targa image file "newtree.tga"
    3. Select the Tgatool2 menu item to send the alpha channel image to the graphics editor. The Alpha channel controls what part of the tree texture file is transparent, and what part is the tree.

    4.  

       
       
       
       
       

      Now you are back in the Graphics Editor!
       

      1. The silhouette of the old tree should appear in the 512 x 512 area. This tree is again no longer interesting for us, so select the entire image, and then clear (or delete it). Ideally, the background remains, and is a uniform white. If not, make it so.
      2. Paste the image from the clipboard which you saved in the previous step. This silhouetted image should be pure white and pure black only, anything else and something needs fixing! Any black part of the image will be transparent in MSTS, so the tree itself should be white.
      3. Look carefully at the trunk and major branches, to see if there are areas which should not be transparent. Minor specks here and there can be erased (to become white). If there are major oddities, retrace your steps to see where they can be repaired.
      4. Save the file (allowing the editor to use the name which it used when it launched the tree image to the graphics editor)
      5. Return to the Tgatool2 window, but do not close the graphics editor window.

      6.  
    5. Select the Tgatool2 menu item to reload the alpha channel image after editing. The new silhouette should appear in the alpha channel window.
    6. Save the file in Tgatool2 as "newtree.tga", do not close Tgatool2.

    7.  
  1. Using MakeAceWin, the 512 x 512 tree image can be transformed into an .ACE texture file. Start up MakeAceWin and:

  2.  
    1. Secify as the input file the file "newtree.tga"; specify as the output file "newtree.ace".
    2. Select as options that the Alpha texture is a one-bit transparency mask; and that DXT compression should be used to create the ACE file.
    3. Press the convert button, and hope for the sun to shine on the new tree.

    4.  

       
       
       
       
       
       
       

  3. Make sure that "newtree.ace" is written to or copied to your route's TEXTURE folder.

  4. Make sure that "newtree.s" and "newtree.sd" are in your route's SHAPES folder.
     
     
  5. In order to use the "newtree" as an object in a route, the route's .REF file must be edited with a UNICODE editor to make the tree available to the Route editor.

  6.  

     
     
     
     
     

    After backing up "myroute.ref" (where "myroute" is the name of your route), use a Text Editor to insert the following into "myroute.ref" :

    Static (
      FileName ( newtree.s )
      Shadow ( ROUND )
      Class ( "Vegetation" )
      Align ( None )
      Description ( Newtree )
    )
     

  7. In order to use the "newtree" in a forest, the route's "FOREST.DAT" file must be edited with  to make the tree available as one of the track objects.

  8.  

     
     
     
     
     

    After backing up "FOREST.DAT" for your route use a Text Editor to insert one line similar to the following:

    Forest ( "Newtree" "Newtree.ace" 10.0f 20.0f 0.8f 1.2f )

    The "FOREST.DAT" file includes an integer number in the second line which sets how many lines of forest items are in the file. Increase it by one for each forest object you are adding.

    In this example:

    10.0f is the width of the prototype tree in meters
    20.0f is the height of the prototype tree in meters
    0.8f is the minimum size multiplier of these trees in the forest
    1.2f is the maximum size multiplier of these trees in the forest

    Trees are created in the forest with a height and width ranging from:

    8.0 meters to 12 meters wide and 16.0 to 24.0 meters high.
     

  9. Congratulations, after all these steps are completed, the Route Editor be started and "Newtree" may be placed either as single tree or as multiple trees in a rectangular forest area.

  10.  
  11. After finishing with the Route Editor, give your world a spin and see how you have improved on nature.

  12. If you decide that trees planted as vegetation objects are not the right size (too big or too small) then you can use the Shape File Manager to rescale information contained in the "newtree.s" file.  Trees which are placed as Forest objects can be made larger or smaller by editing the information in the "FOREST.DAT" file to give them more or less height and width, or more or less range in size.

    When the tree is finished, close the  program files (Tgatool2, MakeAceWin, and your Graphics Editor). I  recommend saving the original image, the modified image with the extraneous information removed, the file "newtree.tga", and, of course, "newtree.ace".


26 Nov 2002