Source Filmmaker

Source Filmmaker

56 ratings
How to export SFM animations to TF2
By Sgt. Sweetheart
Ever wanted to export your SFM work into your beloved, hat addict game? Now's your chance!
This guide in a video

You can find the text version below.
1.) What will you need and some common questions
IMPORTANT: Since the "new" tf2 update that changed sv_pure on valve servers, there is a chance that this modification won't be able to work on certain servers.

For this guide, you will need:

- Source SDK ( Just start it up, and refresh it's content )
- Blender
- Blender source tools
- GCFScape
- Notepad++
- Crowbar

Some short answers for common questions:

- Can others see my animations on the server?
If it is an animation that replaces an offical one, then no, they can't.
- I used an IK rig for the animation and SFM won't let me export anything.
Just disable the rig and you can export your animation without any problem.
2.) About your animations in the game
Before beginning to animate you should keep in mind, that since you wish to replace an already existing taunt with yours, it will have the same length as the original one with the same props/sounds.

For example: The Schadenfreude is a long taunt with a sound file.

Why is this important? You can customise stuff that is already in the game, but when you try to add something that doesn't exist in the game and it can't refer to anything, you won't be able to see your content unless you play on your own server and load it yourself. This is just a lazy way to "test" your work inside the game.

To see how many frames each taunt has, you will need to open the vpk file named tf2_misc_dir ( with gcfscape ) and search for the character's animation file that is located in models/player and usually named *classname*_animations.mdl
After decompiling this file, you will find smd files inside an animations folder.

TF2 animations use the following system: They have one file for the animation, usually called layer_*animation* and a secondary file to load the animation. The secondary file also has the data of how many frames that animation consists of. My example, showed in the video uses the Soldier's primary taunt which is a 85 frame animation and my replacement is a bit longer than the original, so TF2 will only play the taunt until the 85th frame. Another thing I've noticed is that, if the taunt is way longer than the actual playtime it will use a sped up version of the custom animation.

This is pretty much all you need to know before starting to do this modification.
3.) After you have done your animation
After you have read the previous text, it will become clear that your animations should usually be around 70-150 frames.

Your actual first step is creating a clean, new project, so it will only contain your animation.
When you're done with this, you can proceed to export this by right clicking on the model and selecting Export - Animation

A menu will show up, where you need to select trim to shot.
(By the time I write this, SFM is an ar$e when it comes to modifying values so it is for the best to do all your animations in a separate project file.)

Get a fancy name for your animation and save it as a dmx.

4.) When you have your animation file from SFM
You will require the latest release of Blender and the Source Tools, both you can find at the beginning of this guide.

For people who are new to Blender:
When you open Blender for the first time, you will see a cube with two other objects.
You can select all of them by holding shift and right clicking on the objects, pressing the delete key and confirming this action. To get a better view, you need to hold the right mouse button and move around. You can also use your scroll wheel.

When you are done with that:
I hope you have already installed the Blender Source Tools with the help of the description on that site, that will allow you to press the space bar and type in "smd" the first ( and only ) thing you will see is what you need. Import your tf2 model by searching the smd model file in your sourcesdk_content ( Steam/SteamApps/yoursteamusername/sourcesdk_content/tf/modelsrc/player/yourclass/parts/smd ) and before you would open the file, you should set it to the Y axis.

When you have imported your model, get the same menu again and import your animation to the model. This step is very important to see if your SFM is up-to-date, because for example, mine for some reason isn't.

But here is why:

If you open the animation file ( while having the "import animations" checked ) and it will give you an error message instead of importing it to your model, then it means your SFM has some extra files that bug the exporter. This might sound dumb, but that is the reason.
From here you can either remove everything that is related to the engine files and redownload the content and do the process again OR and this is a REALLY a much better solution: Send the .dmx project file to one of your friends, who has a more "cleaner", "pure" version of the software. I'm still working on this issue myself, because there should be a better explanation, but I hope this helped too.

If you did managed to load your animation:

Congratulations, your export was successful.
BUT WHAT IS THIS? Up to a certain point it only shows you the default pose and it rotated your model in a different position, even though you did stayed with the Y axis? The latter one is normal and easy to fix, just select all ( by clicking "A" ) and choose the rotation tool from below and give a cool value like "90" on the X axis.

But what about the animation? Again, I'm without any answers since this topic is without any documentation too. ( *cough* after all, this is the first tutorial about exporting stuff from SFM to Source games ) There is a solution, of course. Below you will find something that is related to frames. Check on them to see when your animation starts ( in my scenerio it is 150 ) remember that value. Same goes for the ending of your animation.

And now we have come to the point to export this file as an SMD.
You'll need to find the menu on the right for the Source engine export, here you only need to give a folder to export the file to and select SMD as a format. Click on the animation dmx below and you should get your animation file from blender in 6-12 seconds.
5.) When you have acquired your SMD animation file from Blender
When you finally obtained your animation file, you should open it up with Notepad++ and start the scripting part.

This isn't as hard as you may think first.
The first time you open files like this it will look like a mess, but if you look closely, it is very easy to understand. The first part will look extremely familiar if you have used SFM in the past, because they are body names for the source model. They all have numbers and at the end of the list, you will see even more numbers. But what is even more important that all of those lines will have a "time *number*" before every list of codes.

time 0 for example is equal with the first frame you will see in-game.
So all these time 0, time 1 stuff are sections. Each section has codes that will give information for the game what to do in that moment, but thankfully it is only about the mathematical order, so you can just simply delete the sections up until a point where you have seen inside Blender that your animation have started ( *FLASHBACK* ONEHUNDREDFIFTY ) and delete them. Same goes with the frames that are after the animation. ( *FLASHBACK* you know, that other number you needed to remember to ) After you're done, save the file and copy it to (almost) the same directory where you have found the SMD model file for your model. This time you need to place it in a folder named animations (and not inside a folder full of dmxs )
6.) The final scripting part to make an acceptable file for our game
After you have placed your smd file and renamed it, in the way it would match with the taunt you're trying to replace in the game. find a folder named "scripts".
Here you will find a file named "*yourclass*_animations.qc" copy this file and rename it by adding a 2 at the end of the file. Open the copied file, delete everything and copy these lines in it:

// defining the upaxis is needed for maya exports
$upaxis Z

$modelname player/yourcharactersname_animations.mdl

$includemodel player/yourcharactersname_animations2.mdl

$definevariable infoNode "yourcharactersnameInfo"
$include "yourcharactersname_definebones.qci"

// include the file that sets up the ikchains
$include "../../TF_animation_rules/ruleshierarchy.qci"
$include "../../TF_animation_rules/TF_macros_list.qci"

$pushd "../animations"

$sequence youranimationname "youranimationname" snap fps 30

Replace lines, wherever it is required.

Save it when you are done.
7.) The last step
Now you can open Crowbar and click on the compiler tab.
In there you will obviously need to select the game you wish to compile it for ( which in our case Team Fortress 2 ) and open our previously edited qc file there. Hit the "Compile QC file " button.

Usually, the software will place your qc file to tf/models/player so you should look for a file named "*yourclass*_animations.mdl" and place it in your custom folder. ( note that you may already have one if you checked that option in crowbar, but you need one in your tf folder. ) Inside the custom folder, create another folder that you can name anything you want to. Inside this folder create a models folder and inside of that models folder, make a player folder and inside that player folder you should place your mdl file.

Now, you probably didn't re-do all the animations for that game, so if you wish to have the rest of the animations working, you will need to copy the original animation mdl file from the current vpk file. ( It is tf2_misc_dir ) Copy the file to your desktop, add a 2 to the end of the file's name and copy it to the same folder where you placed your custom animation to.

And that's it. You have a working taunt replacement.

Of course, this method can be used to replace weapon animations too, so now anyone can fix the infamous reload animations.

Also, I would like to thank these people who helped me to make this guide possible: VCR, Astute and Josh Griffin for his helpful tutorial on how to do the same method with Blender only.
< >
Calcium Oxide Duration! Jul 1, 2018 @ 1:43pm 
How would I do this with weapons?
STAR o Totozu Mar 13, 2018 @ 7:42pm 
And the .VCD?? how i export with it
Nemersis Aug 8, 2016 @ 7:53am 
Well thanks anyway.
Sgt. Sweetheart  [author] Aug 8, 2016 @ 7:48am 
Like something that is entirely new? No idea there.
Nemersis Aug 8, 2016 @ 7:42am 
I have a very specific question. How i can import animations from tf2 to custom model? Like somthing from Garry's mod or Counter-Strike:Source?
Sgt. Sweetheart  [author] Jul 26, 2016 @ 6:16am 
Yes, of course
Sgt. Sweetheart  [author] May 4, 2016 @ 11:19am 
That problem is in SFM then. You need to get a file that uses that format or else the game doesn't know how to deal with the information,
Deep Thunder May 4, 2016 @ 11:11am 
Question, I'm trying to do another animation, only there aren't any "time 0" lines of codes in the .smd unlike my other working .smd. And thus I can't compile with crowbar. Any idea why? (I know it's something I did wrong SFM but I don't know what it is)
Sgt. Sweetheart  [author] May 4, 2016 @ 10:42am 
Nice job
Deep Thunder May 4, 2016 @ 10:31am 
Hey JC Denton, this guide helped me properly port a completely new animation from SFM to L4D2 (even though it was intended for TF2 and may be outdated as you said). And for that, I thank you.