HowTo/Export from Blender using FBX

From TrainzOnline
< HowTo(Difference between revisions)
Jump to: navigation, search
(Added animation section and some samples.)
(Major rewrite for Blender 2.80)
(28 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This is a work in progress as:
+
This page describes how to export a simple model from Blender 2.80 into the [[FBX file format]] for use in TrainzThe model uses a Trainz PBRMetal format so it is only suitable for TRS2019 and later versions. The Blender source and PBRMetal textures are provided.
(1) the author learns more about the process, and
+
(2) N3V are exploring the FBX format.  Please contact the author if you have something to contribute.
+
  
==Introduction==
+
Some knowledge of using Blender and Trainz asset creation is assumed.
  
This guide provides information for the export of FilmBoX (FBX) files from Blender.  
+
[[File:Cube asset in game.jpg|500px|left]] {{clear}}
  
 +
=Video Tutorial=
  
===Versions===
+
A video tutorial can be found at [https://www.youtube.com/watch?v=qTXgaNOETF0 Exporting basic Cube from Blender with PBR Materials]. 
  
{| class="wikitable"
 
  
|-
+
=Asset Creation Workflow=
|style="width:100px;"|TANE:||style="width:200px;"|4.5 or later.
+
|-
+
|Blender:|| Known to work for Blender 2.78a or later.  The FBX exporter is a standard addon for Blender.
+
|-
+
|FBX format:|| Binary format only (see discussion below).  FBX 2011, FBX2012, FBX2013.
+
|-
+
|Special requirements:|| None.  Creators will need their preferred image editors and text editors but there are no special requirements for FBX.
+
|-
+
|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.
+
|}
+
  
 +
The basic workflow is:
 +
:#  Create your mesh.
 +
:#  Create a UV map for mapping mesh polygons to a texture.
 +
:#  Apply a Trainz material including textures.
 +
:#  If required, animate the mesh.
 +
:#  Export the model to an FBX file.
 +
:#  Import the model into Trainz.  Trainz will create a Trainzmesh mesh data file.
  
===The FBX format===
+
The provided Blender models are ready for you to do steps 3 through 6.  Step 4 is ignored.
  
A brief discussion on the FBX format history can be found  {{plain link|https://en.wikipedia.org/wiki/FBX here}}.  FBX can be exported either as an ASCII (i.e. human readable) file or in binary format. TANE will only recognise the binary format.
+
=Exporting FBX in Blender 2.80=
 +
==Blender 2.80 Features==
  
 +
Blender 2.8 introduces a number of new features that can benefit Trainz modellers. These include "Collections", a change in workspaces, and opportunities to create Trainz PBR textures within Blender.  The latter is quite complex and the author is currently evaluating a number of tools that might be useful.  Those tools are likely to be payware but very cheap payware compared to full commercial toolsets.
 +
There is now a separate Image Editor and UV Editor.  The differences are not obvious apart from some minor changes to the associated toolsets.
  
==Blender and FBX==
+
===Collections===
 +
Scene Collections replace the old layers system and now avoids the 20 layer limit.  The most useful aspect of collections is that you can name them so their contents are easily recognised.  For example, you can put all your LOD0 meshes in a LOD0 collection, LOD1 meshes in a LOD1 collection, and so on.
 +
You can group items such as lamps and cameras in their own collection and simply hide them when not needed. You can find more information on collections in video tutorials on the Web.
 +
===Workspaces===
 +
You might find workspaces easier to use than earlier Blender versions.  You can easily add or delete workspaces as it suits your development style.  A useful set of workspaces might be:
 +
:*Default (you can rename that to something like "Modelling")
 +
:*UV Editing
 +
:*Shading
 +
:*Animation
 +
:*Compositing (optional, but could be used for baking parameter textures)
 +
:*3D View Full (optional)
 +
:*Scripting (optional)
 +
==Blender 2.80 Issues for Trainz Modellers==
 +
===Blender Render===
 +
This is gone for 2.8 and that will make it difficult for those not wanting to use Trainz PBR textures.  The author has not yet investigated if cycles can be used for this purpose except for NOTEX.
  
Blender is capable of both importing and exporting FBXThe Blender exporter does not export all possible object attributes and it is likely that TANE will not recognise all those attributes that are exported.
+
===Parenting===
The Blender documention contains {{plain link|https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/Autodesk_FBX list of attributes}} that are exported.
+
Parent/child links are less obvious in 2.8You can see the relationship in the collection tree but it is possible to have a child object in a different collection and that is a bit confusing.
 +
==Blender Addons==
 +
There are a number of interesting addons for Blender 2.8.  Some are free and others are payware.  
 +
The Material Library addon comes with Blender 2.8 as a community addon. You don't need to install it but you do need to enable it.
 +
You can find this addon in the Edit Menu, Preferences, and filter on "material".  See the following image:<br />
 +
[[File:Material library.jpg|800px]]<br />
 +
This addon will allow you to save Trainz PBR materials.
 +
==Example Model==
 +
A sample model of a simple cube is provided. The mesh is UV mapped but there is no material or textures linked in the model. The source files include both a starting and completed model together with texture images, config.txt, etc.  Just change the owner KUID id to yours.
 +
The source files can be found here: [[File:blender_cube280.zip]]
 +
:* Create a suitable working folder on your PCYou might call it "FBX_export_example_1".
 +
:* Unzip the files into that folder.
 +
:* Start Blender 2.8 and load file "mycube_b280_start.blend".
  
Included in this guide is a list of attributes that have been observed as exported and treatment/acceptance by TANEThe list is incomplete and so is a work in progress.
+
==Creating a Trainz PBRMetal Material==
 +
The Trainz PBRMetal material is the base material for Trainz PBR assets.  Other Trainz PBR materials are variations of this material.  There isn't a standard Blender shader node for PBRMetal but we can use the Principled BSDF shader node and set up the three texture imputs of Albedo, Parameter and Normal.  See [[M.pbrmetal]] for more information on this material.
 +
<br />Making a PBRMetal material is a little tedious but we can automate this by using a standard Blender addon called Material Library VX.
 +
:* Change to the Shading workspace.
 +
:* Select the cube and select the material icon in the Properties window (bottom right)It should show no materials.
 +
:* Select New (material).  You should get this view although the material name may be different:[[File:New material.jpg|1400px]]
 +
:* Blender creates a new material with a Principled BSDF shader node and material output node.  This will be the basis of our Trainz PBR material.
 +
:* Change the name of the material to "Template_Trainz_PBRMetal".  We deliberately use a generic name because we will want to save it for other models.
 +
:* Within the Shader Node editor press Shift A and add a texture->image texture node.
 +
:* Select the new texture node and press Shift D and drag the texture node copy to a blank space. Repeat to create another texture node.  These nodes will be used for our Albedo, Normal and Parameter textures.
 +
:* Make sure the three texture nodes are stacked one on top of each other as per the image below.
 +
:* Connect the top texture node from the Colour output to the Base Color input on the shader node.  You make connections by left clicking the output (on the right) and dragging the line to the destination input.
 +
:* Connect the Alpha output of the middle texture node to the Roughness input shader node.  While this may not make sense it does work!
 +
:* Connect the Color output of the bottom node to the Normal input shader node.
 +
:* Press Shift A and add a Vector-Normal Map node to a blank space within the editor.
 +
:* Drag the Normal Map node onto the link between the bottom texture node and the Normal input. Blender automatically reroutes the links.  Note that you could have created the Normal Map node and dropped it on that link.
 +
:* The result should look like this:<br />[[File:Trainz PBRMetal template.jpg]]<br />
  
 +
==Saving the PBRMetal Material Template==
 +
This action need only be done once.
 +
:* Select the Material icon in the Properties Editor.
 +
:* Find the Material Library VX panel.  This is the addon we enabled earlier.
 +
:* Choose the Cycles Templates library.  There will be a pause here as the addon loads a Blender file in the background and finds the materials within it.
 +
:* Add the "Template_Trainz_PBRMetal" to the library by clicking the plus (+) icon.
 +
:* Scroll through the list or search for "Trainz" to ensure the template is in the list.
 +
:* Change the material name allocated to the mesh to "mycube.m.pbrmetal" or any suitable name.<br />[[File:Mycube material.jpg]]<br />
  
==Skills Required==
+
==Using the Template in Other Projects==
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.  
+
We created the Trainz PBRMetal template so it can be used in other projects.  To see how this works try the following:
 +
:* Save your current working file.
 +
:* Start a new project and just use the default cube.
 +
:* Select the Material option in the Properties Editor.
 +
:* There should be a default material called Material1.  If not, just create a new one.
 +
:* Scroll down to find the Material Library VX panel.
 +
:* Select the Cycles Template library.
 +
:* Search for "trainz" or scroll down until you find it.
 +
:* Click on the Apply icon which looks like a round ball.  The Trainz PBRMetal template will replace the existing material allocated to the mesh.
 +
:* Open the Shading workspace and the material we created earlier will be visible.  All you need to do is rename the material and allocate the textures which is what we will do next.
  
 +
==Add the Material Textures==
 +
:* Reopen your working Blender file if required.
 +
:* Change to the Shading Workspace.
 +
:* Select the top texture node, click on Open and add the file "cube_albedo.png".  You may need to navigate Blender to your working folder as it doesn't default to your Blender file location.
 +
:* Select the middle texture node and load the file "cube_parameter.png".
 +
:* Change the Color Space to Non-color.
 +
:* Select the bottom texture node and load the file "cube_normal.png".
 +
:* Change the Color Space to Non-color.
 +
:* If you have the 3D Viewport in "Look dev" mode (3rd ball icon from the left) you will see the material applied to the cube.  This is a reasonable representation of how it will look in Trainz.
 +
[[ File:Material applied.jpg]]
  
==Exporting a mesh object from Blender in FBX format==
 
  
The FBX exporter addon must be enabled in User Preferences.
+
==Exporting to FBX==
 +
The model is now ready for export.
 +
:* Change to the Default workspace and select the mesh object in the 3D Viewport. 
 +
:* Select File->Export->Export FBX and the FBX export panel will show in the bottom left hand corner of the window.  If the Export FBX option isn’t shown, then make sure it is enabled in User Preferences.
 +
:* Operator Presets.  This option allows you to define an export configuration that can be recalled rather than having to set options each time.
 +
:* Scale:  Leave the scale value at 1.0 and make sure the small button to the right of the scale is unchecked.
 +
:* The four export options categories: Main, Geometries, Armature and Animation show different menus and sub options for those categories.  You can leave the standard settings for Geometries, Armature and Animation.
 +
:* For Main options:
 +
:*:* Check Selected Objects. 
 +
:*:* Apply Scalings:  Use “FBX All”.
 +
:*:* Forward: select option “Y Forward”.  This automatically changes the Up option to “Z Up” which is correct for Trainz.
 +
:* Check Mesh only since we are not exporting empties or animation.
 +
:* Leave all other options at their default values.
 +
:* At the top of the window, make sure the selected target folder is your project folder.
 +
:* Enter the target FBX file as “mycube_lod0.fbx” .
 +
:* Click on the Export FBX button at the top right.  The mesh will be exported.
  
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
+
[[File:B280 FBX PBRMetal asset FBX export settings.jpg]] {{clear}}
vary significantly between the Binary export version and the ASCII export version so make sure you have Binary selected.
+
  
===The Main Menu===
+
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.
[[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.
+
* 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.
+
==Importing into Trainz==
 
+
===Config.txt===
* Leave the Experimental and Custom Properties as deselected.
+
When you submit your asset, Trainz will convert the FBX file to a Trainzmesh file so the mesh table will need to identify each mesh as such. For the sample asset the filename will be mycube_lod0.trainzmesh.  See the config.txt in the project folder.
* 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}}
+
 
+
====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==
+
 
+
Setting up the CONFIG.TXT
+
 
+
The only changes to the config.txt are in the mesh table.  The 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 commitCurrently 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===
+
  
 +
===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.
 
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 chosenThis may be an issue with the Blender FBX exporter.
+
===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.
 +
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 again.  Since the trainzmesh files already exist no FBX conversion is carried out.
  
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.
+
==Animation==
 +
If you are interest in animation for Blender 2.8, see this [[HowTo/Export Blender FBX Animation|page]].  
  
==Warnings and Errors==
+
=Errors, Warnings and other Issues=
  
Ignore errors or warnings about Phong shaders.
+
==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.
  
 
+
==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 importerErrors or warnings starting with VE are generated by Trainz.  See [[Asset_Validation]].
==Materials==
+
 
+
This section identifies the material options used by the FBX exporterFor detailed descriptions on how Trainz uses material types 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="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;"
 
|- style="font-weight:bold; text-align:center;"
   ! width=20% style=" border:1px solid gray;"|Material Option
+
   ! width=40% style=" border:1px solid gray;"|Warning/Error
   ! width=10% style=" border:1px solid gray;"|Shader
+
   ! width=60% style=" border:1px solid gray;"|Help/Explanation
  ! 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;"|Warning: T16080: ...shading mode not recognised: Phong
  | style="border:1px solid gray;font-weight:normal;"|Any
+
   | style="border:1px solid gray;font-weight:normal;"| You can ignore this warning.
   | 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;"|Warn,  T15808: FBX-DOM (TOK_KEY, offset 0xnnnn) source object for connection does not exist
  | style="border:1px solid gray;font-weight:normal;"|Any
+
   | style="border:1px solid gray;font-weight:normal;"| You can ignore this warning.
   | 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;"|Error: Unable to determine vertex format.
  | style="border:1px solid gray;font-weight:normal;"| Any
+
   | 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;"|Factor applied to emissive colour
+
 
|-
 
|-
   | style="border:1px solid gray;font-weight:normal;"|World -> Ambient_Color
+
   | 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;"|Any
+
   | 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 modifierThis problem is known to occur when using modifiers that may produce ngons on export.
  | 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;"|Error, Error, T16128: FindInvalidDataProcess fails on mesh uvcoords: All vectors are identical"
  | style="border:1px solid gray;font-weight:normal;"| Any
+
   | 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.
   | 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. (this hasn't been tested)
+
|-
+
  | 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.
+
==Return to Index==
 
+
   
In summary, material values you can play with in any material include:
+
[[HowToGuides|<< How To Guides]]
:* Diffuse colour
+
:* Diffuse specular
+
:* Transparency
+
:* Specular colour
+
:* Specular intensity
+
:* Specular hardness
+
:* Shading Emit
+
:* Mirror
+
:* Ambient (in World)
+
 
+
==Textures==
+
 
+
This section identifies the texture options used by the FBX exporter.  Very 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 fine.  You 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.
+
|}
+
 
+
 
+
===Sample Blender FBX Material Models===
+
 
+
These are just Blender models (the cube) that demonstrate the various [http://online.ts2009.com/mediaWiki/index.php/Material_Types Trainz materials].
+
 
+
Notex:  Just a simple notex material on a box.
+
[File:4000001- FBX paint-test-notex.zip]
+
 
+
Onetex, reflect, tbumptex, tbumpenv and tbumpgloss
+
 
+
These are simple boxes using the same texture but with different material types;
+
 
+
Onetex:
+
[[File:4000002 - FBX paint-test-onetex.zip]]
+
 
+
Reflect:
+
[[File:4000003 - FBX - paint-test-reflect.zip]]
+
 
+
Tbumptex:
+
[[File:4000004 - FBX - paint-test tbumptex.zip]]
+
 
+
Tbumpenv:
+
[[File:4000005 - FBX - paint-test tbumpenv.zip]]
+
 
+
Tbumpgloss:
+
 
+
(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==
+
 
+
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 created.  Then go back and correct entries in the config.txt.
+
 
+
 
+
Sample mesh-table entry with animation:
+
 
+
mesh-table {
+
  default {
+
    auto-create                          1
+
    mesh                                  "box.trainzmesh"
+
    anim                                  "box_scene.kin"
+
    animation-loop-speed                  1.00
+
  }
+
 
+
 
+
 
+
 
+
==Animation Warnings and Errors==
+
 
+
 
+
{|  style="border:1px solid gray;border-collapse:collapse;background:white;font-weight:bold; " cellpadding=5px align=left width=70%
+
  |+ Errors
+
|- 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;"|! ...  T14120: Simplified dummy tracks with just one key.
+
  | style="border:1px solid gray;font-weight:normal;"| Not sure what this warning is about but the animation is OK.
+
|-
+
  | style="border:1px solid gray;font-weight:normal;"|! ... Skipping one or more lines with the same contents
+
  | style="border:1px solid gray;font-weight:normal;"|To be investigated.  Perhaps the FBX file is repeating information.
+
|}
+
 
+
 
+
 
+
==Sample Animations==
+
 
+
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!
+
 
+
===Simple Animation 1 - Uses an empty as animated parent===
+
 
+
[[File:890045 fbx anim1 - empty.zip]]
+
 
+
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.
+
 
+
When exporting, you must select Empty and Mesh.
+
 
+
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 2 - Uses an armature as animated parent===
+
 
+
[[File:890044 fbx anim1 - armatures.zip]]
+
 
+
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.
+
 
+
This is much the same as Sample 1 but demonstrates that you can use either an empty or an armature for simple animations.
+
 
+
When exporting, you must select Armature and Mesh.
+
 
+
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-lod0_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===
+
[[Category:How-to guides]]
More complex animation samples will be added when available.
+
[[Category:Modeling]]
 +
[[Category:Content creation]]

Revision as of 20:31, 1 September 2019

This page describes how to export a simple model from Blender 2.80 into the FBX file format for use in Trainz. The model uses a Trainz PBRMetal format so it is only suitable for TRS2019 and later versions. The Blender source and PBRMetal textures are provided.

Some knowledge of using Blender and Trainz asset creation is assumed.

Cube asset in game.jpg

Contents

Video Tutorial

A video tutorial can be found at Exporting basic Cube from Blender with PBR Materials.


Asset Creation Workflow

The basic workflow is:

  1. Create your mesh.
  2. Create a UV map for mapping mesh polygons to a texture.
  3. Apply a Trainz material including textures.
  4. If required, animate the mesh.
  5. Export the model to an FBX file.
  6. Import the model into Trainz. Trainz will create a Trainzmesh mesh data file.

The provided Blender models are ready for you to do steps 3 through 6. Step 4 is ignored.

Exporting FBX in Blender 2.80

Blender 2.80 Features

Blender 2.8 introduces a number of new features that can benefit Trainz modellers. These include "Collections", a change in workspaces, and opportunities to create Trainz PBR textures within Blender. The latter is quite complex and the author is currently evaluating a number of tools that might be useful. Those tools are likely to be payware but very cheap payware compared to full commercial toolsets. There is now a separate Image Editor and UV Editor. The differences are not obvious apart from some minor changes to the associated toolsets.

Collections

Scene Collections replace the old layers system and now avoids the 20 layer limit. The most useful aspect of collections is that you can name them so their contents are easily recognised. For example, you can put all your LOD0 meshes in a LOD0 collection, LOD1 meshes in a LOD1 collection, and so on. You can group items such as lamps and cameras in their own collection and simply hide them when not needed. You can find more information on collections in video tutorials on the Web.

Workspaces

You might find workspaces easier to use than earlier Blender versions. You can easily add or delete workspaces as it suits your development style. A useful set of workspaces might be:

  • Default (you can rename that to something like "Modelling")
  • UV Editing
  • Shading
  • Animation
  • Compositing (optional, but could be used for baking parameter textures)
  • 3D View Full (optional)
  • Scripting (optional)

Blender 2.80 Issues for Trainz Modellers

Blender Render

This is gone for 2.8 and that will make it difficult for those not wanting to use Trainz PBR textures. The author has not yet investigated if cycles can be used for this purpose except for NOTEX.

Parenting

Parent/child links are less obvious in 2.8. You can see the relationship in the collection tree but it is possible to have a child object in a different collection and that is a bit confusing.

Blender Addons

There are a number of interesting addons for Blender 2.8. Some are free and others are payware. The Material Library addon comes with Blender 2.8 as a community addon. You don't need to install it but you do need to enable it. You can find this addon in the Edit Menu, Preferences, and filter on "material". See the following image:
Material library.jpg
This addon will allow you to save Trainz PBR materials.

Example Model

A sample model of a simple cube is provided. The mesh is UV mapped but there is no material or textures linked in the model. The source files include both a starting and completed model together with texture images, config.txt, etc. Just change the owner KUID id to yours. The source files can be found here: File:Blender cube280.zip

  • Create a suitable working folder on your PC. You might call it "FBX_export_example_1".
  • Unzip the files into that folder.
  • Start Blender 2.8 and load file "mycube_b280_start.blend".

Creating a Trainz PBRMetal Material

The Trainz PBRMetal material is the base material for Trainz PBR assets. Other Trainz PBR materials are variations of this material. There isn't a standard Blender shader node for PBRMetal but we can use the Principled BSDF shader node and set up the three texture imputs of Albedo, Parameter and Normal. See M.pbrmetal for more information on this material.
Making a PBRMetal material is a little tedious but we can automate this by using a standard Blender addon called Material Library VX.

  • Change to the Shading workspace.
  • Select the cube and select the material icon in the Properties window (bottom right). It should show no materials.
  • Select New (material). You should get this view although the material name may be different:New material.jpg
  • Blender creates a new material with a Principled BSDF shader node and material output node. This will be the basis of our Trainz PBR material.
  • Change the name of the material to "Template_Trainz_PBRMetal". We deliberately use a generic name because we will want to save it for other models.
  • Within the Shader Node editor press Shift A and add a texture->image texture node.
  • Select the new texture node and press Shift D and drag the texture node copy to a blank space. Repeat to create another texture node. These nodes will be used for our Albedo, Normal and Parameter textures.
  • Make sure the three texture nodes are stacked one on top of each other as per the image below.
  • Connect the top texture node from the Colour output to the Base Color input on the shader node. You make connections by left clicking the output (on the right) and dragging the line to the destination input.
  • Connect the Alpha output of the middle texture node to the Roughness input shader node. While this may not make sense it does work!
  • Connect the Color output of the bottom node to the Normal input shader node.
  • Press Shift A and add a Vector-Normal Map node to a blank space within the editor.
  • Drag the Normal Map node onto the link between the bottom texture node and the Normal input. Blender automatically reroutes the links. Note that you could have created the Normal Map node and dropped it on that link.
  • The result should look like this:
    Trainz PBRMetal template.jpg

Saving the PBRMetal Material Template

This action need only be done once.

  • Select the Material icon in the Properties Editor.
  • Find the Material Library VX panel. This is the addon we enabled earlier.
  • Choose the Cycles Templates library. There will be a pause here as the addon loads a Blender file in the background and finds the materials within it.
  • Add the "Template_Trainz_PBRMetal" to the library by clicking the plus (+) icon.
  • Scroll through the list or search for "Trainz" to ensure the template is in the list.
  • Change the material name allocated to the mesh to "mycube.m.pbrmetal" or any suitable name.
    Mycube material.jpg

Using the Template in Other Projects

We created the Trainz PBRMetal template so it can be used in other projects. To see how this works try the following:

  • Save your current working file.
  • Start a new project and just use the default cube.
  • Select the Material option in the Properties Editor.
  • There should be a default material called Material1. If not, just create a new one.
  • Scroll down to find the Material Library VX panel.
  • Select the Cycles Template library.
  • Search for "trainz" or scroll down until you find it.
  • Click on the Apply icon which looks like a round ball. The Trainz PBRMetal template will replace the existing material allocated to the mesh.
  • Open the Shading workspace and the material we created earlier will be visible. All you need to do is rename the material and allocate the textures which is what we will do next.

Add the Material Textures

  • Reopen your working Blender file if required.
  • Change to the Shading Workspace.
  • Select the top texture node, click on Open and add the file "cube_albedo.png". You may need to navigate Blender to your working folder as it doesn't default to your Blender file location.
  • Select the middle texture node and load the file "cube_parameter.png".
  • Change the Color Space to Non-color.
  • Select the bottom texture node and load the file "cube_normal.png".
  • Change the Color Space to Non-color.
  • If you have the 3D Viewport in "Look dev" mode (3rd ball icon from the left) you will see the material applied to the cube. This is a reasonable representation of how it will look in Trainz.

Material applied.jpg


Exporting to FBX

The model is now ready for export.

  • Change to the Default workspace and select the mesh object in the 3D Viewport.
  • Select File->Export->Export FBX and the FBX export panel will show in the bottom left hand corner of the window. If the Export FBX option isn’t shown, then make sure it is enabled in User Preferences.
  • Operator Presets. This option allows you to define an export configuration that can be recalled rather than having to set options each time.
  • Scale: Leave the scale value at 1.0 and make sure the small button to the right of the scale is unchecked.
  • The four export options categories: Main, Geometries, Armature and Animation show different menus and sub options for those categories. You can leave the standard settings for Geometries, Armature and Animation.
  • For Main options:
    • Check Selected Objects.
    • Apply Scalings: Use “FBX All”.
    • Forward: select option “Y Forward”. This automatically changes the Up option to “Z Up” which is correct for Trainz.
  • Check Mesh only since we are not exporting empties or animation.
  • Leave all other options at their default values.
  • At the top of the window, make sure the selected target folder is your project folder.
  • Enter the target FBX file as “mycube_lod0.fbx” .
  • Click on the Export FBX button at the top right. The mesh will be exported.
B280 FBX PBRMetal asset FBX export settings.jpg
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.

Importing into Trainz

Config.txt

When you submit your asset, Trainz will convert the FBX file to a Trainzmesh file so the mesh table will need to identify each mesh as such. For the sample asset the filename will be mycube_lod0.trainzmesh. See the config.txt in the project folder.

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.

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. 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.

Animation

If you are interest in animation for Blender 2.8, see this page.

Errors, Warnings and other Issues

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.

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.
Error, Error, T16128: FindInvalidDataProcess fails on mesh uvcoords: All vectors are identical" 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.


Return to Index

<< How To Guides

Personal tools