HowTo/Export from Blender using FBX

From TrainzOnline
< HowTo(Difference between revisions)
Jump to: navigation, search
(Update to Blender 3.2 level . Change of test model to one that uses LOD (mesh-table).)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
<!-- Start -->
 +
This page describes how to export a simple rock model from Blender into the [[FBX file format]] for use in Trainz as a scenery object.  The model uses a [[LOD|Level of Detail]] (LOD) system suitable for scenery objects.<br>
  
==Introduction==
+
Some knowledge of Blender would be useful.
  
This guide provides information for the export of FilmBoX (FBX) files from Blender.  
+
A Blender rock mesh is provided along with three PBR textures suitable for creating a [[M.pbrmetal|PBRMetal]] material.
  
===Versions===
+
[[File:Blender320-FBX-export-rocks.jpg|500px|left]] {{clear}} <!-- Uploaded -->
  
{| class="wikitable"
+
=Asset Creation Workflow=
 +
The basic workflow is:
 +
:#  Create your mesh.
 +
:#  Create a UV map for mapping mesh polygons to a texture.
 +
:#  Create and apply a Trainz material including textures.
 +
:#  Create additional lower polygon meshes to be used as [[Level of Detail]] (LOD) meshes.
 +
:#  Create a config.txt file that identifies your model, its type, a mesh definition, and a description including an image (thumbnail) of the model. 
 +
:#  Export the model to an FBX file.
 +
:#  Add model textures and texture definition files so Trainz knows how to use those textures.
 +
:#  Import the model into Trainz.  During import Trainz will create Trainzmesh mesh file for each FBX file.
 +
<p>The first two steps have been done for you.</p>
  
|-
+
=Project files= <!-- Project file NOT uploaded yet -->
|style="width:100px;"|TANE:||style="width:200px;"|4.5 or later.
+
A project file [[File:Blender320-project.zip|Blender320-project.zip]] is provided in zip format. The file contains:
|-
+
# A Blender named my_rock_blender320_start.blendThis Blender model has two meshes. One very high polygon mesh used only to bake a normal map and a much smaller mesh that will be the first LOD level (LOD 0).
|Blender:|| Known to work for Blender 2.78a or laterThe FBX exporter is a standard addon for Blender.
+
# Three PBR textures and their texture description files:
|-
+
#* rockmat-albedo.png, rockmat-albedo.texture.txt
|FBX format:|| Binary format only (see discussion below). FBX 2011, FBX2012, FBX2013.
+
#* rockmat-parameter.png, rockmat-parameter.texture.txt
|-
+
#* rockmat-normal.png, rockmat-normal.texture.txt
|Special requirements:|| NoneCreators will need their preferred image editors and text editors but there are no special requirements for FBX.
+
# A config.txtYou will need to add your own kuid.
|-
+
# A thumbnail image.
|Other software:||  There are free FBX viewers available on the web including {{plain link|http://www.autodesk.com/products/fbx/fbx-review|FBX Review}} and FBX Converter  programs by Autodesk.
+
# A Blender file named my_rock_blender320_final.blendThis is the end result ready for export.
|}
+
  
===The FBX format===
 
  
A brief discussion on the FBX format history can be found {{plain link|https://en.wikipedia.org/wiki/FBX here}}.   FBX can be exported, or imported, either as an ASCII (i.e. human readable) file or in binary format.
+
=Adding the Material, creating LOD meshes, and Exporting=
 +
==Load Your Model==
 +
:* Create a suitable working folder on your computer.  You might call it "FBX_export_example_1".
 +
:* Unpack the project file [[File:Blender320-project.zip|Blender320-project.zip]] into your working folder. <!-- Project file NOT uploaded yet -->
 +
:* Start Blender, load the start Blender file and then save it as "rock_working.blend".
 +
<br>
 +
[[File:Blender320-FBX-export-start.jpg|1200px|left]] {{clear}} <!-- Uploaded -->
 +
<br>
 +
==What's in the model?==
 +
<p>On opening the Blender file you will be in Layout mode with an untextured rock mesh.  In the Scene Collection panel there are three
 +
Blender collections: "high poly meshes", "Other", and "lod0. <br>
 +
The very high poly mesh version has 1.5 million triangles and is unsuitable for export as a Trainz mesh but it is suitable for baking normal maps for a lower poly mesh.  We will not use it so hide it by unchecking the white box to the right of the high poly meshes collection.
 +
You can also uncheck the Other collection.  That can be useful for hiding lamps and cameras.<br>
 +
The lod0 collection contains the main mesh we will work with so make sure it is checked and visible.  If you look at the bottom right of the screen it should show Tris 6,144.  This count is a bit high for a rock so Level of Detail (LOD) meshes are required.
 +
</p>
 +
<br>
 +
==Task 1 - Create a Trainz material==
 +
:* Make sure the "rock_lod0n" mesh is selected and no others visible.  Change to the Shading mode by clicking on the Shading tab at the top of the screen.
 +
[[File:Blender320-FBX-export-shader-editor.jpg|1200px|left]] {{clear}} <!-- Uploaded -->
 +
<br>
 +
:* In the Properties Editor, which is at the bottom right, create a new material. Click on the material name and change it to "rock.m.pbrmetal".
 +
<table bgcolor=#000000 width=900 cellpadding=2>
 +
<tr valign="top">
 +
<td>
 +
<table bgcolor=#ffffb0 cellpadding=2>
 +
<tr valign="top">
 +
<td>[[image:NotePad.PNG|link=]]</td>
 +
<td>On creating the material a Principled BSDF shader node and a Material Output will be created in the Shader Editor.<br>
 +
Blender uses several different collections of nodes and these are material nodes.  Basically, nodes take some information on the left side and output different information on the right.  The shader node takes in a whole lot of information from basic colour, PBR values, and normals. The output is sent to the Material Output node which is what is displayed on the associated mesh. All of the shader inputs have default values.</td>
 +
</tr>
 +
</table>
 +
</td>
 +
</tr>
 +
</table>
 +
<br>
 +
<p>For a Trainz [[M.pbrmetal|PBRMetal]] material we need to provide an albedo (base colour) texture, a set of parameters textures (emissive, ambient occlusion, roughness and metallicity) combined in one file, and a normals texture.</p><br>
  
==Blender and FBX==
+
:* Within the shader editor press Shift A and create an Image Texture node as shown below.
 +
<br>
 +
[[File:Blender320-FBX-export-create-a-texture-input-node.jpg|1200px|left]]  {{clear}}
 +
<br>
 +
:* Click on the Color output and drag the connection across to the Base Color input of the shader node.  If you connect to the wrong input then disconnect by clicking on the input end of the link which is on the left side. 
 +
:* Back in the Image Texture node use the Open dialog and find the file "rockmat-albedo.png".  The rock will now show the base colours.
 +
:* Create another Image Texture node and connect it to the Roughness input of the shader node. 
 +
:* Load the file "rockmat-param.png" into the node.
 +
:* Change the image texture node Color Space to non-color as the texture doesn't actually contain colour information.
 +
<br>
 +
<table bgcolor=#000000 width=900 cellpadding=2>
 +
<tr valign="top">
 +
<td>
 +
<table bgcolor=#ffffb0 cellpadding=2>
 +
<tr valign="top">
 +
<td>[[image:NotePad.PNG|link=]]</td>
 +
<td>An image texture typically has three channels of red, green and blue (RGB) colour information.  If transparency is used then a fourth channel called alpha is used (RGBA).
 +
Game engines often use these channels to carry information other than colour and this is the case for a Trainz parameters texture.  For more information read [[M.pbrmetal#Parameter|PBRMetal Parameter Texture]].
 +
<br>
 +
Linking the parameters texture to the roughness input is the only way to get Blender to export texture names correctly in an FBX file.  Consequently the model may look slightly different in game.
 +
</td>
 +
</tr>
 +
</table>
 +
</td>
 +
</tr>
 +
</table>
  
Blender is capable of both importing and exporting FBX formatted files. Two formats are available: ASCII FBX 6.1 and binary FBX 7.4 (Blender 2.78).  Since TANE will only accept FBX versions between 7.1 (7100) and 7.5 (7500), the ASCII version cannot be used for TrainzNote that work on the Blender ASCII importer/exporter is frozen.
+
<p>Now we add the normal map but we need an additional node to provide additional information.</p><br>
 +
:* Using Shift A, add a Vector->Normal Map node and connect it to the Normal input of the shader node. <br>
 +
[[File:Blender320-FBX-export-create-a-vector-normal-map-node.jpg|1200px|left]]  {{clear}}
 +
:* Add another Image Texture node, connect it to the Normal Map node and load the "rockmat-normal.png" texture.
 +
:* Your material, in the Shader Editor, should look like the following:
 +
<br>
 +
[[File:Blender320-FBX-export-complete-material.jpg|1200px|left]] {{clear}}
 +
<br>
 +
<p>Now is a good time to save your Blender file.</p>
 +
<br>
  
The Blender exporter does not export all possible object attributes and it is likely that TANE will not recognise all those attributes that are exported.
+
==Task 2 - Create lower poly LOD versions==
The Blender documentation contains {{plain link|https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/Autodesk_FBX list of attributes}} that are exported.   
+
<p>The rock_lod0n mesh is 6144 triangles and needs to be  reduced to less than 300 triangles for the lowest polygon mesh.</p>
 +
<p>In TS19 and later versions, you can dictate the distance at which LOD levels swap out and also the distance the mesh is not rendered at all.  This is independent of any draw distance a user may apply although Trainz will use the lowest draw distance of the two schemes.</p>
 +
<p>Each lower poly mesh must be at least 20% fewer polys than the previous mesh but to get down to 300 polys using just 20%  would take quite a few levels.  So, it is recommended that 20% be applied only for the first LOD change and a more agressive reduction after that.</p>
 +
<br>
 +
<p>In this asset we will aim for levels like this:</p>
 +
<table bgcolor=#00ffff border=2 width=600>
 +
<tr>
 +
<th>LOD Level</th>
 +
<th>Triangles</th>
 +
<th>Distance</th>
 +
</tr>
 +
<tr valign="top">
 +
<td>LOD0</td>
 +
<td>6144</td>
 +
<td>0 to 100 metres</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>LOD1</td>
 +
<td>4900</td>
 +
<td>100 to 300 metres</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>LOD2</td>
 +
<td>1000</td>
 +
<td>300 to 600 metres</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>LOD3</td>
 +
<td>250</td>
 +
<td>600 to 5000 metres</td>
 +
</tr>
 +
<tr valign="top">
 +
<td></td>
 +
<td></td>
 +
<td>No render beyond 5000 metres</td>
 +
</tr>
 +
</table>
 +
<br>
 +
===Creating the LOD1 mesh===
 +
:* If you haven't done so, save now.
 +
:* In the Outliner Editor (top right) select the LOD0 collection.
 +
:* Right click and select Duplicate Selection.  This duplicates both the collection and meshes in the collection.
 +
:* Rename the collection to LOD1 and rename the mesh to rock_lod1n. There is no rename action in the drop down menu but double clicking on the name will allow a change.
 +
:* Hide the LOD0 collection by unchecking the box to the right of the collection name.  This hides the entire collection.
 +
:* In the Properties Editor, select the Modifiers tab which is the spanner icon.  There should be no modifiers listed.
 +
:* Click on Add Modifier and select the Decimate option.
 +
:* The Decimate modifier has basically three options: Collapse, Un-Subdivide, and Planar.  Generally, it is best to use the Collapse option but sometimes you can get a better result with Planar. The poly count is a face count that is most likely the number of quads (4 sided polygon) so the number of triangles would be twice that number.  This isn't always correct and depends on the mesh topology.  It should be close enough for our purposes.
 +
:* For LOD1 we want a maximum of 4900 triangles (2450 faces) so use a Ratio value of 0.54 that gives a result of 2425 faces.  This value may need to be tweaked if the actual value seen by Trainz is higher and therefore breaks the 20% rule.
 +
:* Do not apply the modifier as this is a non destructive setting and may need to be changed.  The modifier will be applied on export.
 +
:* Save your work and we will move onto LOD2.
 +
<br>
 +
===Creating the LOD2 mesh===
 +
:* This time select the LOD1 collection, make a duplicate and rename the collection to LOD2 and the mesh to rock_lod2n.  You could have duplicated LOD0 instead but this way we alrady have a decimate modifier.
 +
:* Hide the LOD0 and LOD1 collections if not already hidden.
 +
:* This time we want to reduce the triangle count to 1000 (face count 500) so a more agressive reduction is required.
 +
:* Try a Ratio value of 0.08 which gives quite a good result for a face count of 473.
 +
:* If you want to compare LOD versions you can show/hide the other LOD collections but make sure you are left working on the correct mesh.
 +
:* Save your work and we will move onto the final LOD - LOD3.
 +
<br>
 +
===Creating the LOD3 mesh===
 +
:* Duplicate the LOD2 collection and rename the collection to LOD3 and the mesh to rock_lod3n.
 +
:* Hide all collections except LOD3.
 +
:* Change the Decimate Ration value to 0.017 that results in 102 faces (204 triangles).  Our rock is now looking a bit pointy in places but remember this will only be shown at 600+ metres.
 +
:* Save your work.
 +
<br>
 +
<!--    -->
 +
<table bgcolor=#000000 width=900 cellpadding=2>
 +
<tr valign="top">
 +
<td>
 +
<table bgcolor=#ffffb0 cellpadding=2>
 +
<tr valign="top">
 +
<td>[[image:NotePad.PNG|link=]]</td>
 +
<td>When creating our mesh names we have been using a convention of "rock_lodxn" where the x character is a LOD level. You can use any names you like within reason but using the "lodxn" will work with N3V's config.txt generator tool.  See [https://contentcreation.trainzsimulator.com/trainz-content-utilities-1-0-2/ Trainz Content Utilities]
 +
</td>
 +
</tr>
 +
</table>
 +
</td>
 +
</tr>
 +
</table>
 +
<br>
 +
<table bgcolor=#000000 width=900 cellpadding=2>
 +
<tr valign="top">
 +
<td>
 +
<table bgcolor=#ffffb0 cellpadding=2>
 +
<tr valign="top">
 +
<td>[[image:NotePad.PNG|link=]]</td>
 +
<td>At this point we have our 4 levels of LOD, LOD0 to LOD3, and that should pass asset validation.  By creating the material after making the original mesh (LOD0) we are able to automatically copy the material from LOD to LOD.  At each stage you should check that the mesh paint is still correct as LOD reduction will change the UV mapping and potentially cause the paint to look wrong.  For a rock this probably doesn't matter but for other models it may not work.
 +
There are other LOD reduction techniques but they are beyond the scope of this tutorial.</td>
 +
</tr>
 +
</table>
 +
</td>
 +
</tr>
 +
</table>
 +
<br>
 +
== Exporting our model==
 +
:* Repeat for each LOD collection
 +
:** Select the next LOD collection and hide all the others.
 +
:** Select the mesh for this LOD - e.g. rock_lod0n.
 +
:** From the top menu select File->Export->FBX.
 +
:** Change the output name, at the bottom of the dialog box, to the name of the mesh - e.g. rock_lod0n.fbx.
 +
:** Change the export settings to the same as this image.
 +
<br>
 +
[[File:Blender320-FBX-export-FBX-export-dialog-box.jpg]]
 +
<br>
 +
<br>
 +
<p>For this export we use:</p>
 +
<table bgcolor=#00ffff border=2 width=600>  <!--Light blue -->
 +
<tr valign="top">
 +
<th>Include</th>
 +
<th>Selected Objects</th>
 +
</tr>
 +
<tr valign="top">
 +
<td>Object Types</td>
 +
<td>Mesh only</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Transform -> Scale</td>
 +
<td>1.00</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Apply Scalings</td>
 +
<td>FBX All</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Forward</td>
 +
<td>Y Forward</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Up</td>
 +
<td>Z Up</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Apply Unit</td>
 +
<td>Ticked</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Use Space Transform</td>
 +
<td>Ticked</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Geometry-> Apply Modifiers</td>
 +
<td>Ticked</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Triangulate Faces</td>
 +
<td>Ticked</td>
 +
</tr>
 +
</table>
 +
<br>
 +
<p>You can ignore the animation settings (armature and Bake Animation).</p>
 +
<br>           
 +
:* Click on the Export FBX button at the top right. The mesh will be exported.  
 +
<br>
 +
<table bgcolor=#000000 width=450 cellpadding=2>
 +
<tr valign="top">
 +
<td>
 +
<table bgcolor=#ffffb0 width=450 cellpadding=2>    <!--yellow -->
 +
<tr valign="top">
 +
<td>[[image:NotePad.PNG|link=]]</td>
 +
<td>The settings shown above will work for Trainz but other settings will also work.</td>
 +
</tr>
 +
</table>
 +
</td>
 +
</tr>
 +
</table>
 +
<br>
 +
<br>
 +
<table bgcolor=#000000 width=900 cellpadding=2>
 +
<tr valign="top">
 +
<td>
 +
<table bgcolor=#00ffff cellpadding=2> <!--Light blue -->
 +
<tr valign="top">
 +
<td>[[image:PencilTips.PNG|link=]]</td>
 +
<td>You can save your preferences for a given export such as "mesh only" or "animation" by clicking on the plus button (+) next to Operator Presets and saving the preset with a name.</td>
 +
</tr>
 +
</table>
 +
</td>
 +
</tr>
 +
</table>
 +
<br>
  
Included in this guide is a list of attributes that have been observed as exported and treatment/acceptance by TANE.  The list is incomplete and will be updated when new information is available.
 
  
N3V use the ASSIMP Open Asset Import Library to extract asset model information from the FBX file.  ASSIMP Version 3.3.1 appears to be FBX version 7.3 and the Blender FBX exporter exports FBX 7.4.  This results in some warnings that appear to be generated by Content Manager but actually come from the ASSIMP process.  If you get warnings that you cannot correct, such as those in the warnings section below, try running the Blender generated FBX file through the Autodesk FBX Converter program and choose FBX2013 as the target. These warnings do not appear to affect the outcome so this step may not be necessary.
+
==Importing into Trainz==
+
===Getting organised===
==TANE and the FBX Importer==
+
:* Create a folder called "export" within your working folderWhile not necessary it is convenient to have all the files Trainz needs to construct the asset.
A discussion of the FBX format and general guidelines for use with TANE is discussed at this Trainz WiKi page:  [[FBX  file format]]
+
<br>
 
+
===FBX conversion to Trainzmesh format===
==Skills Required==
+
<p>While the FBX format is convenient for mesh creation and developing materials and textures, Trainz needs a conversion to a format that can be easily loaded by the game engine.</p>
For this version of the guide, it is assumed the user has some knowledge of the use of Blender and an understanding of the Trainz asset creation process.
+
<p>When you submit your asset into Trainz, Trainz will convert all the FBX files to Trainzmesh files using the same filename but changing the suffixSo a file called "rock_lod0n.fbx" will become "rock_lod0n.trainzmesh".</p>
 
+
<p>This means that your asset configuration in the config.txt file must refer to Trainzmesh files rather than FBX files.</p>
==Exporting a mesh object from Blender in FBX format (no animation)==
+
<br>
 
+
===Config.txt===
The FBX exporter addon must be enabled in User Preferences.
+
<p>For this asset we are creating a kind "scenery" asset and the [[Config.txt file|config.txt]] will use [[Mesh-table LOD|mesh-table LOD]] together with a [[KIND_Mesh#mesh-table-lod-transition-distances|mesh-table-lod-transition-distances]] tag.</p>
 
+
<p>As explained earlier, the mesh-table-lod-transition-distances tag will control the distances at which the meshes changes and when they are no longer rendered.</p>
Select File->Export->Export FBX and the FBX export panel will show in the bottom left hand corner and should look like the following pictureThe panel contents
+
<p>A config.txt is provided in the project files although you will need to provide your own kuidThis is part of the config.txt.</p>
vary significantly between the Binary export version and the ASCII export version so make sure you have Binary selected.
+
<br>
 
+
===The Main Menu===
+
[[File:Blender_FBX_Main_Menu.jpg|380px|left]]
+
* Ignore the Operator Presets for now.
+
* Ensure FBX 7.4 binary version is selected.
+
* The Main/Geometry/Armatures/Animation buttons provide menu options for the item selected.  Select the Main option.
+
* Selected Objects.  This option needs careful consideration.  Unlike the Blender XML exporter, the FBX exporter will export all objects in all layers
+
which is probably undesirable in many cases and particularly if you have different LOD models in different layers.  So, first select those objects within Blender
+
that you want to export and then select Selected Objects in this panel.
+
* Scale.  Leave the Scale value as 1.00 and deselect the small icon to the right of the Scale value. (See note below)
+
* Forward and Up.  Set these to the values :Y forward and Z Up.
+
 
+
The options below are multi select (i.e. you can select more than one).  For the time being just leave Mesh selected.
+
 
+
* Leave the Experimental and Custom Properties as deselected.
+
* Leave Path Mode as Auto and Batch Mode as Off.
+
* Choose the FBX filename and export using the Export FBX in the top right hand corner.  There is no exporter log.
+
{{clear}}
+
 
+
Note that  Blender 2.79 introduced some options for scaling that need some investigation.  Recommend using "FBX All" until this has been investigated.
+
 
+
====Tip====
+
You can save your preferences for a given situation by clicking on the plus button (+) next to Operator Presets and saving the preset with a name.  This is particularly useful for animation.  You will need to reload the preset each time you start Blender.
+
 
+
===The Geometry Menu===
+
 
+
[[File:FBX Geometry Menu.jpg|380px|left]]
+
* Leave these values as shown.
+
{{clear}}
+
 
+
===The Armatures and Animation Menus===
+
 
+
* See the [http://online.ts2009.com/mediaWiki/index.php?title=HowTo/Export_from_Blender_using_FBX&action=submit#Animation Animation Section].
+
{{clear}}
+
 
+
===Config.txt - simple model===
+
 
+
Setting up the CONFIG.TXT
+
 
+
The only changes to the config.txt are in the mesh tableThe mesh entries for FBX files now have a "trainzmesh" extention as per the following example:
+
 
+
  mesh-table {
+
    default {
+
      auto-create                          1
+
      mesh                                  "my-mesh.trainzmesh"
+
    }
+
  }
+
 
+
Note that for the LM.TXT Level of Detail (LOD) you can still use the LM convention but the LM.TXT file must refer to trainzmesh files.
+
 
+
===Files created===
+
 
+
====Mesh files====
+
 
+
The file my-mesh.trainzmesh is created during the asset commit.  Currently the FBX file is not deleted but bundled into the asset.  Since the FBX format is readable by 3D modelling tools, you may want to remove any FBX files from assets uploaded to the DLS or other web sites.
+
 
+
====Texture.txt files====
+
 
+
You can provide your own texture.txt files (advisable) or let the commit process create them for you.  The commit process will create suitable files, such as those required for normal maps, but you can provide your own if you have special requirements.
+
 
+
Warning:  If you get odd effects with your textures, check the associated texture.txt file first.  The FBX importer tends to add an "alpha=" line even though no alpha option has been chosen.  This may be an issue with the Blender FBX exporter.
+
 
+
PEV's TextureTXT utility can be very useful for creating texture.txt files and its worth adding it into AssetX if you use AssetX for managing your projects.
+
 
+
===Double Sided Meshes===
+
It appears that FBX does not support double sided meshes so you need to create a metadata file as described at [[FBX file format#Mesh Metadata Files]].  Note that this is done per material.  i.e. you cannot have the same material for single sided and double sided meshes.
+
 
+
===Self Illuminated Meshes===
+
Meshes that require self illumination require a separate material with the Shader->Emit value set to a value other than 0.  A value of 1.0 is recommended.  The Blender exporter also exports an emissive colour using the diffuse colour value.  It is not known if TANE uses the emissive colour.  You might also experiment with the specular values.
+
 
+
===General warnings and errors===
+
Errors and warnings starting with a T, such as T16128, are errors ouput by the ASSIMP converter and are not output by the Trainz FBX importer.
+
 
+
{|  style="border:1px solid gray;border-collapse:collapse;background:white;font-weight:bold; " cellpadding=5px align=left width=70%
+
|- style="font-weight:bold; text-align:center;"
+
  ! width=40% style=" border:1px solid gray;"|Warning/Error
+
  ! width=60% style=" border:1px solid gray;"|Help/Explanation
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Warning:  T16080: ...shading mode not recognised: Phong
+
  | style="border:1px solid gray;font-weight:normal;"| You can probably ignore this warning.  The warning may go away if you run the FBX file through Autodesk's FBX Converter program to the FBX2013 format.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Warn,  T15808: FBX-DOM (TOK_KEY, offset 0xnnnn) source object for connection does not exist
+
  | style="border:1px solid gray;font-weight:normal;"| You can probably ignore this warning.  The warning may go away if you run the FBX file through Autodesk's FBX Converter program to the FBX2013 format.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Error: Unable to determine vertex format.
+
  | style="border:1px solid gray;font-weight:normal;"|This can be caused by having multiple UV maps for the same mesh.  For example, baking a painted mesh to a bake mesh requires two UV maps.  Remove old maps before exporting.  If you wish to keep those maps, back up the Blender file and then delete the extra maps.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Error, T5268 or T9068, Failed to triangulate polygon (no ear found). Probably not a simple polygon.
+
  | style="border:1px solid gray;font-weight:normal;"|Try triangulating the mesh, or meshes, using Ctrl T (quads to tris).  If the error continues, try using the Triangulate modifier.  This problem is known to occur when using modifiers that may produce ngons on export.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Error, Error, T16128: FindInvalidDataProcess fails on mesh uvcoords: All vectors are identical"
+
  | style="border:1px solid gray;font-weight:normal;"|Probably caused by having multiple UV maps for the same mesh. Not sure of the relationship between this error and the "Unable to determine vertex format" error.
+
|}
+
 
+
===Level of Detail (LOD)===
+
 
+
The rules for [[Level of Detail]] for FBX models are the same as indexed mesh (IM) models except for the use of the Trainzmesh suffix for mesh files.
+
 
+
====Mesh-Table Method====
+
 
+
This is a very simple scenery model of a coloured ball using three levels of LOD:  [[File:6000101_-_FBX_-_LOD_mesh-table_test1.zip]].
+
The Blender source is provided.
+
 
+
====LM.TXT Method====
+
 
+
(TBD)
+
 
+
==Animation==
+
 
+
===Overview===
+
 
+
Trainz will not animate a mesh without the use of helper points using the "b.r" notation.  For Blender, those helper points can be armatures (bones) or empties.  Lattices are not supported by the FBX exporter.
+
 
+
An animation must have a root helper normally called "b.r.main" although "b.r.root" will also work.  Using such names helps identify the overall parent of the animation.
+
Other animation helpers are called "b.r.xxx", where "xxx" can be any name.  These helpers must be children of the main/root helper.
+
 
+
===Exporting an animated mesh object===
+
====The Main Menu====
+
[[File:Blender FBX export main-anim.jpg|380px|left]]
+
* Select Empty and Armature depending on how you set up your animation.
+
* Other options are described above.
+
{{clear}}
+
 
+
====The Armatures Menu====
+
[[File:FBX Armatures Menu.jpg|380px|left]]
+
* Use the values as shown. 
+
{{clear}}
+
 
+
====The Animation Menu====
+
[[File:Blender FBX anim menu1.jpg|380px|left]]
+
* Select Baked Animation and disable the other options.
+
 
+
Authors note:  This is completely different from the process described in the 3DS Max FBX animation export.
+
If Baked Animation is not ticked, then none of the other animation options are available.  So far, none of those other options have been found useful.
+
{{clear}}
+
 
+
===Files created during the export and import process===
+
 
+
The Blender exporter creates a binary file with the name of your choosing plus an FBX suffix.  For animation, the exporter creates an internal name that the TANE importer uses for an animation (KIN) file.
+
 
+
If you choose Baked Animation (recommended), then the animation name is comprised of the FBX name and the word "_scene".  So, if you export a model called "box.fbx" with animation, then the importer creates a "box.trainsmesh" and "box_scene.fbx".
+
 
+
If you don't choose Baked Animation, then the TANE importer uses the name of the animation channel so you might get names like "b.r.main-b.r.mainAction.kin".
+
 
+
===Config.txt - Animation===
+
 
+
The names of mesh and KIN files may not be obvious so you may need to create some dummy names for your mesh and KIN files.  After importing into TANE, open the asset for editing and look for the files createdThen go back and correct entries in the config.txt.
+
 
+
Sample mesh-table entry with animation:
+
  
 +
kind                                      "scenery"
 +
kuid                                      Note: supply your own kuid here
 +
trainz-build                              "4.6"
 +
category-class                            "HM"
 +
category-region                          "00"
 +
category-era                              "2010s;2020s"
 
  mesh-table {
 
  mesh-table {
  default {
+
  lod0n {
    auto-create                          1
+
    mesh                                  "rock_lod0n.trainzmesh"
    mesh                                  "box.trainzmesh"
+
    auto-create                          1
    anim                                  "box_scene.kin"
+
    lod-level                            0
    animation-loop-speed                  1.00
+
    mesh-season                          0
  }
+
  }
 
+
  lod1n {
 
+
    mesh                                  "rock_lod1n.trainzmesh"
===Animation warnings and errors===
+
    auto-create                          1
 
+
    lod-level                            1
{|  style="border:1px solid gray;border-collapse:collapse;background:white;font-weight:bold; " cellpadding=5px align=left width=70%
+
    mesh-season                          0
|- style="font-weight:bold; text-align:center;"
+
  }
  ! width=40% style=" border:1px solid gray;"|Warning/Error
+
  lod2n {
  ! width=60% style=" border:1px solid gray;"|Help/Explanation
+
    mesh                                 "rock_lod2n.trainzmesh"
|-
+
    auto-create                          1
  | style="border:1px solid gray;font-weight:normal;"|! ...  T14120: Simplified dummy tracks with just one key.
+
    lod-level                            2
  | style="border:1px solid gray;font-weight:normal;"| Not sure what this warning is about but the animation is OK.
+
    mesh-season                          0
|-
+
  }
  | style="border:1px solid gray;font-weight:normal;"|! ... Skipping one or more lines with the same contents
+
  lod3n {
  | style="border:1px solid gray;font-weight:normal;"|This is an ASSIMP message and can be ignored.
+
    mesh                                  "rock_lod3n.trainzmesh"
|}
+
    auto-create                          1
 
+
    lod-level                            3
===Sample animations===
+
    mesh-season                          0
 
+
  }
The following samples are provided to demonstrate different types of Blender FBX animations.  You are free to use them for any purpose - i.e. no copyright!
+
}
 
+
mesh-table-lod-transition-distances      100,300,600,5000
====Simple Animation 1 - Uses an empty as animated parent====
+
<br>
 
+
<p>The trainz-build should be 4.6 or above.</p>
[[File:890045 fbx anim1 - empty.zip]]
+
<p>The mesh table identifies the four meshes used in the asset plus the LOD level.</p>
 
+
<p>The mesh-table-lod-transition-distances identifies the distance at which the mesh changes to the next lower polygon meshYou can change these if you want to experiment.</p>
This animation rotates a coloured cube around the X axis using an empty as parent b.r.main.  The animation action, within Blender, is called b.r.mainAction.  The channel has been set to linear interpolation.
+
<br>
 
+
===Texture.txt files===
When exporting, you must select Empty and Mesh.
+
<p>You can provide your own texture.txt files (advisable) or let the commit process create them for you.</p>
 
+
<br>
Exported names:  The Blender FBX exporter creates a file called box.fbx.  On commit, TANE creates a mesh file called box.trainzmesh and an animation file called box_scene.kin. 
+
===Committing the asset===
 
+
:* Commit the asset by dragging the folder onto CMAssuming the commit is error free, open the asset for edit in explorer and see what Trainz has created.
====Simple Animation 2 - Uses an armature as animated parent====
+
<br>
 
+
<p>You will get a warning like "...shading node not recognized:Phong"Trainz doesn't use the exported shader anyway so you can ignore the warning.</p>
[[File:890044 fbx anim1 - armatures.zip]]
+
<p>The trainzmesh files should be as described above. The FBX files will also be present so you may want to delete those if you are ready to upload your asset to the DLS or elsewhereIf you delete the FBX files, then you will need to commit the asset againSince the trainzmesh files already exist no FBX conversion is carried out.</p>
 
+
<br>
This animation rotates a coloured cube around the X axis using an armature with a single bone as parent b.r.main.  The animation rotates anti-clockwise.
+
=About the boulder asset=
 
+
<p>The material used for this asset was created within Substance Painter which is a powerful PBR material and texture creation tool.</p>
This is much the same as Sample 1 but demonstrates that you can use either an empty or an armature for simple animations.
+
<p>You can make your own PBR textures within Blender but that is beyond the scope of this tutorialThere are several payware Blender addons that can create quite good textures,  One worth looking at is PBR Painter and the Trainz user Cayden has been promoting that for Trainz useSearch for the PBR Painter thread on the Trainz forums.</p>
 
+
<br>
When exporting, you must select Armature and Mesh.
+
=Animation=
 
+
<p>If you are interested in animation for Blender, see [[HowTo/Export Blender FBX Animation|How to export Blender FBX animation]].</p>
Exported names:  The Blender FBX exporter creates a file called box.fbx.  On commit, TANE creates a mesh file called box.trainzmesh and an animation file called box_scene.kin. 
+
 
+
====Simple Animation 3 - Four animated cogs - LOD model====
+
 
+
[[File:4000110 - FBX - anim test 4 - four cogs.zip]]
+
 
+
This animation simulates four rotating cogs.  There are two LOD levels.  LOD0 (the high poly version) is in layer 1 and LOD1 (the low poly version) is in layer 2. Layer 11 contains the animated armatures.  There are four animation tracks.
+
 
+
To export LOD0, select all the objects in layers 1 and 11 so the LOD0 meshes and the armatures are all selected.  On export, ensure Empty, Armature and Mesh are selected and use the name "4cogs-lod0.fbx".  b.r.main is an empty so Empty must be selected.
+
 
+
To export LOD1, select all the objects in layers 2 and 11 so the LOD1 meshes and the armatures are all selected.  On export, ensure Empty, Armature and Mesh are selected and use the name "4cogs-lod1.fbx".
+
 
+
You can choose any names you want but a meaningful name is useful.
+
 
+
This is the relevant section of config.txt:
+
 
+
mesh-table {
+
  gears-lod0 {
+
    auto-create                          1
+
    mesh                                  "4cogs-lod0.trainzmesh"
+
    lod-level                            0
+
    anim                                  "4cogs-lod0_scene.kin"
+
    animation-loop-speed                  1.00
+
  }
+
  gears-lod1 {
+
    auto-create                          1
+
    mesh                                  "4cogs-lod1.trainzmesh"
+
    lod-level                            1
+
    anim                                  "4cogs-lod1_scene.kin"
+
    animation-loop-speed                  1.00
+
  }
+
}
+
mesh-detail-level-count                  2
+
 
+
Note that the transition from LOD0 to LOD1 is obvious.
+
 
+
====More complex animations====
+
 
+
=====A Sample Steam Piston Animation=====
+
[[File:Bsa.zip]]
+
 
+
[[File:Circle_guided_steam_animation.jpg|380px]]
+
 
+
This example shows how to animate a steam piston and crankshaft using a circle to guide the location of the piston shaft.  This is a variation of Torsten's sample for the XML exporter.  General instructions for export are contained in the Blender file as a text object.
+
 
+
==Legacy Materials==
+
 
+
This section identifies the legacy material options used by the FBX exporter (i.e. prior to the introduction of [[TRS19]]).  For detailed descriptions on how Trainz uses material types, including TRS19 PBR materials, see [[Material Types]] and the child pages detailing different Trainz material types.
+
 
+
The exporter treats material options based on the chosen material shader model.  Even though Trainz uses its own shaders, it may be worthwhile selecting different shader models in Blender to see the effect.  In particular, choosing the Phong model for the specular shader will enable the export of a number of extra material options. These may, or may not, actually result in observable changes in Trainz.
+
 
+
The FBX exporter uses the following material options:
+
 
+
{|  style="border:1px solid gray;border-collapse:collapse;background:white;font-weight:bold; " cellpadding=5px align=left width=70%
+
 
+
|- style="font-weight:bold; text-align:center;"
+
  ! width=20% style=" border:1px solid gray;"|Material Option
+
  ! width=10% style=" border:1px solid gray;"|Shader
+
  ! width=70% style=" border:1px solid gray;"|Comment
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Diffuse -> Color
+
  | style="border:1px solid gray;font-weight:normal;"|Any
+
  | style="border:1px solid gray;font-weight:normal;"|Used for both diffuse and emissive colour
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Diffuse -> Intensity
+
  | style="border:1px solid gray;font-weight:normal;"|Any
+
  | style="border:1px solid gray;font-weight:normal;"|Factor applied to diffuse colour
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Shading -> Emit
+
  | style="border:1px solid gray;font-weight:normal;"| Any
+
  | style="border:1px solid gray;font-weight:normal;"|Factor applied to emissive colour
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|World -> Ambient_Color
+
  | style="border:1px solid gray;font-weight:normal;"|Any
+
  | style="border:1px solid gray;font-weight:normal;"|Not sure what effect this may have, if any, on the exported resultSee also Shading -> Ambient.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Shading -> Ambient
+
  | style="border:1px solid gray;font-weight:normal;"| Any
+
  | style="border:1px solid gray;font-weight:normal;"|Amount of global ambient colour the material receives.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Transparency
+
  | style="border:1px solid gray;font-weight:normal;"|Any
+
  | style="border:1px solid gray;font-weight:normal;"|Use transparency if checked.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Transparency -> Alpha
+
  | style="border:1px solid gray;font-weight:normal;"|Any
+
  | style="border:1px solid gray;font-weight:normal;"|Transparency (opacity) factor.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Specular -> Color
+
  | style="border:1px solid gray;font-weight:normal;"|Phong
+
  | style="border:1px solid gray;font-weight:normal;"|
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Specular -> Intensity
+
  | style="border:1px solid gray;font-weight:normal;"|Phong
+
  | style="border:1px solid gray;font-weight:normal;"|
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Specular -> Hardness
+
  | style="border:1px solid gray;font-weight:normal;"|Phong
+
  | style="border:1px solid gray;font-weight:normal;"|Shininess
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Mirror -> Color
+
  | style="border:1px solid gray;font-weight:normal;"|Phong
+
  | style="border:1px solid gray;font-weight:normal;"|Mirror must be checked.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Mirror -> Reflectivity
+
  | style="border:1px solid gray;font-weight:normal;"|Phong
+
  | style="border:1px solid gray;font-weight:normal;"|Mirror must be checked
+
|}
+
 
+
Be wary of checking Shading->Shadeless as this stops the export of several attributes including: Specular Color, Specular Factor, Shininess Exponent, Reflection Color, Reflection Factor, Specular, and Shininess.
+
 
+
In summary, material values you can play with in any material include:
+
:* Diffuse colour
+
:* Diffuse specular
+
:* Transparency
+
:* Specular colour
+
:* Specular intensity
+
:* Specular hardness
+
:* Shading Emit
+
:* Mirror
+
:* Ambient (in World)
+
 
+
===Sample Assets===
+
 
+
====Notex====
+
 
+
Description: TBD
+
 
+
Sample asset:  A notex material applied to a box. [[File:4000001- FBX paint-test-notex.zip]]
+
 
+
====Onetex====
+
 
+
Description: TBD
+
 
+
Sample asset:  A onetex material applied to a box. [[File:4000002 - FBX paint-test-onetex.zip]]
+
 
+
====Reflect====
+
 
+
Description: This works well when an image is used to influence the material base colourCheck/tick the Mirror option in the Material panel and select the amount of reflectively you need.  Start with 0.5 and experiment.
+
The attached example uses env_metal.tga as a reflection texture. You can set the Mapping Coordinates to either UV or ReflectionReflection makes the model look correct in Blender but makes no difference to TANE.
+
In the Texture Influence->Diffuse section, check both Color and MirrorDon't change the values of either field as the FBX exporter ignores them.
+
 
+
M.reflect doesn't work well with a diffuse texture.  Other materials are probably better suited for that purpose.
+
 
+
Sample asset: A reflect material applied to a box. [[File:4000003_-_FBX_-_paint-test-reflect.zip]]
+
 
+
====Gloss====
+
 
+
Description: TBD
+
 
+
====Tbumptex====
+
 
+
Description: TBD
+
 
+
Sample asset: A tbumptex material applied to a box. [[File:4000004 - FBX - paint-test tbumptex.zip]]
+
 
+
====Tbumpgloss====
+
 
+
Description: TBD
+
 
+
====Tbumpenv====
+
 
+
Description: TBD
+
 
+
Sample asset: A tbumpenv material applied to a box. [[File:4000005 - FBX - paint-test tbumpenv.zip]]
+
 
+
====Transparency and Double Sided Meshes====
+
 
+
This asset demonstrates transparency using notex materials and a double sided mesh using a onetex material. In particular, it shows how metadata files can be used for this purpose.
+
[[File:6000011_-_FBX_-_transparency_test_1.zip]]
+
 
+
===Textures===
+
 
+
This section identifies the texture options used by the FBX exporterVery few of the available options are actually exported and the only exported item relevant to normal/bump maps is the Mapping->Coordinates value.  In practice, this isn't an issue as test assets using Trainz bump mapped materials work fineYou might need to provide your own texture.txt files when normal maps are required.
+
 
+
The FBX exporter uses the following texture slot options:
+
 
+
{|  style="border:1px solid gray;border-collapse:collapse;background:white;font-weight:bold; " cellpadding=5px align=left width=70%
+
 
+
|- style="font-weight:bold; text-align:center;"
+
  ! width=20% style=" border:1px solid gray;"|Texture Option
+
  ! width=70% style=" border:1px solid gray;"|Comment
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Texture name
+
  | style="border:1px solid gray;font-weight:normal;"|Can be any name but recommend names such as Diffuse, Normal or similar to identify purpose.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Texture type
+
  | style="border:1px solid gray;font-weight:normal;"|Must be "Image or movie"
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Image -> Name
+
  | style="border:1px solid gray;font-weight:normal;"|Filename of image.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Image -> Use Alpha
+
  | style="border:1px solid gray;font-weight:normal;"|Tick if alpha channel is to be used.
+
  |-
+
  | style="border:1px solid gray;font-weight:normal;"|Image -> Alpha Mode
+
  | style="border:1px solid gray;font-weight:normal;"|This value is exported but probably not used by Trainz so leave it as "straight".
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Mapping -> Coordinates
+
  | style="border:1px solid gray;font-weight:normal;"|Use UV, Normal or Reflection
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Mapping -> Map
+
  | style="border:1px solid gray;font-weight:normal;"|UV map name
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|Image Mapping -> Extension
+
  | style="border:1px solid gray;font-weight:normal;"|Use Repeat if UV wrapping required.  Probably only of value within Blender since Trainz texture.txt files define image wrapping.
+
|}
+
  
==Video Tutorials==
+
=Some tips for exporting=
Exporting basic Cube from Blender with PBR Materials:
+
:*  Triangulate (convert to three sided polygons) before export. You can do this per mesh by using the triangulate command (Ctrl T) in mesh edit mode.  Or you can add a triangulate modifier to the mesh in mesh object mode.  The modifier method is preferred since keeping meshes in multi sided polygons help with editing.
 +
:*  Make sure you only have one UV map per mesh.  Trainz doesn't seem to like more than one UV map.
 +
:*  Unapplied mesh scaling can cause issues including island distortment in the UV editor.  Apply any scaling before export.
 +
:*  FBX does not support double sided meshes so you will need to create a metadata file as described at [[FBX file format#Mesh Metadata Files]].  Note that this is done per material.  i.e. you cannot have the same material for single sided and double sided meshes.
 +
<br>
 +
=FBX to Trainzmesh Conversion Warnings and Errors=
 +
<p>Errors and warnings starting with a T, such as T16128, are errors ouput by the ASSIMP converter and are not output by the Trainz FBX importer.  Errors or warnings starting with VE are generated by Trainz.  See [[Asset_Validation]].</p>
 +
<table bgcolor=#00ffff border=2 width=900>
 +
<tr>
 +
<th>Warning/Error</th>
 +
<th>Help/Explanation</th>
 +
</tr>
 +
<tr valign="top">
 +
<td>Warning:  T16080: ...shading mode not recognised: Phong</td>
 +
<td>You can ignore this warning</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Warn,  T15808: FBX-DOM (TOK_KEY, offset 0xnnnn) source object for connection does not exist</td>
 +
<td>You can ignore this warning</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Error: Unable to determine vertex format</td>
 +
<td>This can be caused by having multiple UV maps for the same mesh.  For example, baking a painted mesh to a bake mesh requires two UV maps.  Remove old maps before exporting.  If you wish to keep those maps, back up the Blender file and then delete the extra maps</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>Error, T5268 or T9068, Failed to triangulate polygon (no ear found). Probably not a simple polygon.</td>
 +
<td>Try triangulating the mesh, or meshes, using Ctrl T (quads to tris).  If the error continues, try using the Triangulate modifier.  This problem is known to occur when using modifiers that may produce ngons on export.</td>
 +
</tr>
 +
<tr valign="top">
 +
<td>T16128: FindInvalidDataProcess fails on mesh uvcoords: All vectors are identical"</td>
 +
<td>Possibly caused by having one or more UV islands collapsed to one pixel.</td>
 +
</tr>
 +
</table>
 +
<br>
 +
=Additional tutorial and Blender help resources=
 +
# An additional video tutorial can be found at [https://www.youtube.com/watch?v=qTXgaNOETF0 Exporting basic Cube from Blender with PBR Materials]. That tutorial uses Substance Painter to create the PBR materials.
 +
# Paul Hobbs' Blender tutorial for creating a steam locomotive. [http://www.44090digitalmodels.co.uk/] The tutorial is quite complex so start with some simple assets like houses or buildings first.
 +
# [[HowTo/Solve Blender Modelling Problems|How to solve Blender modelling problems]]
 +
<br>
  
[https://www.youtube.com/watch?v=qTXgaNOETF0 Video]
+
=Return to Index=
  
==Return to Index==
 
 
 
[[HowToGuides|<< How To Guides]]
 
[[HowToGuides|<< How To Guides]]
  

Latest revision as of 15:59, 27 June 2022

This page describes how to export a simple rock model from Blender into the FBX file format for use in Trainz as a scenery object. The model uses a Level of Detail (LOD) system suitable for scenery objects.

Some knowledge of Blender would be useful.

A Blender rock mesh is provided along with three PBR textures suitable for creating a PBRMetal material.

Blender320-FBX-export-rocks.jpg

Contents

[edit] Asset Creation Workflow

The basic workflow is:

  1. Create your mesh.
  2. Create a UV map for mapping mesh polygons to a texture.
  3. Create and apply a Trainz material including textures.
  4. Create additional lower polygon meshes to be used as Level of Detail (LOD) meshes.
  5. Create a config.txt file that identifies your model, its type, a mesh definition, and a description including an image (thumbnail) of the model.
  6. Export the model to an FBX file.
  7. Add model textures and texture definition files so Trainz knows how to use those textures.
  8. Import the model into Trainz. During import Trainz will create Trainzmesh mesh file for each FBX file.

The first two steps have been done for you.

[edit] Project files

A project file File:Blender320-project.zip is provided in zip format. The file contains:

  1. A Blender named my_rock_blender320_start.blend. This Blender model has two meshes. One very high polygon mesh used only to bake a normal map and a much smaller mesh that will be the first LOD level (LOD 0).
  2. Three PBR textures and their texture description files:
    • rockmat-albedo.png, rockmat-albedo.texture.txt
    • rockmat-parameter.png, rockmat-parameter.texture.txt
    • rockmat-normal.png, rockmat-normal.texture.txt
  3. A config.txt. You will need to add your own kuid.
  4. A thumbnail image.
  5. A Blender file named my_rock_blender320_final.blend. This is the end result ready for export.


[edit] Adding the Material, creating LOD meshes, and Exporting

[edit] Load Your Model

  • Create a suitable working folder on your computer. You might call it "FBX_export_example_1".
  • Unpack the project file File:Blender320-project.zip into your working folder.
  • Start Blender, load the start Blender file and then save it as "rock_working.blend".


Blender320-FBX-export-start.jpg


[edit] What's in the model?

On opening the Blender file you will be in Layout mode with an untextured rock mesh. In the Scene Collection panel there are three Blender collections: "high poly meshes", "Other", and "lod0.
The very high poly mesh version has 1.5 million triangles and is unsuitable for export as a Trainz mesh but it is suitable for baking normal maps for a lower poly mesh. We will not use it so hide it by unchecking the white box to the right of the high poly meshes collection. You can also uncheck the Other collection. That can be useful for hiding lamps and cameras.
The lod0 collection contains the main mesh we will work with so make sure it is checked and visible. If you look at the bottom right of the screen it should show Tris 6,144. This count is a bit high for a rock so Level of Detail (LOD) meshes are required.


[edit] Task 1 - Create a Trainz material

  • Make sure the "rock_lod0n" mesh is selected and no others visible. Change to the Shading mode by clicking on the Shading tab at the top of the screen.
Blender320-FBX-export-shader-editor.jpg


  • In the Properties Editor, which is at the bottom right, create a new material. Click on the material name and change it to "rock.m.pbrmetal".
NotePad.PNG On creating the material a Principled BSDF shader node and a Material Output will be created in the Shader Editor.
Blender uses several different collections of nodes and these are material nodes. Basically, nodes take some information on the left side and output different information on the right. The shader node takes in a whole lot of information from basic colour, PBR values, and normals. The output is sent to the Material Output node which is what is displayed on the associated mesh. All of the shader inputs have default values.


For a Trainz PBRMetal material we need to provide an albedo (base colour) texture, a set of parameters textures (emissive, ambient occlusion, roughness and metallicity) combined in one file, and a normals texture.


  • Within the shader editor press Shift A and create an Image Texture node as shown below.


Blender320-FBX-export-create-a-texture-input-node.jpg


  • Click on the Color output and drag the connection across to the Base Color input of the shader node. If you connect to the wrong input then disconnect by clicking on the input end of the link which is on the left side.
  • Back in the Image Texture node use the Open dialog and find the file "rockmat-albedo.png". The rock will now show the base colours.
  • Create another Image Texture node and connect it to the Roughness input of the shader node.
  • Load the file "rockmat-param.png" into the node.
  • Change the image texture node Color Space to non-color as the texture doesn't actually contain colour information.


NotePad.PNG An image texture typically has three channels of red, green and blue (RGB) colour information. If transparency is used then a fourth channel called alpha is used (RGBA).

Game engines often use these channels to carry information other than colour and this is the case for a Trainz parameters texture. For more information read PBRMetal Parameter Texture.
Linking the parameters texture to the roughness input is the only way to get Blender to export texture names correctly in an FBX file. Consequently the model may look slightly different in game.

Now we add the normal map but we need an additional node to provide additional information.


  • Using Shift A, add a Vector->Normal Map node and connect it to the Normal input of the shader node.
Blender320-FBX-export-create-a-vector-normal-map-node.jpg
  • Add another Image Texture node, connect it to the Normal Map node and load the "rockmat-normal.png" texture.
  • Your material, in the Shader Editor, should look like the following:


Blender320-FBX-export-complete-material.jpg


Now is a good time to save your Blender file.


[edit] Task 2 - Create lower poly LOD versions

The rock_lod0n mesh is 6144 triangles and needs to be reduced to less than 300 triangles for the lowest polygon mesh.

In TS19 and later versions, you can dictate the distance at which LOD levels swap out and also the distance the mesh is not rendered at all. This is independent of any draw distance a user may apply although Trainz will use the lowest draw distance of the two schemes.

Each lower poly mesh must be at least 20% fewer polys than the previous mesh but to get down to 300 polys using just 20% would take quite a few levels. So, it is recommended that 20% be applied only for the first LOD change and a more agressive reduction after that.


In this asset we will aim for levels like this:

LOD Level Triangles Distance
LOD0 6144 0 to 100 metres
LOD1 4900 100 to 300 metres
LOD2 1000 300 to 600 metres
LOD3 250 600 to 5000 metres
No render beyond 5000 metres


[edit] Creating the LOD1 mesh

  • If you haven't done so, save now.
  • In the Outliner Editor (top right) select the LOD0 collection.
  • Right click and select Duplicate Selection. This duplicates both the collection and meshes in the collection.
  • Rename the collection to LOD1 and rename the mesh to rock_lod1n. There is no rename action in the drop down menu but double clicking on the name will allow a change.
  • Hide the LOD0 collection by unchecking the box to the right of the collection name. This hides the entire collection.
  • In the Properties Editor, select the Modifiers tab which is the spanner icon. There should be no modifiers listed.
  • Click on Add Modifier and select the Decimate option.
  • The Decimate modifier has basically three options: Collapse, Un-Subdivide, and Planar. Generally, it is best to use the Collapse option but sometimes you can get a better result with Planar. The poly count is a face count that is most likely the number of quads (4 sided polygon) so the number of triangles would be twice that number. This isn't always correct and depends on the mesh topology. It should be close enough for our purposes.
  • For LOD1 we want a maximum of 4900 triangles (2450 faces) so use a Ratio value of 0.54 that gives a result of 2425 faces. This value may need to be tweaked if the actual value seen by Trainz is higher and therefore breaks the 20% rule.
  • Do not apply the modifier as this is a non destructive setting and may need to be changed. The modifier will be applied on export.
  • Save your work and we will move onto LOD2.


[edit] Creating the LOD2 mesh

  • This time select the LOD1 collection, make a duplicate and rename the collection to LOD2 and the mesh to rock_lod2n. You could have duplicated LOD0 instead but this way we alrady have a decimate modifier.
  • Hide the LOD0 and LOD1 collections if not already hidden.
  • This time we want to reduce the triangle count to 1000 (face count 500) so a more agressive reduction is required.
  • Try a Ratio value of 0.08 which gives quite a good result for a face count of 473.
  • If you want to compare LOD versions you can show/hide the other LOD collections but make sure you are left working on the correct mesh.
  • Save your work and we will move onto the final LOD - LOD3.


[edit] Creating the LOD3 mesh

  • Duplicate the LOD2 collection and rename the collection to LOD3 and the mesh to rock_lod3n.
  • Hide all collections except LOD3.
  • Change the Decimate Ration value to 0.017 that results in 102 faces (204 triangles). Our rock is now looking a bit pointy in places but remember this will only be shown at 600+ metres.
  • Save your work.


NotePad.PNG When creating our mesh names we have been using a convention of "rock_lodxn" where the x character is a LOD level. You can use any names you like within reason but using the "lodxn" will work with N3V's config.txt generator tool. See Trainz Content Utilities


NotePad.PNG At this point we have our 4 levels of LOD, LOD0 to LOD3, and that should pass asset validation. By creating the material after making the original mesh (LOD0) we are able to automatically copy the material from LOD to LOD. At each stage you should check that the mesh paint is still correct as LOD reduction will change the UV mapping and potentially cause the paint to look wrong. For a rock this probably doesn't matter but for other models it may not work. There are other LOD reduction techniques but they are beyond the scope of this tutorial.


[edit] Exporting our model

  • Repeat for each LOD collection
    • Select the next LOD collection and hide all the others.
    • Select the mesh for this LOD - e.g. rock_lod0n.
    • From the top menu select File->Export->FBX.
    • Change the output name, at the bottom of the dialog box, to the name of the mesh - e.g. rock_lod0n.fbx.
    • Change the export settings to the same as this image.


Blender320-FBX-export-FBX-export-dialog-box.jpg

For this export we use:

Include Selected Objects
Object Types Mesh only
Transform -> Scale 1.00
Apply Scalings FBX All
Forward Y Forward
Up Z Up
Apply Unit Ticked
Use Space Transform Ticked
Geometry-> Apply Modifiers Ticked
Triangulate Faces Ticked


You can ignore the animation settings (armature and Bake Animation).


  • Click on the Export FBX button at the top right. The mesh will be exported.


NotePad.PNG The settings shown above will work for Trainz but other settings will also work.



PencilTips.PNG You can save your preferences for a given export such as "mesh only" or "animation" by clicking on the plus button (+) next to Operator Presets and saving the preset with a name.



[edit] Importing into Trainz

[edit] Getting organised

  • Create a folder called "export" within your working folder. While not necessary it is convenient to have all the files Trainz needs to construct the asset.


[edit] FBX conversion to Trainzmesh format

While the FBX format is convenient for mesh creation and developing materials and textures, Trainz needs a conversion to a format that can be easily loaded by the game engine.

When you submit your asset into Trainz, Trainz will convert all the FBX files to Trainzmesh files using the same filename but changing the suffix. So a file called "rock_lod0n.fbx" will become "rock_lod0n.trainzmesh".

This means that your asset configuration in the config.txt file must refer to Trainzmesh files rather than FBX files.


[edit] Config.txt

For this asset we are creating a kind "scenery" asset and the config.txt will use mesh-table LOD together with a mesh-table-lod-transition-distances tag.

As explained earlier, the mesh-table-lod-transition-distances tag will control the distances at which the meshes changes and when they are no longer rendered.

A config.txt is provided in the project files although you will need to provide your own kuid. This is part of the config.txt.


kind                                      "scenery"
kuid                                      Note: supply your own kuid here
trainz-build                              "4.6"
category-class                            "HM"
category-region                           "00"
category-era                              "2010s;2020s"
mesh-table {
  lod0n {
    mesh                                  "rock_lod0n.trainzmesh"
    auto-create                           1
    lod-level                             0
    mesh-season                           0
  }
  lod1n {
    mesh                                  "rock_lod1n.trainzmesh"
    auto-create                           1
    lod-level                             1
    mesh-season                           0
  }
  lod2n {
    mesh                                  "rock_lod2n.trainzmesh"
    auto-create                           1
    lod-level                             2
    mesh-season                           0
  }
  lod3n {
    mesh                                  "rock_lod3n.trainzmesh"
    auto-create                           1
    lod-level                             3
    mesh-season                           0
  }
}
mesh-table-lod-transition-distances       100,300,600,5000


The trainz-build should be 4.6 or above.

The mesh table identifies the four meshes used in the asset plus the LOD level.

The mesh-table-lod-transition-distances identifies the distance at which the mesh changes to the next lower polygon mesh. You can change these if you want to experiment.


[edit] Texture.txt files

You can provide your own texture.txt files (advisable) or let the commit process create them for you.


[edit] Committing the asset

  • Commit the asset by dragging the folder onto CM. Assuming the commit is error free, open the asset for edit in explorer and see what Trainz has created.


You will get a warning like "...shading node not recognized:Phong". Trainz doesn't use the exported shader anyway so you can ignore the warning.

The trainzmesh files should be as described above. The FBX files will also be present so you may want to delete those if you are ready to upload your asset to the DLS or elsewhere. If you delete the FBX files, then you will need to commit the asset again. Since the trainzmesh files already exist no FBX conversion is carried out.


[edit] About the boulder asset

The material used for this asset was created within Substance Painter which is a powerful PBR material and texture creation tool.

You can make your own PBR textures within Blender but that is beyond the scope of this tutorial. There are several payware Blender addons that can create quite good textures, One worth looking at is PBR Painter and the Trainz user Cayden has been promoting that for Trainz use. Search for the PBR Painter thread on the Trainz forums.


[edit] Animation

If you are interested in animation for Blender, see How to export Blender FBX animation.

[edit] Some tips for exporting

  • Triangulate (convert to three sided polygons) before export. You can do this per mesh by using the triangulate command (Ctrl T) in mesh edit mode. Or you can add a triangulate modifier to the mesh in mesh object mode. The modifier method is preferred since keeping meshes in multi sided polygons help with editing.
  • Make sure you only have one UV map per mesh. Trainz doesn't seem to like more than one UV map.
  • Unapplied mesh scaling can cause issues including island distortment in the UV editor. Apply any scaling before export.
  • FBX does not support double sided meshes so you will need to create a metadata file as described at FBX file format#Mesh Metadata Files. Note that this is done per material. i.e. you cannot have the same material for single sided and double sided meshes.


[edit] FBX to Trainzmesh Conversion Warnings and Errors

Errors and warnings starting with a T, such as T16128, are errors ouput by the ASSIMP converter and are not output by the Trainz FBX importer. Errors or warnings starting with VE are generated by Trainz. See Asset_Validation.

Warning/Error Help/Explanation
Warning: T16080: ...shading mode not recognised: Phong You can ignore this warning
Warn, T15808: FBX-DOM (TOK_KEY, offset 0xnnnn) source object for connection does not exist You can ignore this warning
Error: Unable to determine vertex format This can be caused by having multiple UV maps for the same mesh. For example, baking a painted mesh to a bake mesh requires two UV maps. Remove old maps before exporting. If you wish to keep those maps, back up the Blender file and then delete the extra maps
Error, T5268 or T9068, Failed to triangulate polygon (no ear found). Probably not a simple polygon. Try triangulating the mesh, or meshes, using Ctrl T (quads to tris). If the error continues, try using the Triangulate modifier. This problem is known to occur when using modifiers that may produce ngons on export.
T16128: FindInvalidDataProcess fails on mesh uvcoords: All vectors are identical" Possibly caused by having one or more UV islands collapsed to one pixel.


[edit] Additional tutorial and Blender help resources

  1. An additional video tutorial can be found at Exporting basic Cube from Blender with PBR Materials. That tutorial uses Substance Painter to create the PBR materials.
  2. Paul Hobbs' Blender tutorial for creating a steam locomotive. [1] The tutorial is quite complex so start with some simple assets like houses or buildings first.
  3. How to solve Blender modelling problems


[edit] Return to Index

<< How To Guides

Personal tools