HowTo/Export Blender FBX Animation

From TrainzOnline
< HowTo(Difference between revisions)
Jump to: navigation, search
(First version)
 
Line 1: Line 1:
  
This page describes a process for exporting animated meshes from Blender to the [[FBX file format]].   Currently, it only describes Blender 2.79 and Blender 2.80 will be added later.
+
This page describes a process for exporting animated meshes from Blender to the [[FBX file format]]. It is intended for new content creators or those more experienced who need to migrate from older versions of Blender and Trainz animation.
  
 
You should be familiar with Blender FBX export as described here [[HowTo/Export from Blender using FBX]]
 
You should be familiar with Blender FBX export as described here [[HowTo/Export from Blender using FBX]]
  
This tutorial is for Trainz Build 4.6.
+
This tutorial is for Trainz Build 4.6 and Blender 2.80.
  
 
=Overview=
 
=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 or empties, or both.  Lattices are not supported by the FBX exporter.
+
==Trainz Animation==
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 in Blender 2.79b=
+
Set up the source files. They can be found here [[File:Mycube animated.zip]]
+
:*  Load the provided Blender sources files into a Trainz asset project folder (directory).  The source files include a Blender model file (mycube_animated_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==
+
In Blender you can animate meshes but that animation is not recognised by TrainzTrainz only recognises animation helper objects that it calls bonesA bone, for Trainz purposes, is an animated helper object using a "b.r." notation.
:*  Start Blender 2.79.
+
Meshes are attached to bones in a parent-child relationship where the child is the meshWhen the parent bone moves in 3D space, the child mesh moves with itIn Trainz you cannot see the animated bones but you can see the mesh.
:* Open the provided Blender source fileThe model has one mesh: mycube_lod0 in layer 0 and an empty called “b.r.main” as an animation helper.
+
:*  The model is set up for Blender Render mode.
+
:* The mesh is UV mapped and has a material called mycube.m.pbrmetalThere is no need to change the material or textures.
+
  
==Animation==
+
Animation helpers in Blender can be armatures or empties. Lattices cannot be used since FBX doesn't recognise them.  
We will now animate the cube to rotate in the Z axis.
+
:* Set the 3D View Window display to wireframe. This isn’t necessary but makes things easier to see.
+
:* In the Timeline Window at the bottom of the screen, change the start frame to 1 and the end frame to 60. This makes the animation sequence run for 60 frames and, given the standard Trainz frame rate is 30 frames per second, the animation will run for 2 seconds.
+
[[file:B279 animation timeline panel.jpg|400px]left]]
+
:* Select the empty b.r.main.
+
:* Ensure the current frame is 1 and press the I key to bring up the Keyframe Menu.  Select Rotation. 
+
:* If you look at the 3D Windows Properties Panel, the Transform->Rotation values should have a coloured background usually yellow.  This signifies that a keyframe exists for the selected object at this frame position.
+
:* In the TimeLine Window, change the current frame to the last frame which is 60.  You can use the jump to last frame icon >>I or just manually set the value to 60.
+
:* In the 3D Windows ->Properties panel Transform->Rotation panel, set the Z value to -360.
+
:* Press the I key to bring up the Keyframe Menu and select rotation.  
+
  
Let’s recap what we have doneWe have set the animation playback range to operate between frame 1 and frame 60This equates to a 2 second animationWe then added a start animation rotation keyframe to the object b.r.main while the object had a Z axis rotation of 0We then added an end rotation keyframe to b.r.main with a Z axis rotation of -360.
+
=Examples=
360 degrees is the same as 0 degrees, but we can’t use 0 for the endframe as this will not cause any rotationA value of -360 causes the rotation to be clockwise and 360 will make it anti-clockwise.
+
Here are a number of example animationsEach example is provided with source files but only the first example is fully explained.
 +
==Example 1 - A Revolving Sphere==
 +
This example is a very basic animation of a sphere using an empty as the animation helper.  The Blender file consists of a sphere located at grid centre and at elevation 2 (metres). The sphere has a PBR material and a simple UV map.
 +
Your task is add the animation helper, add the rotation animation, export to FBX and import into Trainz.
 +
===Load Example 1===
 +
:* On your computer, create a project folder called "anim_example_1" or whatever name suits you.
 +
:* Download the source files from here: [[File:Ex1 export.zip]]
 +
:* The source file is in zip format so extract it into the project folderThe source includes:
 +
  example1_start.blend;
 +
  example1_completed.blend;
 +
  ex1_albedo.png
 +
  ex1_albedo.texture.txt
 +
  ex1_normal.png
 +
  ex1_normal.texture.txt
 +
  ex1_parameter.png
 +
  ex1_parameter.texture.txt
 +
  thumbnail_0.jpg
 +
  config.txt
 +
:* The config.txt is complete but you will need to change the asset kuid to be one of your own.
 +
:* Open the ex1_example.blend Blender source file in Blender 2.8It should look similar to the following.  If the sphere is a pink/purple colour then that means Blender can't find the material textures.  You should be able to correct that by reloading the textures within Blender.
 +
[[File:Ex1 start.jpg|1200px|thumb|center|The Start Layout]]
 +
:* Save the file as "ex1_working.blend".
 +
===Add the Trainz Animation Helper===
 +
:* Position the Blender cursor at World Origin (0,0,0). Press Shift S to bring up the Snap menu and select Cursor to World Origin.
 +
:* Add an empty at the cursor location. Use menu Add->Empty->Arrows.  Shift A should also work.
 +
:* Double click on the new Empty in the Properties Editor and rename it to "b.r.main".
 +
:* Move the b.r.main helper into the Animation collectionYou can either drag and drop it in the Properties Window or the menu Object->Collection->Move to Collection.  Having a collection name Animation makes it easier to export different LOD meshes.
 +
===Animate the Trainz Helper===
 +
:* Change to the Animation Workspace and ensure the b.r.main object is selected.  You will need to use the object's Context values that are shown at the bottom right - location, rotation, scale, etc.
 +
[[File:Blender280 anim example1- view1.jpg|1200px|thumb|center|B.R.Main]]
 +
:* For animation we use keyframes (aka frames) to manage our animation.  Trainz operates animations at 30 frames per second (fps) and, as we want to run this animation for two seconds, the End Frame in Timeline should be 60.  Make sure the Start Frame is 1 and the Current Keyframe is 1.  See the following image.
 +
[[File:Blender280 anim example1- view2.jpg|1200px|thumb|center|Animation timeline]]
 +
:* Select the b.r.main helper if not already selected.
 +
:* For the start of our animation we need to set the rotation of our helper to be at 0 (zero) degrees.  For this example we can just leave the helper as Blender placed it..
 +
:* Press the I key and select Rotation.  This creates a frame with just rotation data which, in this case, is 0.  You will see a keyframe indicator appear at frame 1 in Timeline and, if you are using the Animation workspace, you will also see entries appear in both the Dope Sheet and Graph editors.
 +
:* Change the Current frame in Timeline to the last keyframe (6)You can click on frame 60 in Timeline, manually change the current frame number or use the "Jump to end" icon in Timeline.
 +
:* At the end of our animation we want the helper to have completed one full rotation of 360 degrees so select the helper and, in the Properties Window->Context, change the Z Rotation value to 360. The result should look like the following:
 +
<br>
 +
[[File:Setting the rotation.jpg|400px|thumb|left|Setting the rotation]]
 +
<br>
  
:* Press the Play icon in the TimeLine WindowYou will see the empty rotating.
+
:* Press the I key and select RotationThis sets the final keyframe.
:* Press the Stop icon and the Go to Beginning icon so that the current frame is 1.
+
:* Test out the animation by clicking on the Forward and Reverse icons in Timeline. When finished reset the animation by stopping it first and then selecting the Start Endpoint icon.  Note that the sphere is not moving yet.
Now we will animate the cube mesh.    We do this by making the mesh a child of the animation helper so there is a parent->child relationship.
+
:* Select the mesh (mycube_lod0).
+
:* Hold the shift key and select the empty (b.r.main).
+
:* Press Ctrl P and then Set Parent To -> Object (Keep Transform).
+
If you press the Play icon in the TimeLine Window, the cube should rotate with the emptyThe parent->child relationship means the mesh must follow the empty.
+
  
=Exporting to FBX=
+
===Review===
==The Main FBX Export Menu==
+
So far we have created the helper with a correct name that Trainz will recognise for animation.  We have set the animation to compete one full circle in the Z axis in 60 keyframes and, since we are using 30fps, the animation will run for 2 seconds.
:*  Select all objects in the 3D window (A key toggle)
+
The use of the value 360 is somewhat of a trick to make sure that Blender animates the helper through 360 degrees.  Although 360 is essentially the same as 0, if you left it at 0 then no animation would take place even though keyframs exist.  Try a zero value and see what happens or rather what doesn't happen.
:*  Select File->Export->Export FBX and the FBX export panel will show in the bottom left hand corner of the window.
+
Using the value of 360 means that the helper will rotate 360 degrees in the anti-clockwise direction.  If you want clockwise motion then change the value to -360.
:* Select Empty and MeshThe empty has the animation so it must be selected along with the mesh for animation to be included in the FBX file.
+
===Smoothing the Animation===
:* Select the other options as shown in the following image. These options are described here [[HowTo/Export from Blender using FBX]].
+
While watching the animation you may have noticed that the animation pauses briefly between the end and restart of the animation.  There is no time gap but this indicates that the animation is not following a linear path but one using an "F curve".  These pauses may be noticeable in game except for bogie animations where the animation is dynamically managed by the game engine.
[[File:B279 export main panel animated.jpg|380px|left]]  
+
Within Blender this characteristic is known as the extrapolation mode of the animation channel.  By default Blender uses an F curve that resembles a Bezier curve.  For many Trainz animations you may want a continuous animation and that means the Linear Extrapolation.  Note that there is a Constant Animation but that may not give the same result as it essentially freezes the animation between keyframes. 
{{clear}}
+
:* Change the workspace to Animation if not there already.
 +
:* In the Graph Editor or the Dope Sheet Editor, select menu Channel>Extrapolation Mode>Linear Extrapolation.
 +
:* Run the animation again and there should be no pauses.
 +
[[File:Linear extrapolation.jpg|400px|thumb|left|Changing to linear extrapolation]]
 +
For more information on Blender animation channel extrapolation see [https://docs.blender.org/manual/en/latest/editors/graph_editor/fcurves/introduction.html]
 +
===Animating the mesh objects===
 +
:* As stated earlier you cannot animate the meshes directly but you can make them follow the animation helper. We do this by making the mesh a child of the helper.
 +
:* There are two meshes to animated: the LOD0 and LOD1 meshes.
 +
:* Enable viewing of both the LOD0 and LOD1 mesh by ticking the two collections.
 +
:* Select the objects sphere_lod0, sphere_lod1 and finally b.r.main.  The help must be selected last.
 +
:* In the 3D window, press Ctrl P>Object (Keep Transform).
 +
:* Test the animation by starting the animation and showing or hiding the two mesh objects.
 +
:* Save your work.
 +
===Exporting the Animation===
 +
The animation data for the helper(s) as well as the parent/child relationships are exported within the FBX file. The Trainz FBX importer will extract the animation data and store it in a KIN file.  Since we have two LOD meshes this means that the importer will create two KIN files but with slightly different names.  As the animation is the same for both meshes you can use just one of the KIN files and delete the other.  Or you can use both.
 +
Blender's FBX exporter will export each animation channel it finds and this can result in multiple KIN files for each mesh.  This doesn't work well if at all.  The solution is to use what is called a baked animation where all the channels and keyframes are "baked" together.  This is actually inefficient for Trainz purposes but is the only answer that currently works reliably.
 +
====Exporting LOD0 Animation====
 +
:* Disable viewing of the LOD1 meshes by unclicking the LOD1 collection.
 +
:* Enable both the LOD0 and Animation collections.
 +
:* In the 3D Editor select all objects using the A keyYou may need to press it twice.
 +
[[File:Exporting LOD0.jpg|400px|thumb||LOD0 FBX Objects Collections]]
 +
:* Go to the File menu and select Export>FBX.
 +
:* The default options will not work for us so we need to change a few things:
 +
:* For the Main tab:
 +
:* Check Selected Objects.
 +
:* Scale - either change the scale value to 0.01 and have the adjacent icon selected, or leave the scale at 1.00 and deselect the icon. (VALIDATE)
 +
:* Apply Scale - use FBX All.
 +
:* Forward - use Y forward
 +
:* Up - Z up.
 +
:* The next area lists those objects to be exported.  In this case we want Empty and Mesh.
 +
:* Leave the other options at their default value.
 +
:* For the Animation tab:
 +
:* Check Baked Animation.
 +
:* Uncheck all other options. For this example we don't care about the other tabs but suggested values are shown in the next set of images.
 +
[[File:Fbx main.jpg|300px|thumb||Main Tab]][[File:FBX geometry.jpg|300px|thumb||Geometry Tab]][[File:FBX armature.jpg|300px|thumb||Armatures Tab]][[File:FBX animation.jpg|300px|thumb||Animation Tab]]
  
==The Animation Menu==
+
:* In the output filename space enter ex1_lod0.fbx and click on the Export FBX icon at the top right.
:* Select the Animation option in the Export FBX panel.
+
====Exporting LOD1 Animation====
[[File:Blender FBX anim menu1.jpg|380px|left]] {{clear}}
+
:* Uncheck the LOD0 collection.
:* Select Baked Animation and disable the other options.
+
:* Check the LOD1 collection.
Authors note: This is completely different from the process described in the 3DS Max FBX animation export.
+
:* Leave the Animation collection checked.
If Baked Animation is not ticked, then none of the other animation options are availableSo far, none of those other options have been found useful.
+
:* Repeat the LOD0 process only changing the output name to ex1_lod1.fbxYou shouldn't need to change any of the export settings unless you restarted Blender.
{{clear}}
+
[[File:Exporting LOD1.jpg|400px|thumb||LOD1 FBX Objects Collections]]
  
==Export to FBX==
 
The animated model is now ready for export.
 
:* Change the export filename to be “mycube.fbx”.
 
:* Click on the Export FBX button at the top right. The mesh and animation will be exported.
 
  
=Setting up the Asset=
+
===Setting up the Asset in Trainz===
 
The FBX file contains both the mesh and the b.r.main empty plus the animation data.  When the FBX file is imported into Trainz, an animation file (KIN) is created in addition to the Trainzmesh file.
 
The FBX file contains both the mesh and the b.r.main empty plus the animation data.  When the FBX file is imported into Trainz, an animation file (KIN) is created in addition to the Trainzmesh file.
The name of the kin file depends on the options chosen within the Export FBX->Animation panel.  If you choose the Baked Animation option, then the kin filename will be the mesh name plus “_scene.kin”.  In this instance, the kin filename will be “mycube_scene.kin”.
+
The name of the kin file depends on the options chosen within the Export FBX->Animation panel.  If you choose the Baked Animation option, then the kin filename will be the mesh name plus “_scene.kin”.  In this instance, the kin filenames will be “ex1_lod0_scene.kin” and “ex1_lod1_scene.kin”.   
:Warning: Not choosing the Baked Animation option can result in several KIN files being createdThese files will be named for the animation channel names within Blender.
+
  This option is not recommended.
+
 
   
 
   
  
==Config.txt==
+
====Config.txt====
 
The names of mesh and KIN files may not be obvious so you may need to create some dummy names for your mesh and KIN files.  After importing into Trainz, open the asset for editing and look for the files created.  Then go back and correct entries in the config.txt.  You can always rename the kin file to a simpler name.
 
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 Trainz, open the asset for editing and look for the files created.  Then go back and correct entries in the config.txt.  You can always rename the kin file to a simpler name.
 
For this asset the mesh table will look like this:
 
For this asset the mesh table will look like this:
  
mesh-table {
+
mesh-table {
 
   lod_0 {
 
   lod_0 {
     mesh                                  "mycube.trainzmesh"
+
     mesh                                  "ex1_lod0.trainzmesh"
 
     auto-create                          1
 
     auto-create                          1
 
     lod-level                            0
 
     lod-level                            0
     anim                                  "mycube_scene.kin"
+
     anim                                  "ex1_lod0_scene.kin"
 +
    animation-loop-speed                  1.00
 +
  }
 +
  lod_1 {
 +
    mesh                                  "ex1_lod1.trainzmesh"
 +
    auto-create                          1
 +
    lod-level                            1
 +
    anim                                  "ex1_lod1_scene.kin"
 
     animation-loop-speed                  1.00
 
     animation-loop-speed                  1.00
 
   }
 
   }
 
}
 
}
==Correcting the Rotation (optional)==
 
You may have noticed that the animation of this sample asset is not constant in either Blender or within Trainz.  i.e. it rotates and then pauses before continuing.  This is caused by the default extrapolation mode applied to the animation before the first and after the last keyframes.
 
In some cases, such as loco drivers, this doesn’t matter because Trainz controls the animation.  However, in animations such as the sample asset this may need correcting.
 
:* Within Blender, change the view of one window to the Graph Editor.
 
:* Select Channel at the bottom of the window, then Extrapolation Mode, then Linear Extrapolation as shown in the following image.
 
  
 +
===Asset in game===
  
[[file:B279 changing extrapolation mode.jpg|1200px|left]] {{clear}}
+
[[File:Ex1 in game.jpg|400px|thumb||Example 1 in Trainz]]
 
+
  
  
Line 112: Line 157:
  
  
 
+
(more examples to come)
=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 Animations==
+
===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, Trainz 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, Trainz 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.
+
  
  
Line 186: Line 164:
 
   
 
   
 
[[HowToGuides|<< How To Guides]]
 
[[HowToGuides|<< How To Guides]]
 
 
[[Category:How-to guides]]
 
[[Category:How-to guides]]
 
[[Category:Modeling]]
 
[[Category:Modeling]]
 
[[Category:Content creation]]
 
[[Category:Content creation]]

Revision as of 18:33, 26 August 2019

This page describes a process for exporting animated meshes from Blender to the FBX file format. It is intended for new content creators or those more experienced who need to migrate from older versions of Blender and Trainz animation.

You should be familiar with Blender FBX export as described here HowTo/Export from Blender using FBX

This tutorial is for Trainz Build 4.6 and Blender 2.80.

Contents

Overview

Trainz Animation

In Blender you can animate meshes but that animation is not recognised by Trainz. Trainz only recognises animation helper objects that it calls bones. A bone, for Trainz purposes, is an animated helper object using a "b.r." notation. Meshes are attached to bones in a parent-child relationship where the child is the mesh. When the parent bone moves in 3D space, the child mesh moves with it. In Trainz you cannot see the animated bones but you can see the mesh.

Animation helpers in Blender can be armatures or empties. Lattices cannot be used since FBX doesn't recognise them.

Examples

Here are a number of example animations. Each example is provided with source files but only the first example is fully explained.

Example 1 - A Revolving Sphere

This example is a very basic animation of a sphere using an empty as the animation helper. The Blender file consists of a sphere located at grid centre and at elevation 2 (metres). The sphere has a PBR material and a simple UV map. Your task is add the animation helper, add the rotation animation, export to FBX and import into Trainz.

Load Example 1

  • On your computer, create a project folder called "anim_example_1" or whatever name suits you.
  • Download the source files from here: File:Ex1 export.zip
  • The source file is in zip format so extract it into the project folder. The source includes:
  example1_start.blend;
  example1_completed.blend;
  ex1_albedo.png
  ex1_albedo.texture.txt
  ex1_normal.png
  ex1_normal.texture.txt
  ex1_parameter.png
  ex1_parameter.texture.txt
  thumbnail_0.jpg
  config.txt
  • The config.txt is complete but you will need to change the asset kuid to be one of your own.
  • Open the ex1_example.blend Blender source file in Blender 2.8. It should look similar to the following. If the sphere is a pink/purple colour then that means Blender can't find the material textures. You should be able to correct that by reloading the textures within Blender.
The Start Layout
  • Save the file as "ex1_working.blend".

Add the Trainz Animation Helper

  • Position the Blender cursor at World Origin (0,0,0). Press Shift S to bring up the Snap menu and select Cursor to World Origin.
  • Add an empty at the cursor location. Use menu Add->Empty->Arrows. Shift A should also work.
  • Double click on the new Empty in the Properties Editor and rename it to "b.r.main".
  • Move the b.r.main helper into the Animation collection. You can either drag and drop it in the Properties Window or the menu Object->Collection->Move to Collection. Having a collection name Animation makes it easier to export different LOD meshes.

Animate the Trainz Helper

  • Change to the Animation Workspace and ensure the b.r.main object is selected. You will need to use the object's Context values that are shown at the bottom right - location, rotation, scale, etc.
B.R.Main
  • For animation we use keyframes (aka frames) to manage our animation. Trainz operates animations at 30 frames per second (fps) and, as we want to run this animation for two seconds, the End Frame in Timeline should be 60. Make sure the Start Frame is 1 and the Current Keyframe is 1. See the following image.
Animation timeline
  • Select the b.r.main helper if not already selected.
  • For the start of our animation we need to set the rotation of our helper to be at 0 (zero) degrees. For this example we can just leave the helper as Blender placed it..
  • Press the I key and select Rotation. This creates a frame with just rotation data which, in this case, is 0. You will see a keyframe indicator appear at frame 1 in Timeline and, if you are using the Animation workspace, you will also see entries appear in both the Dope Sheet and Graph editors.
  • Change the Current frame in Timeline to the last keyframe (6). You can click on frame 60 in Timeline, manually change the current frame number or use the "Jump to end" icon in Timeline.
  • At the end of our animation we want the helper to have completed one full rotation of 360 degrees so select the helper and, in the Properties Window->Context, change the Z Rotation value to 360. The result should look like the following:


Setting the rotation


  • Press the I key and select Rotation. This sets the final keyframe.
  • Test out the animation by clicking on the Forward and Reverse icons in Timeline. When finished reset the animation by stopping it first and then selecting the Start Endpoint icon. Note that the sphere is not moving yet.

Review

So far we have created the helper with a correct name that Trainz will recognise for animation. We have set the animation to compete one full circle in the Z axis in 60 keyframes and, since we are using 30fps, the animation will run for 2 seconds. The use of the value 360 is somewhat of a trick to make sure that Blender animates the helper through 360 degrees. Although 360 is essentially the same as 0, if you left it at 0 then no animation would take place even though keyframs exist. Try a zero value and see what happens or rather what doesn't happen. Using the value of 360 means that the helper will rotate 360 degrees in the anti-clockwise direction. If you want clockwise motion then change the value to -360.

Smoothing the Animation

While watching the animation you may have noticed that the animation pauses briefly between the end and restart of the animation. There is no time gap but this indicates that the animation is not following a linear path but one using an "F curve". These pauses may be noticeable in game except for bogie animations where the animation is dynamically managed by the game engine. Within Blender this characteristic is known as the extrapolation mode of the animation channel. By default Blender uses an F curve that resembles a Bezier curve. For many Trainz animations you may want a continuous animation and that means the Linear Extrapolation. Note that there is a Constant Animation but that may not give the same result as it essentially freezes the animation between keyframes.

  • Change the workspace to Animation if not there already.
  • In the Graph Editor or the Dope Sheet Editor, select menu Channel>Extrapolation Mode>Linear Extrapolation.
  • Run the animation again and there should be no pauses.
Changing to linear extrapolation

For more information on Blender animation channel extrapolation see [1]

Animating the mesh objects

  • As stated earlier you cannot animate the meshes directly but you can make them follow the animation helper. We do this by making the mesh a child of the helper.
  • There are two meshes to animated: the LOD0 and LOD1 meshes.
  • Enable viewing of both the LOD0 and LOD1 mesh by ticking the two collections.
  • Select the objects sphere_lod0, sphere_lod1 and finally b.r.main. The help must be selected last.
  • In the 3D window, press Ctrl P>Object (Keep Transform).
  • Test the animation by starting the animation and showing or hiding the two mesh objects.
  • Save your work.

Exporting the Animation

The animation data for the helper(s) as well as the parent/child relationships are exported within the FBX file. The Trainz FBX importer will extract the animation data and store it in a KIN file. Since we have two LOD meshes this means that the importer will create two KIN files but with slightly different names. As the animation is the same for both meshes you can use just one of the KIN files and delete the other. Or you can use both. Blender's FBX exporter will export each animation channel it finds and this can result in multiple KIN files for each mesh. This doesn't work well if at all. The solution is to use what is called a baked animation where all the channels and keyframes are "baked" together. This is actually inefficient for Trainz purposes but is the only answer that currently works reliably.

Exporting LOD0 Animation

  • Disable viewing of the LOD1 meshes by unclicking the LOD1 collection.
  • Enable both the LOD0 and Animation collections.
  • In the 3D Editor select all objects using the A key. You may need to press it twice.
LOD0 FBX Objects Collections
  • Go to the File menu and select Export>FBX.
  • The default options will not work for us so we need to change a few things:
  • For the Main tab:
  • Check Selected Objects.
  • Scale - either change the scale value to 0.01 and have the adjacent icon selected, or leave the scale at 1.00 and deselect the icon. (VALIDATE)
  • Apply Scale - use FBX All.
  • Forward - use Y forward
  • Up - Z up.
  • The next area lists those objects to be exported. In this case we want Empty and Mesh.
  • Leave the other options at their default value.
  • For the Animation tab:
  • Check Baked Animation.
  • Uncheck all other options. For this example we don't care about the other tabs but suggested values are shown in the next set of images.
Main Tab
Geometry Tab
Armatures Tab
Animation Tab
  • In the output filename space enter ex1_lod0.fbx and click on the Export FBX icon at the top right.

Exporting LOD1 Animation

  • Uncheck the LOD0 collection.
  • Check the LOD1 collection.
  • Leave the Animation collection checked.
  • Repeat the LOD0 process only changing the output name to ex1_lod1.fbx. You shouldn't need to change any of the export settings unless you restarted Blender.
LOD1 FBX Objects Collections


Setting up the Asset in Trainz

The FBX file contains both the mesh and the b.r.main empty plus the animation data. When the FBX file is imported into Trainz, an animation file (KIN) is created in addition to the Trainzmesh file. The name of the kin file depends on the options chosen within the Export FBX->Animation panel. If you choose the Baked Animation option, then the kin filename will be the mesh name plus “_scene.kin”. In this instance, the kin filenames will be “ex1_lod0_scene.kin” and “ex1_lod1_scene.kin”.


Config.txt

The names of mesh and KIN files may not be obvious so you may need to create some dummy names for your mesh and KIN files. After importing into Trainz, open the asset for editing and look for the files created. Then go back and correct entries in the config.txt. You can always rename the kin file to a simpler name. For this asset the mesh table will look like this:

mesh-table {

 lod_0 {
   mesh                                  "ex1_lod0.trainzmesh"
   auto-create                           1
   lod-level                             0
   anim                                  "ex1_lod0_scene.kin"
   animation-loop-speed                  1.00
 }
 lod_1 {
   mesh                                  "ex1_lod1.trainzmesh"
   auto-create                           1
   lod-level                             1
   anim                                  "ex1_lod1_scene.kin"
   animation-loop-speed                  1.00
 }

}

Asset in game

Example 1 in Trainz


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.


(more examples to come)


Return to Index

<< How To Guides

Personal tools