HowTo/Export from Blender using FBX

From TrainzOnline
< HowTo(Difference between revisions)
Jump to: navigation, search
(Major rewrite of this page. More to come.)
Line 1: Line 1:
 +
(THIS IS A WORK IN PROGRESS)
  
==Introduction==
+
This page describes how to export a simple model from Blender 2.79 and 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 guide provides information for the export of FilmBoX (FBX) files from Blender.  
+
Some knowledge of using Blender and Trainz asset creation is assumed.
  
===Versions===
+
[[File:B279_model.jpg|500px|left]] {{clear}}
  
{| class="wikitable"
+
=Video Tutorial=
  
|-
+
A video tutorial can be found at [https://www.youtube.com/watch?v=qTXgaNOETF0 Exporting basic Cube from Blender with PBR Materials].  
|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 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. 
+
=Asset Creation Workflow=
  
==Blender and FBX==
+
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.
  
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 Trainz.  Note that work on the Blender ASCII importer/exporter is frozen.
+
The provided Blender models are ready for you to do steps 3 through 6. Step 4 is ignored.
  
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.
+
=Exporting in Blender 2.79b=
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.
+
Set up the source files. They can be found here [[File:Mycube 279.zip]]
 +
:*  Load the provided Blender sources files into a Trainz asset project folder (directory). The source files include a Blender model file (mycube_279.blend), three images (textures) for the material, the texture description files, and an incomplete config.txt.
 +
:* Using a plain ASCII text editor, edit the config.txt and add your own asset kuid.
  
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.
+
==Loading the Blender Source Model==
 +
:*  Start Blender.
 +
:*  Open the provided Blender source file.  The model has one mesh: mycube_lod0 in layer 0.  
 +
:* The model is set up for Blender Render mode.
 +
:*  The mesh is UV mapped but has no material.
  
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.4This 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.
+
==Materials and Textures==
+
:* Create a new material called “mycube.m.pbrmetal”There is no need to change any other material settings. More information on Materials can be found here:
==TANE and the FBX Importer==
+
http://online.ts2009.com/mediaWiki/index.php/Material_Types
A discussion of the FBX format and general guidelines for use with TANE is discussed at this Trainz WiKi page:  [[FBX  file format]]
+
  
==Skills Required==
+
[[File:B279_FBX_PBRMetal_asset_material.jpg|400px|left]] {{clear}}
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.  
+
  
==Exporting a mesh object from Blender in FBX format (no animation)==
+
===Albedo Texture===
 +
:*  Add a new texture slot called “albedo”.  The name itself is not significant but it is useful to use a name that reflects its purpose.
 +
:*  Set the texture type to Image or Movie and load the image MyCube_albedo.png.
 +
:*  Uncheck Use Alpha.
 +
:*  Set the Mapping Coordinates to UV and select map UVMap.
 +
:*  Within the Influence Section check Diffuse->Color
  
The FBX exporter addon must be enabled in User Preferences.
+
[[File:B279_FBX_PBRMetal_asset_albedo.jpg|400px|left]] {{clear}}
  
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
+
===Normal Texture===
vary significantly between the Binary export version and the ASCII export version so make sure you have Binary selected.
+
:*  Add a new texture slot called “normal”. 
 +
:*  Set the texture type to Image or Movie and load the image MyCube_normal.png.
 +
:* Check Use Alpha since the provided normal texture uses a height map in the alpha channel.
 +
:*  Set the Mapping Coordinates to UV and select map UVMap.
 +
:*  Within the Influence Section check Geometry->Normal.  There is no need to set a value since the FBX exporter ignores it.  Make sure no other options, such as Diffuse->Color, are selected.
 +
[[File:B279_FBX_PBRMetal_asset_normal.jpg|400px|left]] {{clear}}
  
===The Main Menu===
+
===Parameter Texture===
[[File:Blender_FBX_Main_Menu.jpg|380px|left]]
+
:*  Add a new texture slot called “parameter”.
* Ignore the Operator Presets for now.
+
:* Set the texture type to Image or Movie and load the image MyCube_parameter.png.
* Ensure FBX 7.4 binary version is selected.
+
:Check Use Alpha since the parameter texture has an alpha channel (metallicity).
* The Main/Geometry/Armatures/Animation buttons provide menu options for the item selected. Select the Main option.
+
:Set the Mapping Coordinates to UV and select map UVMap.
* Selected Objects. This option needs careful consideration.  Unlike the Blender XML exporter, the FBX exporter will export all objects in all layers
+
:Within the Influence Section check Specular->Hardness. This is the indication to Trainz that this texture is used for the parameter texture.  Make sure nothing else is checked in Influence.
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
+
[[File:B279_FBX_PBRMetal_asset_parameter.jpg|400px|left]] {{clear}}
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.
+
==Exporting to FBX==
* Leave Path Mode as Auto and Batch Mode as Off.  
+
The model is now ready for export.
* Choose the FBX filename and export using the Export FBX in the top right hand corner.  There is no exporter log.
+
:* Select the mesh object in the 3D window (right click)
{{clear}}
+
:*  Select File->Export->Export FBX and the FBX export panel will show in the bottom left hand corner of the windowIf 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.  
Note that Blender 2.79 introduced some options for scaling that need some investigationRecommend using "FBX All" until this has been investigated.
+
:*  Scale:  Leave the scale value at 1.0 and make sure the small button to the right of the scale is unchecked.
 
+
:*  Version: Select FBX 7.4 binary.
====Tip====
+
:*  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.
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.
+
:*  For Main options:
 
+
:*:*  Check Selected Objects.  This exports all objects on visible layers.
===The Geometry Menu===
+
:*:*  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:FBX Geometry Menu.jpg|380px|left]]  
+
[[File:B279 FBX export panel1.jpg|400px|left]]  
* Leave these values as shown.
+
 
{{clear}}
 
{{clear}}
  
===The Armatures and Animation Menus===
+
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.
  
* See the [http://online.ts2009.com/mediaWiki/index.php?title=HowTo/Export_from_Blender_using_FBX&action=submit#Animation Animation Section].
+
==Importing into Trainz==
{{clear}}
+
===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.
===Config.txt - simple model===
+
 
+
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.
+
=Exporting in Blender 2.80=
 
+
===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)
 
(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 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%
 
|- 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;"|This is an ASSIMP message and can be ignored.
 
|}
 
 
===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-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 result.  See 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 colour.  Check/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 Reflection.  Reflection makes the model look correct in Blender but makes no difference to TANE.
 
In the Texture Influence->Diffuse section, check both Color and Mirror.  Don'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 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.
 
|}
 
 
==Video Tutorials==
 
Exporting basic Cube from Blender with PBR Materials:
 
 
[https://www.youtube.com/watch?v=qTXgaNOETF0 Video]
 
  
 
==Return to Index==
 
==Return to Index==

Revision as of 17:36, 9 April 2019

(THIS IS A WORK IN PROGRESS)

This page describes how to export a simple model from Blender 2.79 and 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.

B279 model.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 in Blender 2.79b

Set up the source files. They can be found here File:Mycube 279.zip

  • Load the provided Blender sources files into a Trainz asset project folder (directory). The source files include a Blender model file (mycube_279.blend), three images (textures) for the material, the texture description files, and an incomplete config.txt.
  • Using a plain ASCII text editor, edit the config.txt and add your own asset kuid.

Loading the Blender Source Model

  • Start Blender.
  • Open the provided Blender source file. The model has one mesh: mycube_lod0 in layer 0.
  • The model is set up for Blender Render mode.
  • The mesh is UV mapped but has no material.

Materials and Textures

  • Create a new material called “mycube.m.pbrmetal”. There is no need to change any other material settings. More information on Materials can be found here:

http://online.ts2009.com/mediaWiki/index.php/Material_Types

B279 FBX PBRMetal asset material.jpg

Albedo Texture

  • Add a new texture slot called “albedo”. The name itself is not significant but it is useful to use a name that reflects its purpose.
  • Set the texture type to Image or Movie and load the image MyCube_albedo.png.
  • Uncheck Use Alpha.
  • Set the Mapping Coordinates to UV and select map UVMap.
  • Within the Influence Section check Diffuse->Color
B279 FBX PBRMetal asset albedo.jpg

Normal Texture

  • Add a new texture slot called “normal”.
  • Set the texture type to Image or Movie and load the image MyCube_normal.png.
  • Check Use Alpha since the provided normal texture uses a height map in the alpha channel.
  • Set the Mapping Coordinates to UV and select map UVMap.
  • Within the Influence Section check Geometry->Normal. There is no need to set a value since the FBX exporter ignores it. Make sure no other options, such as Diffuse->Color, are selected.
B279 FBX PBRMetal asset normal.jpg

Parameter Texture

  • Add a new texture slot called “parameter”.
  • Set the texture type to Image or Movie and load the image MyCube_parameter.png.
  • Check Use Alpha since the parameter texture has an alpha channel (metallicity).
  • Set the Mapping Coordinates to UV and select map UVMap.
  • Within the Influence Section check Specular->Hardness. This is the indication to Trainz that this texture is used for the parameter texture. Make sure nothing else is checked in Influence.
B279 FBX PBRMetal asset parameter.jpg


Exporting to FBX

The model is now ready for export.

  • Select the mesh object in the 3D window (right click)
  • 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.
  • Version: Select FBX 7.4 binary.
  • 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. This exports all objects on visible layers.
    • 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.
B279 FBX export panel1.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.

Exporting in Blender 2.80

(TBD)


Return to Index

<< How To Guides

Personal tools