HowTo/Export from Blender using FBX

From TrainzOnline
< HowTo(Difference between revisions)
Jump to: navigation, search
(Added some warnings and error tables)
(Major rewrite for Blender 2.80)
(41 intermediate revisions by 5 users not shown)
Line 1: Line 1:
(Work in progress)
+
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.
  
This page provides advice on exporting from Blender to the FBX format.  It may contain sections that may be better placed on other pages, such as material definition pages, but will be hosted here for now.
+
Some knowledge of using Blender and Trainz asset creation is assumed.
  
Note that FBX export/import is currently only available to TrainzDev members using dev build 81786 or higher. (as at 14 Apr 2016)
+
[[File:Cube asset in game.jpg|500px|left]] {{clear}}
  
==Introduction==
+
=Video Tutorial=
  
This guide provides information for the export of FilmBoX (FBX) files from Blender.  The FBX format is currently only available for TrainzDev members using TANE test builds.  The guide will be updated as lessons are learned and features added to the export process.
+
A video tutorial can be found at [https://www.youtube.com/watch?v=qTXgaNOETF0 Exporting basic Cube from Blender with PBR Materials].   
  
The FBX format is intended as a replacement for existing indexed mesh (IM) and perhaps animation (KIN) files.  It is not known if existing IM and KIN will continue to be supported by N3V.
 
  
 +
=Asset Creation Workflow=
  
===Development of this guide===
+
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 importer is incomplete as is this guideThe guide will be updated as testing discovers new information.  Currently (18 Apr 2016), only mesh objects can be imported.  There is no support as yet for attachments or animation.
+
The provided Blender models are ready for you to do steps 3 through 6Step 4 is ignored.
  
===Versions===
+
=Exporting FBX in Blender 2.80=
 +
==Blender 2.80 Features==
  
{| class="wikitable"
+
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===
|style="width:100px;"|TANE:||style="width:200px;"|4.4 or later.
+
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.
|Blender:|| Not sure about this but it does work for Blender 2.77.  The FBX exporter is a standard addon for Blender.
+
===Workspaces===
|-
+
You might find workspaces easier to use than earlier Blender versionsYou can easily add or delete workspaces as it suits your development style. A useful set of workspaces might be:
|FBX format:|| Binary format only (see discussion below)FBX 2011, FBX2012, FBX2013.
+
:*Default (you can rename that to something like "Modelling")
|-
+
:*UV Editing
|Special requirements:|| None.  Creators will need their preferred image editors and text editors but there are no special requirements for FBX.
+
:*Shading
|-
+
:*Animation
|Other software:||  There are free FBX viewers available on the web including the {{plain link|http://www.autodesk.com/products/fbx/fbx-review FBX Review}} program by Autodesk.
+
:*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:<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 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".
  
===The FBX format===
+
==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 />
  
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.
+
==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 />
  
 +
==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.
  
==Blender and FBX==
+
==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]]
  
Blender is capable of both importing and exporting FBX.  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.
 
The Blender documention contains a  {{plain link|https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/Autodesk_FBX  list of attributes}} that are exported. 
 
  
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.
+
==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.
  
 +
[[File:B280 FBX PBRMetal asset FBX export settings.jpg]]  {{clear}}
  
==Skills Required==
+
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.
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.  
+
  
 +
==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.
  
==Exporting a mesh object from Blender in FBX format==
+
===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.
  
The FBX exporter addon must be enabled in User Preferences.
+
===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.
  
Select File->Export->Export FBX and the FBX export panel will show in the bottom left hand corner and should look like the following picture.  The panel contents
+
==Animation==
vary significantly between the Binary export version and the ASCII export version so make sure you have Binary selected.
+
If you are interest in animation for Blender 2.8, see this [[HowTo/Export Blender FBX Animation|page]].  
  
===The Main Menu===
+
=Errors, Warnings and other Issues=
[[File:FBX_Main_Menu.jpg|380px|left|thumb|frameless|Caption FBX Main Menu]]
+
* 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.  (note that hiding objects may be a useful option but that hasn't been tested)
+
* Scale.  Leave the Scale value as 1.00 and deselect the small icon to the right of the Scale value.  The default value for this icon is selected and
+
will cause your object to be 100 times its specified size in Blender.  This issue is still being investigated.
+
* Forward and Up.  Leave these in the default values of "-Z Forward" and "Y Up".
+
* The next six options of Empty, Camera, Lamp, Armature, Mesh and Other are mult select.  i.e. zero or more can be selected.  Select Mesh only at this point.
+
* Leave the Experimental and Custom Properties as deselected.  These have not been tested.
+
* Leave Path Mode as Auto and Batch Mode as Off.  These will be investigated later.
+
* Choose the FBX filename and export using the Export FBX in the top right hand corner.  There is no exporter log.
+
{{clear}}
+
  
===The Geometry Menu===
+
==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 materiali.e. you cannot have the same material for single sided and double sided meshes.
[[File:FBX Geometry Menu.jpg|380px|left|thumb|Caption FBX Geometry Menu]]
+
* Leave these values as shown.  We need more information on this.
+
{{clear}}
+
 
+
===The Armatures Menu===
+
 
+
[[File:FBX Armatures Menu.jpg|380px|left|thumb|Caption FBX Armatures Menu]]
+
* Leave these values as shown.  We need more information on this.
+
{{clear}}
+
 
+
===The Animation Menu===
+
 
+
[[File:FBX Animation Menu.jpg|380px|left|thumb|Caption FBX Animation Menu]]  
+
* Leave these values as shownWe need more information on this.
+
{{clear}}
+
 
+
 
+
==Config.txt==
+
 
+
Setting up the CONFIG.TXT
+
(The config.txt WiKi page will probably be updated in the future to reflect changes required for FBX)
+
 
+
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"
+
    }
+
  }
+
 
+
==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 and made available if opened for edit. This may change.
+
 
+
===Texture.txt Files===
+
 
+
You can provide your own texture.txt files 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.
+
 
+
==Warnings and Errors==
+
 
+
The TrainzDev team are reporting issues back to N3V and many problems have been fixed.  The following is provided to assist creators.
+
  
 +
==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]].
  
 
{|  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%  
  |+ Warnings
 
 
|- style="font-weight:bold; text-align:center;"
 
|- style="font-weight:bold; text-align:center;"
   ! width=40% style=" border:1px solid gray;"|Warning
+
   ! width=40% style=" border:1px solid gray;"|Warning/Error
 
   ! width=60% style=" border:1px solid gray;"|Help/Explanation
 
   ! width=60% style=" border:1px solid gray;"|Help/Explanation
 
|-
 
|-
   | style="border:1px solid gray;font-weight:normal;"|Phong shader not supported
+
   | 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 ignore this as Trainz uses its own shaders. The warning is supposed to be suppressed but still occurs in some circumstances
+
   | style="border:1px solid gray;font-weight:normal;"| You can ignore this warning.
 
|-
 
|-
   | style="border:1px solid gray;font-weight:normal;"|Number of polys exceeds 10,000 polys
+
   | 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;"|This is a standard TANE warning and not related to the FBX importer.
+
   | style="border:1px solid gray;font-weight:normal;"| You can ignore this warning.
 
|-
 
|-
   | style="border:1px solid gray;font-weight:normal;"|unused
+
   | style="border:1px solid gray;font-weight:normal;"|Error: Unable to determine vertex format.
   | style="border:1px solid gray;font-weight:normal;"|unused
+
   | 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;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;"|Error
+
  ! width=60% style=" border:1px solid gray;"|Help/Explanation
+
 
|-
 
|-
   | style="border:1px solid gray;font-weight:normal;"|LOD mesh poly counts are identical which triggers the 20% reduction error.  
+
   | 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;"| You need to select only those meshes that will be exported for a LOD and ensure that Selected Objects is selected.
+
   | 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;"|No meshes show in game or Preview Asset.
+
   | 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;"|This can occur for a number of reasons including material issues but ensure that your mesh has only one UV map.
+
   | 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;"|unused
+
  | style="border:1px solid gray;font-weight:normal;"|unused
+
 
|}
 
|}
  
  
 +
==Return to Index==
 +
 +
[[HowToGuides|<< How To Guides]]
  
==Materials==
+
[[Category:How-to guides]]
 
+
[[Category:Modeling]]
(This section may be moved to the Materials WiKi pages when the FBX importer is mature)
+
[[Category:Content creation]]
 
+
Treatment of materials is unchanged and no changes to existing textures are required.
+
 
+
===m.notex===
+
 
+
Currently there may be a problem with mixing NOTEX materials and other materials in the same export.  This is being investigated.
+
 
+
===m.onetex===
+
 
+
There are no special Blender settings for ONETEX materials.  A sample ONETEX material and texture setting is shown below.
+
 
+
(insert pics for onetex)
+
 
+
===m.reflect===
+
 
+
(TBD)
+
 
+
===m.gloss===
+
 
+
(TBD)
+
 
+
===m.tbumptex===
+
 
+
(TBD)
+
 
+
===m.tbumpenv===
+
 
+
(TBD)
+
 
+
===m.tbumpgloss===
+
 
+
(TBD)
+
 
+
==Exportable Attributes and TANE==
+
 
+
(table here)
+
 
+
 
+
 
+
(to be continued)
+

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