Jump to content

Trainz/Creating Normal Maps with Blender

From Wikibooks, open books for an open world
logo
Trainz Content Creation—Intermediate to Advanced Topics
TOC | BeginningsFun | AM&C | Creation | InBook Refs ORP Refs:  • Index • Containers • Kinds • Tags | Appendixes  • Vers
 Glossary
 HKeys-CM
 HKeys-DVR
 HKeys-SUR
 HKeys-WIN
 Mouse use
 Notations

Creating Normal Maps with Blender 2.5 for Trainz Assets

[edit | edit source]
Editor's note: Various Blender installs can be hosted on the same computer, and legacy version downloads are available from the Blender web site. New content creators are advised to use the version that is the source of the tutorial then repeat the same subject material in the preferred Blender version.



Acknowledgments

[edit | edit source]

This tutorial was inspired by a number of discussions on the Trainz Content Creation Forum and the author's interest in creating normal maps for use in Trainz. Paul Hobbs discusses normal mapping in his excellent Blender tutorials[1] that can be found on his website. Those tutorials are written for an earlier version of Blender and the Blender 2.5 interface is rather different.

There are several You Tube videos on normal mapping in Blender but the following are recommended viewing:

  • [blender 2.5 normal map tutorial (HY6-RtGwfLo)] - by Blender Nerd
  • [Blender Normal Map Tutorial (mU-cSUSR0Vs)] - by d123s404

Introduction

[edit | edit source]

This tutorial demonstrates how to simulate rivets on a flat plate using a material created from a normal map texture and a simple diffuse (coloured) texture. The material is then applied to the sides of a simple cube that is used as a scenery asset in Trainz.

There are some actions in the steps below that may differ from your normal approach to content creation in Trainz. That's OK. Just use whatever method suits you. The tutorial method of copying asset files from a working folder into a Trainz editing folder is only for simplicity. The author uses Andi06's AssetX[note 1] program[2] to manage that process.

The tutorial uses layers in Blender to move objects out of the way temporarily. The numbering of these layers is contained in the Blender Manual[3]. Basically the 10 layer boxes on the top row are numbered 1 to 10 and the bottom row from 11 to 20.

Some actions in the tutorial require you to be in Object Mode or Edit Mode. To ensure you are in the correct mode, the tutorial will remind you of the correct mode.

Assumptions and Prerequisite Knowledge

[edit | edit source]
  • Experience with creating objects in Blender and use of the Blender exporter for Trainz.
  • Experience with creating assets in Trainz.

Before You Start

[edit | edit source]

You will need a rivet mesh for this exercise. For Trainz purposes a rivet can simply be a half sphere and the easiest way to get a suitable rivet is to download the Bits Box (Cab Controls) from Paul Hobbs’ site. There is a rivet.blend file in the collection that is suitable. Place a copy of rivet.blend in a known location.

Purpose

[edit | edit source]

To demonstrate how to create a normal mapped object in Blender using the Blender Bake option. The object is exported from Blender and imported into Trainz as a new scenery asset.

Programs and Items Used

[edit | edit source]

Essential

[edit | edit source]
  • Blender 2.5 (2.57.x or 2.58.0)
  • Blender Trainz Exporter (0.96 version)
  • Trainz Simulator 12 (build 47059) (TS9 and TS10 should also work but have not been tested by the author)
  • A colour texture file in uncompressed TGA format. Just a black, red or blue file will suffice. It must comply with the standard for texture files for Trainz.

Desirable

[edit | edit source]


Expected Result

[edit | edit source]

At the completion of this tutorial you should have the following asset in Trainz.

Blender normal mapped cube in Trainz
Blender normal mapped cube in Trainz


Method

[edit | edit source]

Step 1 – Create Trainz asset

[edit | edit source]
  • Open Trainz Content Manager and create a new scenery asset. Change the asset name to “Normal Test”. Keep a note of the KUID number and save the asset. You can ignore the errors since we do not yet have a mesh. Exit Content Creator Plus.
  • Commit the asset, ignore the errors and open it for edit again. This will update the asset name and ensure the asset is correctly named in the editing folder.


Step 2 – Create Blender environment

[edit | edit source]
  • In your Blender user area create a new folder and call it “Normal Test”.
  • Copy the config.txt from the “…\Auran\...\UserData\Editing\Normal Test” folder into your new Blender folder. We will edit the config.txt later.


Step 3 – Create low and high poly meshes

[edit | edit source]

Create the basic meshes

[edit | edit source]
  • Start Blender and save the default project as Normal_Test.blend in your Blender Normal_Test folder.
Object Mode
  • The normal cube is a bit big so scale it to 0.5 in all axes or just resize the X,Y and Z dimensions to 1.
  • Change the Z location value to bring the bottom of the cube to the level of the grid floor.
  • Apply scale and location to the cube (Ctrl A).
  • Move the cube to layer 6. We will use it later.
  • Position the 3D cursor at zero (0,0,0) (Shift C).
  • Add a new plane mesh and call it “lo poly”.
  • Change to top view using the 7 numpad key.
  • Resize using the dimensions values or scale the plane to a one Blender unit square.
  • Apply the scale. This is also required if you resized the plane using dimension values.
  • In the Properties Editor, select the Object Data icon (the triangle), open the Normals twisty and deselect Double Sided. This isn’t strictly necessary but the exporter will warn about it.
  • In the 3D Editor select the lo poly mesh and create a duplicate with Shift D. Press escape to avoid moving the new mesh.
  • Rename the duplicate mesh from “lo poly.001” to “hi poly”.
  • Move the hi poly mesh to layer 1 and then select layer 1 so we can work on the hi poly mesh.
  • Save the Blender file.

The Resized Cube
The Resized Cube

Modify the hi poly mesh

[edit | edit source]
Object Mode
  • Import the rivet mesh into your working Blender file. In detail:
  • File->Append
  • Select the rivet.blend file
  • Object->Rivet
  • Link/Append from Library
  • The append command places the rivet at location 0,0,0 but it will need to be rotated minus 90 degrees on the Y axis.
  • Select the rivet and change the Y Rotation value to -90.
  • Then press Ctrl A and then Apply Rotation to set this placement as the standard orientation.
  • The imported rivet is 0.02 Blender units which is roughly ¾ inch. You could rescale the rivet to about 0.025 which is roughly 1 inch. This might make the rivet more visible in Trainz. Experiment with different sizes to find a rivet size that suits you. The dimension values for a one inch rivet are X = 0.025, Y = 0.25 and Z = 0.0125.

Rivet resized to one inch
Rivet resized to one inch


  • Move the rivet to the top left corner of the plate and use it to create additional rivets in any pattern you prefer. You can duplicate the rivet by selecting the rivet, followed by Shift D then either X or Y. The X or Y allows you to move the duplicated rivet along either of those axes. Once you have 2 or 3 rivets just select all of them and duplicate as required.


Lots of rivets!
Lots of rivets!


  • When you have created all the required rivets, select them, but not the plane, and form a single mesh using Ctrl J.

Warning! You also need to join the rivets mesh with the hi poly mesh but, if you select the hi poly mesh last, all the rivets will be flattened. This is probably because the hi poly mesh is a simple plane.

  • Select the hi poly mesh first and then the rivets mesh and join using Ctrl J. Check the join is OK by looking at a side view (numpad 3). The rivets should be visible above the plane.
  • Change back to top down view.
  • The mesh name will have changed so rename the mesh back to “hi poly”.
  • Save the Blender file.

We are now ready to create the material and normal texture.

Step 4 – Create material and normal texture

[edit | edit source]
Object Mode
  • Change to layer 1 and select the lo poly mesh.
  • Open the UV/Image Editor in another panel. Create one if you do not have one visible. Create a new image called “rivets_normal” (Image->New Image) using a 512 * 512 size. Leave alpha checked and check 32 bit float.
  • Select the lo poly mesh and select the material icon in the Properties Editor.
Material Settings
  • Create a new material called “rivets.m.tbumptex”.
  • Change the Specular settings to Blinn shader and intensity 0.2.
  • Change the Shading->Emit to 0.5.
  • Leave other settings unchanged.
  • Note: These settings gave a reasonable result in Trainz. This is one area you could experiment with different settings to improve your result.
  • In the Properties Editor select the textures icon.
Normal Texture Settings
  • Create a new texture called “normal” using the Image or Movie type.
  • In the Image twisty, select the leftmost button (Browse image to be linked) and select rivets_normal from the list.
  • Note: This uses the “generated” image within Blender. This may need to be changed to an external file once the final normal map has been created.
  • In Image Sampling select Normal map and leave other settings unchanged.
  • In Mapping change the Coordinates setting to UV.
  • In Influence deselect Diffuse->Color and select Geometry->Normal.
  • Save the Blender file.

We are now ready to commence the baking process.

Step 5 – Bake normal map

[edit | edit source]
Object Mode
  • Go to layer 2 and move the hi poly mesh to layer 1.
  • Move to Layer 1 and select the lo poly mesh.
  • Move to Edit Mode (tab) and ensure you have Face Select Mode selected.
Edit Mode
  • Unwrap the mesh (U->Unwrap) and the mesh will be projected onto the rivets_normal image. As there is only one face on the lo poly mesh it just fills the image.
  • Return to Object Mode.
Object Mode
  • Ensure you are in Blender Render mode. This mode is displayed in the Blender Information panel – usually at the top of the main Blender window.
  • Select the Render icon (the camera) in the Properties Editor.
  • Close off all the sub window “twisties” and open up the Bake sub window.
  • The settings for the Bake window are:
  • Bake Mode -> Normals
  • Bake from multires -> unchecked
  • Normal Space -> Tangent
  • Clear -> checked
  • Selected to Active -> checked
  • Margin -> 2
  • Distance -> 0
  • Split -> Automatic
  • Bias -> 0.08 (see note 2)
  • Select the hi poly mesh and then Shift select the lo poly mesh. Ensure that the lo poly mesh is the active mesh as we will be baking from the selected mesh to the active mesh.


Ready to bake
Ready to bake


  • Select the Bake option and you should see the rivets_normal image converted to a normal map.


After baking
After baking


  • Go to the UV/Image Editor window and save the normal map image (save as image) as a raw Targa file with the name rivets_normal.tga. The "raw Targa" file type can be selected from the file types in the Save as Image twisty on the left hand side of the window. Check the save location as Blender tends to try and save the file in the root directory of your C: drive.
  • Move the hi poly mesh to layer 2. This is done so the mesh is not included in the exported IM file for Trainz.
  • Select the lo poly mesh. Note we cannot see the rivets on the object yet.
  • In the Properties Editor, select the normal texture and reload the rivets_normal file from disk. See Note 1.

Note 1: If you have packed the image into Blender the reload option will be unavailable. If this has occurred you will need to unlock the data block. But if you followed the instructions above this will not be necessary.

Note 2: The default Bias value is zero which, if unchanged may result in a splatter effect of bumps. This was the value chosen by video tutorials that the author observed. You can experiment with different values to see which gives the best effect. The result probably depends on the type of bumps and depressions being modelled.

Step 6 – Create diffuse material

[edit | edit source]
  • Select the lo poly mesh in the 3D Editor.
  • In the Properties Editor select the textures icon.
  • Create a new texture called “diffuse” using the Image or Movie type. Load your simple one colour texture file. This example uses the black.tga file common to many models.
  • Change the Mapping->Coordinates to UV.
  • The Influence->Color should be checked which is the default.

At this point you could just export the lo poly mesh to Trainz but it would appear as a plane. A more interesting object is a normal mapped cube so we will use the cube for our export.

Step 7 – Create riveted box

[edit | edit source]
Object Mode
  • Move to layer 6 or the layer containing the cube.
  • Select the cube and then go to the Properties Editor and choose the Material icon. If there is an existing material then remove it.
  • Apply the rivets.m.tbumptex material to the cube.
  • Change to edit mode.
Edit Mode
  • Select all faces of the cube and unwrap the cube to map against the rivets_normal image.
  • If necessary, move and resize each cube face to take up the entire rivets_normal image.
  • Change to object mode.


Step 8 – Export model

[edit | edit source]
Object Mode
  • Save the Blender file.
  • Export using the Blender Trainz exporter. You don’t need to change any of the exporter settings but make sure it is exporting into your Normal_Test folder.

Assuming you have no errors, you are now ready to set up for importing into Trainz.

Step 9 – Create or modify the config.txt file

[edit | edit source]
  • Open the config.txt file within the normal_test folder using your preferred editor. Add or change the file to reflect the sample config.txt below. Remember not to remove or change the first line of the file.

kuid                  {your kuid number}
username              "Normal Test"
kind                  "scenery"
trainz-build          3.4  (or whatever was provided by your content manager)
mesh-table            {
                       default {
                                auto-create    1
                                mesh           "normal_test.im"
                               }
                      }
category-class        "XVG"
thumbnails            { 
                       0 {
                          image         "$screenshot$.jpg"
                          width         240
                          height        180
                         }
                      }



Note: It is assumed you have a suitable thumbnail image. You could delete or omit that section but TS12 will complain. PEV’s AssetX program has a thumbnail generation facility.

Step 10 – Asset file check

[edit | edit source]

We now need to import the asset files into Trainz Content Manager. There are several ways of doing this but for the purpose of this tutorial we will just copy the files using Windows copy.

  • Ensure the asset is “Open for Edit” in Content Manager. Open a window to folder …\Auran\TSxx\UserData\editing\Normal Test.
  • Open the development folder where the Blender files are located.
  • The following files are to be copied (not moved) from the development folder to the Trainz editing folder.
  • Config.txt
  • Normal_test.im
  • Rivets_normal.tga
  • Rivets_normal.texture.txt
  • Black.tga (this was my diffuse colour file – substitute whatever file you used)
  • Black.texture.txt


The following pictures show my source folder, with files to be copied highlighted, and the destination folder.

Source file folder
Source file folder
Trainz editing folder with asset files
Trainz editing folder with asset files


After copying the files, move to Trainz Content Manager, select the Normal Test asset and commit. If you have errors check you have all the files and that tga files are not compressed.

Step 11 – Display in Trainz

[edit | edit source]

Launch Trainz from Content Manager (Ctrl L), find a suitable test route and session and add the “Normal Test” scenery object to your session. The lighting affects the display of the normal map texture and seems to work best on horizontal surfaces. In some lights the rivets are difficult to see. Below is how the asset looks in the author’s Trainz session (TS12). You may need to experiment with different colours and settings to get the effect that works best for you. Since the rivets are rather small, the effect is subtle and, in some lighting conditions, almost invisible.

Blender normal mapped cube in Trainz
Blender normal mapped cube in Trainz




This final picture shows the normal image in the UV/Image Editor, the textured cube in the 3D Editor and part of the attributes for the normal material in the Properties->Texture Editor. Note that the GLSL option is selected in the Shading panel in the 3D Editor Properties panel. This is only done for taking this picture so both textures are visible on the model.

Normal map and GLSL view of cube
Normal map and GLSL view of cube



Notes and footnotes

[edit | edit source]

Other Reading

[edit | edit source]

The official Blender website at http://www.blender.org
Van Gumster, Jason (2011). Blender For Dummies 2nd Ed. Indianapolis, Indiana: Wiley Publishing, Inc. SBN 978-0470-58446-0.
WiKiBooks also has a Blender specific collection at Blender 3D including the "Blender: Noob to Pro" at Blender 3D: Noob to Pro that has sections on bump and normal mapping.

Notes

[edit | edit source]
  • All technical and many HowTo references are normally sourced
  1. from the TrainzOnline wiki,
  2. it's template forms an external link to an N3V Wiki HELP namespace page given only the page title.
  • It add NS and HowTo parameters to link to Help namespace like:

http://online.ts2009.com/mediaWiki/index.php/Help:Surveyor_Tools  

internal coding
<span class="plainlinks">[http://online.ts2009.com/mediaWiki/index.php/HowTo/{{{1|{{{URL|{{{url|}}}}}}}}} {{{p|{{{2|{{#replace:|{{{1|{{{URL|{{{url|}}}}}}}}}|_| }}}}}}}}]</span>

A close read of the shows the linking string given as {{{1}}} or URL= or url= is the subpage address after the TrainzWiki Help TOC-page listing N3V help articles.

  • Like most every Trainz template it may be given the pretty-text parameter '|p= some string which forms a priority output, otherwise, the template is designed to replace underscores in a url with spaces and display the page title, just as if it were a local page link on any Wikimedia based Wiki project.
  • It is also designed for placeholder parameter {{{2}}} to support the more convenient pipe-separated call normally seen in wikimarkup language:
{{HT|some_underscored_url_pagename |Some pretty name'}}'''

For this template, since the subpage names AND the Trainz Wiki divisions are named for topic clarity, the shorter form using the page name is likely to be what is desired:

{{HT|some_underscored_url_pagename}}


</noinclude>HowTo pages

  1. or the various Content Creator's Guides (0nline or in Trainz releases of yore).
  2. Many Trainz data model asset references are augmented here on the Wikibook under the reference link in the page title bars.

 

  1. AssetX has built-in Windows Help files, but can still be difficult to master if one is unfamiliar with Trainz behaviors and the evolutionary changes in the Trainz data model over the years. See also the forum thread: [AssetX] for more information.

 

References

[edit | edit source]

 

  1. Hobbs, Paul. "Part 2 Mapping and Texturing". A Blender Tutorial - Building a Simple Loco. Retrieved 30 July 2011.
  2. AssetX, Andi06, retrieved 2015-0803 {{citation}}: Check date values in: |accessdate= (help); Text "web" ignored (help)
  3. "3D interaction, Navigating, Layers", Blender Manual, Blender Foundation, retrieved 30 July 2011 {{citation}}: Text "web" ignored (help)