HowTo/Export from Blender using FBX

From TrainzOnline
< HowTo(Difference between revisions)
Jump to: navigation, search
(Materials)
Line 289: Line 289:
 
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.
 
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.
  
==Materials==
+
==Legacy Materials==
 
    
 
    
This section identifies the legacy material options used by the FBX exporter.  For detailed descriptions on how Trainz uses material types, including TRS18 PBR materials, see [[Material Types]] and the child pages detailing different Trainz material types.
+
This section identifies the legacy material options used by the FBX exporter (i.e. Pre-TRS18).  For detailed descriptions on how Trainz uses material types, including TRS18 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 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.

Revision as of 12:10, 24 January 2018

Contents

Introduction

This guide provides information for the export of FilmBoX (FBX) files from Blender.

Versions

TANE: 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 FBX Review and FBX Converter programs by Autodesk.

The FBX format

A brief discussion on the FBX format history can be found here . FBX can be exported, or imported, either as an ASCII (i.e. human readable) file or in binary format.

Blender and FBX

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 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 documentation contains a 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 TANE. The list is incomplete and will be updated when new information is available.

N3V use the ASSIMP Open Asset Import Library to extract asset model information from the FBX file. ASSIMP Version 3.3.1 appears to be FBX version 7.3 and the Blender FBX exporter exports FBX 7.4. This results in some warnings that appear to be generated by Content Manager but actually come from the ASSIMP process. If you get warnings that you cannot correct, such as those in the warnings section below, try running the Blender generated FBX file through the Autodesk FBX Converter program and choose FBX2013 as the target. These warnings do not appear to affect the outcome so this step may not be necessary.

TANE and the FBX Importer

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

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)

The FBX exporter addon must be enabled in User Preferences.

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 vary significantly between the Binary export version and the ASCII export version so make sure you have Binary selected.

The Main Menu

Blender FBX Main Menu.jpg
  • Ignore the Operator Presets for now.
  • Ensure FBX 7.4 binary version is selected.
  • The Main/Geometry/Armatures/Animation buttons provide menu options for the item selected. Select the Main option.
  • Selected Objects. This option needs careful consideration. Unlike the Blender XML exporter, the FBX exporter will export all objects in all layers

which is probably undesirable in many cases and particularly if you have different LOD models in different layers. So, first select those objects within Blender that you want to export and then select Selected Objects in this panel.

  • Scale. Leave the Scale value as 1.00 and deselect the small icon to the right of the Scale value. (See note below)
  • Forward and Up. Set these to the values :Y forward and Z Up.

The options below are multi select (i.e. you can select more than one). For the time being just leave Mesh selected.

  • Leave the Experimental and Custom Properties as deselected.
  • Leave Path Mode as Auto and Batch Mode as Off.
  • Choose the FBX filename and export using the Export FBX in the top right hand corner. There is no exporter log.

Note that Blender 2.79 introduced some options for scaling that need some investigation. Recommend using "FBX All" until this has been investigated.

Tip

You can save your preferences for a given situation by clicking on the plus button (+) next to Operator Presets and saving the preset with a name. This is particularly useful for animation. You will need to reload the preset each time you start Blender.

The Geometry Menu

FBX Geometry Menu.jpg
  • Leave these values as shown.

The Armatures and Animation Menus

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 commit. Currently the FBX file is not deleted but bundled into the asset. Since the FBX format is readable by 3D modelling tools, you may want to remove any FBX files from assets uploaded to the DLS or other web sites.

Texture.txt files

You can provide your own texture.txt files (advisable) or let the commit process create them for you. The commit process will create suitable files, such as those required for normal maps, but you can provide your own if you have special requirements.

Warning: If you get odd effects with your textures, check the associated texture.txt file first. The FBX importer tends to add an "alpha=" line even though no alpha option has been chosen. This may be an issue with the Blender FBX exporter.

PEV's TextureTXT utility can be very useful for creating texture.txt files and its worth adding it into AssetX if you use AssetX for managing your projects.

Double Sided Meshes

It appears that FBX does not support double sided meshes so you need to create a metadata file as described at FBX file format#Mesh Metadata Files. Note that this is done per material. i.e. you cannot have the same material for single sided and double sided meshes.

Self Illuminated Meshes

Meshes that require self illumination require a separate material with the Shader->Emit value set to a value other than 0. A value of 1.0 is recommended. The Blender exporter also exports an emissive colour using the diffuse colour value. It is not known if TANE uses the emissive colour. You might also experiment with the specular values.

General warnings and errors

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

Warning/Error Help/Explanation
Warning: T16080: ...shading mode not recognised: Phong 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.
Warn, T15808: FBX-DOM (TOK_KEY, offset 0xnnnn) source object for connection does not exist 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.
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, T9068 Failed to triangulate polygon (no ear found). Probably not a simple polygon. This follows a previous info "All polygons triangulated" The exact cause of this problem is unknown but recommend using a mesh edit tool to triangulate all polygons.
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.

Level of Detail (LOD)

The rules for Level of Detail for FBX models are the same as indexed mesh (IM) models except for the use of the Trainzmesh suffix for mesh files.

Mesh-Table Method

This is a very simple scenery model of a coloured ball using three levels of LOD: File:6000101 - FBX - LOD mesh-table test1.zip. The Blender source is provided.

LM.TXT Method

(TBD)

Animation

Overview

Trainz will not animate a mesh without the use of helper points using the "b.r" notation. For Blender, those helper points can be armatures (bones) or empties. Lattices are not supported by the FBX exporter.

An animation must have a root helper normally called "b.r.main" although "b.r.root" will also work. Using such names helps identify the overall parent of the animation. Other animation helpers are called "b.r.xxx", where "xxx" can be any name. These helpers must be children of the main/root helper.

Exporting an animated mesh object

The Main Menu

Blender FBX export main-anim.jpg
  • Select Empty and Armature depending on how you set up your animation.
  • Other options are described above.

The Armatures Menu

FBX Armatures Menu.jpg
  • Use the values as shown.

The Animation Menu

Blender FBX anim menu1.jpg
  • 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.

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

Warning/Error Help/Explanation
! ... T14120: Simplified dummy tracks with just one key. Not sure what this warning is about but the animation is OK.
! ... Skipping one or more lines with the same contents 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-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

A Sample Steam Piston Animation

File:Bsa.zip

Circle guided steam animation.jpg

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. Pre-TRS18). For detailed descriptions on how Trainz uses material types, including TRS18 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:

Material Option Shader Comment
Diffuse -> Color Any Used for both diffuse and emissive colour
Diffuse -> Intensity Any Factor applied to diffuse colour
Shading -> Emit Any Factor applied to emissive colour
World -> Ambient_Color Any Not sure what effect this may have, if any, on the exported result. See also Shading -> Ambient.
Shading -> Ambient Any Amount of global ambient colour the material receives.
Transparency Any Use transparency if checked.
Transparency -> Alpha Any Transparency (opacity) factor.
Specular -> Color Phong
Specular -> Intensity Phong
Specular -> Hardness Phong Shininess
Mirror -> Color Phong Mirror must be checked.
Mirror -> Reflectivity Phong 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:

Texture Option Comment
Texture name Can be any name but recommend names such as Diffuse, Normal or similar to identify purpose.
Texture type Must be "Image or movie"
Image -> Name Filename of image.
Image -> Use Alpha Tick if alpha channel is to be used.
Image -> Alpha Mode This value is exported but probably not used by Trainz so leave it as "straight".
Mapping -> Coordinates Use UV, Normal or Reflection
Mapping -> Map UV map name
Image Mapping -> Extension Use Repeat if UV wrapping required. Probably only of value within Blender since Trainz texture.txt files define image wrapping.

Return to Index

<< How To Guides

Personal tools