Report article RSS Feed Switching Animations Between Models

Learn how to implement HL2's Fast Zombie animations to the Citizen's model.

Posted by PhoeniX1992 on Apr 22nd, 2010
Intermediate Animation.

The fact that I've been stuck on this problem myself was reason enough to, after succeeding, to create a tutorial for others who might attempt to do the same thing, namely, switching animations from one model, to the other. As long as you follow the steps, not much can go wrong, and of course, you are always encouraged to add more steps of your own to get the desired result!

I know this is a quite long tutorial, but it will teach you to work with different programs, and applying different techniques which might be useful for other stuff you may run into during modding for the Source engine! Good luck, and as always, comments, tips and any other feedback are always welcome! For this tutorial, I will be switching the Fast Zombie's animations to one of the Citizen's model.

Required Software

Here's a quick overview on what we are going to do:

  1. Extracting the needed models from the right .GCF file
  2. Decompiling the extracted models
  3. Combining the needed files in the same folder
  4. Rewriting the .QC file to fit our needs and compiling the model
  5. Fixing the face texture error
  6. Fixing the hand error

Step 1 - Extracting the needed models from the right .GCF file
Once you have installed all the necessary tools, open up the .GCF which contains the models you will need. The .GCF's are located in ..\Steam\steamapps\ . The one I need is source models.gcf

User Posted Image

Open it up with GCFScape and browse to root\hl2\models\Humans\Group01\ . I chose the male07, because I like the model. Select all the male07 files and drag them to an empty folder in which you will work on the model, it doesn't really care where you place it, as long as it's easy to find.

User Posted Image

Now select the second model you will need, same procedure, but place them in another empty folder, to keep the decompiled files apart from each other later on.

User Posted Image

Step 2 - Decompiling the extracted models
After extracting the models to some fresh, empty folders, load up Cannonfodder's MDL Decompiler and select the first model for decompilation. Don't forget to set the Output folder to the same folder (or a new one) as your Source .mdl! Also uncheck the Steam File Access option, as it will most likely crash Cannonfodder on decompiling.

User Posted Image

Repeat the same process for the other model

Step 3 - Combining the needed files in the same folder
After decompilation, you will be left with the following files for the Male07 model and the FastZombie model

User Posted Image

User Posted Image

As you might have noticed, the FastZombie model decompiles to a LOT more files, this is because all the animation .SMD's are combined in the FastZombie's model, while the Citizen's are in a separate file, so they can be used by all the other variations of the Citizen's model

We will need all the FastZombie's animation files, so select them and copy them into a new folder (I named mine Mutants, because I aim to create a mutant like npc).

The .SMD files you will need are almost all, except for the ragdoll, phymodel, reference, unkownmodel and lod .SMD files

From the Citizen you will need the ragdoll, phymodel, reference and lod .SMD files. You will also need the Citizen's mdldecompiler.qc, as we will use this as a base for our new model.

After placing all the needed files in a separate folder you will have something like this

User Posted Image

Step 4 - Rewriting the .QC file to fit our needs and compiling the model
I renamed all the reference files from ...citizen... to ...mutant_humanmale... to make it more recognizable and understandable for the npc I'm trying to create. It might be wise for you too to rename your models.

Now open up the mdldecompiler.qc with notepad, or in my case with Notepad++. It will show up like this

User Posted Image

As you can see, in Notepad++ every important piece of code is highlighted, so you will notice it much faster than in regular notepad! It also has the abilty to collapse certain controllers, which as you can see here, with the facial animation system saves me 180 lines of code to scroll through!

Next we will modify the lines to suit our needs, we'll start with the first $cd line. This line is needed for our model compiler to know in which directory it should start to work. But as long as all the files are in the same directory, you can delete this line. This makes moving the files around a lot easier, since you don't have to edit the .QC file evry them you move them then.

Next up is the $modelname string, this one will determine what the name of your model will be, and what it's path will be in your mod's model folder. Set it up the way you want, similair to this, remember that it will start in the "model" map of the mod/game you compile this model for!

$modelname "Mutants/Humanmale.mdl"

The next line to edit is the one which will tell the compiler the name of our model (not extremely important) and the reference file of it (the way it looks). You see after that you will have to open a curly bracket (in some cases), after this bracket the facial animation system is declared, this might not apply for your model. I changed the name of my model to "mutant_humanmale" and the used model to the corresponding "mutant_humanmale_reference.smd".

$model "mutant_humanmale" "mutant_humanmale_reference.smd" {<br>[FACIAL ANIMATION SYSTEM STUFF]<br>}

Next up are the LOD definitions, these tell the compiler, and the engine to replace the base model with a lower detail version at longer distances. The $lod command will contain a $replacemodel command, which tells the compiler which model to replace with what lower detail one. In this case the model to replace will be our reference model, and we want it to be replaced by the corresponding LOD version. Set these up as the following

<br>$lod 8<br> {<br>  replacemodel "mutant_humanmale_reference" "lod1_mutant_humanmale_reference"<br>}<br>$lod 20<br> {<br>  replacemodel "mutant_humanmale_reference" "lod2_mutant_humanmale_reference"<br>}<br>$lod 40<br> {<br>  replacemodel "mutant_humanmale_reference" "lod3_mutant_humanmale_reference"<br>}<br>$lod 80<br> {<br>  replacemodel "mutant_humanmale_reference" "lod4_mutant_humanmale_reference"<br>}<br>$shadowlod<br>{<br>  replacemodel "mutant_humanmale_reference" "lod5_mutant_humanmale_reference"<br>}<br>

The next thing to change is the $cdmaterials option, this will tell the compiler where the materials for this model are. Since we're using the Citizen's base .qc file, these should already be set up correctly. If not, set them up like this.

<br>$cdmaterials "models\Humans\Male\Group01\"<br>$cdmaterials "models\Humans\Male\"<br>

If you would like to reskin your model though, you can change these folders to a custom one, this way you won't have to edit and overwrite the standard skins.

<br>$cdmaterials "models\Mutants\Male\"<br>

Next up are a lot of options which we don't need to change, but if you're interested in what they mean, they should be very self-explanatory

You will notice there are a few $includemodel options. These will tell the compiler to include all the Citizen's animations from the shared animation model files, we don't need them as we want a mutant, so you can delete these lines.

<br>$includemodel "humans/male_shared.mdl"<br>$includemodel "humans/male_ss.mdl"<br>$includemodel "humans/male_gestures.mdl"<br>$includemodel "humans/male_postures.mdl"<br>

What we do have to copy from the FastZombie's .qc is all the animation, sequence and ikchain definitions, so look them up in that .qc and copy them into our Mutants .qc. This will tell the compiler to use all the animations. This is an example of the code we will need to copy. The $sequence and $animation strings will tell the compiler what animations to use, and the $ikchain is used for the model to show correctly ingame on sloped surfaces and step, so the legs and knees will bend at an anatomaly correct way.

<br>$sequence idle "idle" loop ACT_IDLE 1 fps 30.00<br>$sequence idle_angry "idle_angry" loop ACT_IDLE_ANGRY 1 fps 30.00<br>$sequence idle_onfire "idle_onfire" loop ACT_IDLE_ON_FIRE 1 fps 30.00<br>$sequence Run "Run" loop ACT_RUN 1 fps 30.00 {<br>  { event AE_FASTZOMBIE_GALLOP_LEFT 5 }<br>  { event AE_FASTZOMBIE_GALLOP_RIGHT 9 }<br>}<br><br>//$sequence Leap "Leap" ACT_RANGE_ATTACK1 1 fps 30.00 {<br>//  { event AE_FASTZOMBIE_LEAP 8 }<br>//}<br><br>//$sequence LeapStrike "LeapStrike" loop ACT_FASTZOMBIE_LEAP_STRIKE 1 fps 26.00<br>$sequence LandRight "LandRight" ACT_FASTZOMBIE_LAND_RIGHT 1 fps 30.00<br>$sequence LandLeft "LandLeft" ACT_FASTZOMBIE_LAND_LEFT 1 fps 30.00<br>$sequence Melee "Melee" loop ACT_MELEE_ATTACK1 1 fps 30.00 {<br>  { event AE_ZOMBIE_ATTACK_RIGHT 3 }<br>  { event AE_ZOMBIE_ATTACK_LEFT 7 }<br>}<br><br>$sequence climbmount "climbmount" fps 30.00<br>$sequence climbloop "climbloop" loop ACT_CLIMB_UP 1 fps 30.00 {<br>  { event AE_FASTZOMBIE_CLIMB_LEFT 5 }<br>  { event AE_FASTZOMBIE_CLIMB_RIGHT 12 }<br>}<br><br>$sequence climbdismount "climbdismount" ACT_CLIMB_DISMOUNT 1 fps 30.00<br>$sequence JumpNavMove "JumpNavMove" ACT_JUMP 1 fps 30.00<br>$sequence leap_start "leap_start" fps 30.00<br>$sequence leap_loop "leap_loop" loop fps 30.00<br>$sequence leap_land "leap_land" fps 30.00<br>$sequence BR2_Roar "BR2_Roar" ACT_FASTZOMBIE_FRENZY 1 fps 30.00<br>$sequence BR2_Attack "BR2_Attack" ACT_FASTZOMBIE_BIG_SLASH 1 fps 30.00 {<br>  { event AE_ZOMBIE_ATTACK_RIGHT 18 }<br>}<br><br>$animation a_Walks "a_Walks" loop fps 30.000000<br>$animation a_WalksE "a_WalksE" loop fps 30.000000<br>$animation a_WalkE "a_WalkE" loop fps 30.000000<br>$animation a_WalkNE "a_WalkNE" loop fps 30.000000<br>$animation a_WalkN "a_WalkN" loop fps 30.000000<br>$animation a_WalkNW "a_WalkNW" loop fps 30.000000<br>$animation a_WalkW "a_WalkW" loop fps 30.000000<br>$animation a_WalkSW "a_WalkSW" loop fps 30.000000<br>$sequence walk_all "a_Walks" loop ACT_WALK 1 fps 30.00 {<br>  { event AE_ZOMBIE_STEP_RIGHT 7 }<br>  { event AE_ZOMBIE_STEP_LEFT 16 }<br>  blendwidth 9<br>  blend move_yaw -180.000000 180.000000<br> a_WalksE a_WalkE a_WalkNE a_WalkN a_WalkNW a_WalkW a_WalkSW a_Walks<br>}<br>$sequence ragdoll "ragdoll" ACT_DIERAGDOLL 1 fps 30.00<br>$ikchain rfoot ValveBiped.Bip01_R_Foot knee  0.774 -0.633 0.000<br>$ikchain lfoot ValveBiped.Bip01_L_Foot knee  0.000 0.000 0.000<br>$ikchain rhand ValveBiped.Bip01_R_Hand knee  0.759 0.651 -0.000<br>$ikchain lhand ValveBiped.Bip01_L_Hand knee  0.726 0.688 0.000<br>

An alternative way to add the animations is to change the $includemodel lines to add the Zombie/Fast.mdl. This way all the animations will be added without all these lines of code. If you like to keep control of them yourself tough, the above code is the way to go.

$includemodel "Zombie/Fast.mdl"

That's all we need to change in the .QC, so save and close it for now. Next up is the fun part, let's compile and open up our model! For this we will write a little batch file so we won't have to write these commands in a terminal by hand. It will define the path to the studiomdl.exe which compiles our model, and the .QC file to compile. After that we add the pause command, to let the commandprompt stay open until we tell it to close. Our .BAT file will look like this

<br>"F:\Program Files\Steam\steamapps\*****\sourcesdk\bin\ep1\bin\studiomdl.exe" "f:\Program Files\Steam\steamapps\*****\sourcesdk\PHOENIX SOURCE\modelsrc\Mutants\source\mdldecompiler.qc" <br><br>pause<br>

Save it as an .BAT and run it! If everything is set up correctly you will see the following screen. Notice that the compiler will compile the model to the game/mod that is currently loaded in Source SDK, so make sure you select the right one, or your models may end up in the wrong game! With Notepad++, in combination with the NppExec plugin, it is also possible to compile your model by just pressing F6... You might want to look into this for fast compiling and testing.

User Posted Image

If everything worked out, load up your model in MDLviewer to see the result!
Tadaa! There we have our disco dancing zombie citizen. But wait, it's hands are all stretched up, and it looks as if he stuck his head in a place without sunlight! But no need to worry, we will fix this in the next steps. This is where VTFEdit and 3DS Max kick in.

User Posted Image

Step 5 - Fixing the face texture error
Luckily, the problem with the face texture is an easy fix (thanks to Guessmyname here at lopers!), Open up the source materials.gcf and browse to root\hl2\materials\Models\Humans\Male\Group1\ and extract the mike_facemap.vmt and .vtf. If you chose another model than the Male07, you will need other files! Place them in the same folders as in the .GCF in your game/mod directory.

Now open up the mike_facemap.vtf with VTFEdit, and open up the Image tab, you will see the Clamp S and Clamp T functions to be checked, uncheck these and save the texture.

User Posted Image

Reload your model in MDLViewer and you will hopefully see a fixed face texture!

Step 6 - Fixing the hand error
We still have the fingery-finger hand issue left, to fix this we will need 3DS Max to reskin the hands to the forearm bones (Thanks again to Guessmyname and some other lopers for this one!). This will tell the compiler and the engine (yes we have to recompile our model, that's why we created an easy to re-use .BAT file) to make the hands animate along with the forearm. This does mean that his hands will stay in an idle position, but ingame you will hardly notice this. Open up 3DS Max and import the mutant_humanmale_reference.smd. For this, you will need the 3DS Max .SMD Import and Export Plugin. During the import, you will recieve a few dialogs, leave the settings for what the are and just continue. In 3DS Max you will now see your Citizen's model appear.

User Posted Image

Now go to the Modifier tab and select the Skin > Envelope option. You will now see the selected bone and it's attached, highlighted Skin. The coloring determines the weight of the animations on this bone and it's attached skin.

User Posted Image

Select the forearm bone by clicking on it and scroll down in the tool list and select the Paint Weights tool, you might want to uncheck the Paint blend weights option. Now paint the hands to add them to the forearm bone. Repeat the same step for the other hand, but this time with the other forearm bone.

User Posted Image

When you're done, export the model to the mutant_humanmale_reference.smd. And recompile your model. Load it up in MDLViewer, and voilà, a zombie citizen without a black head, and no more stretched fingers!

User Posted Image

I hope you enjoyed this tutorial and learned something from it. This was a lot of work to do, so if you pulled it off, you should actualy be proud of yourself!

Post comment Comments
Maxen1416 Apr 22 2010, 8:56pm says:

ROFL loved that dogs face xXDD
and thanks for the tut!

+4 votes     reply to comment
Su[)az][mA Apr 23 2010, 9:48am says:

lol, great tut :P

+1 vote     reply to comment
3didy May 6 2010, 4:19am says:

cool,got me interested in H2L game making

+1 vote     reply to comment
xfire0904 May 7 2010, 6:12pm says:

yea i now can import playermodels from CS:S portal DOD and more skins for CS:S to SMOD XD

+1 vote     reply to comment
Sn1pe May 25 2010, 4:00pm says:

There's an utterly and extremely easy way to incorporate new and custom made animations for all half life 2 characters. No re-rigging and setting up the models required at all.

+1 vote     reply to comment
RakashiJ Jun 3 2010, 4:24pm says:

yeeeeeeeeeeeah, well the last time i tryed to make a skin, it didnt work. and the tut was short and simple. i thought, i could pull it off, i got the right programs, and tada it didnt work!

-1 votes     reply to comment
Angrypeppermushroom2 Dec 18 2010, 9:46pm says:

Why cannonfoders compiler? WHY?!!?!?

+1 vote     reply to comment
agent00kevin Mar 2 2011, 11:45pm says:

Nice TUT, but I cant get the Fast Zombie animations. It gives me an error when it tries to open the file, something involving cannot open ^B which is some reference to a headcrab.

When I linked the Fast Zombie animations with the $includemodel line, it just crashed HL2.exe every time.

It DID work for other anims though, like metropolice and combine. I went one step further and renamed the model, smd, vvd and phys files from citizen_05 to Police, essentially giving citizens Combine Ai, which is MUCH smarter. (they are reskinned into infected)

Anyone know how to actually get the fast Zombie Anims out of there?

+1 vote     reply to comment
Aggregate Mar 24 2011, 9:49am says:

Used this tutorial to give a soldier a metrocops animations so he could use the pistol, it worked! Great tutorial.

+1 vote     reply to comment
karol1234 Jun 10 2011, 7:10am says:

plx create video tut

+1 vote     reply to comment
g-man1 Oct 14 2011, 12:37pm says:

man i have it non-steam

-1 votes     reply to comment
TRULLE90 Mar 19 2012, 2:04pm says:

how do i pack the smd files back to a mdl file again? please ansear

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Report Abuse
Report article
Related Games
Half-Life 2
Half-Life 2 Single & Multiplayer First Person Shooter
Half-Life 2: Episode Two
Half-Life 2: Episode Two Single & Multiplayer First Person Shooter
Related Engines
Source Commercial Released Oct 31, 2004
Related Groups
Valve Developer & Publisher