Switching Animations Between Models

Tutorial collection, comprehensive listings on main site.

Switching Animations Between Models

Postby Tutorial on Sun Mar 28, 2010 8:29 pm

category
Modelling

description
Learn how to switch the Fast Zombie animations to one of the Citizen models.

keywords
model, animation, animations, models, switching, fast zombie, citizen.

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.

Image

Required Software

Here's a quick overview on what we are going to do:
Step 1 - Extracting the needed models from the right .GCF file
Step 2 - Decompiling the extracted models
Step 3 - Combining the needed files in the same folder
Step 4 - Rewriting the .QC file to fit our needs and compiling the model
Step 5 - Fixing the face texture error
Step 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

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.

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.

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.

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

Image

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

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

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!

Code: Select all
$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".

Code: Select all
$model "mutant_humanmale" "mutant_humanmale_reference.smd" {
[FACIAL ANIMATION SYSTEM STUFF]
}


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

Code: Select all
$lod 8
 {
  replacemodel "mutant_humanmale_reference" "lod1_mutant_humanmale_reference"
}
$lod 20
 {
  replacemodel "mutant_humanmale_reference" "lod2_mutant_humanmale_reference"
}
$lod 40
 {
  replacemodel "mutant_humanmale_reference" "lod3_mutant_humanmale_reference"
}
$lod 80
 {
  replacemodel "mutant_humanmale_reference" "lod4_mutant_humanmale_reference"
}
$shadowlod
{
  replacemodel "mutant_humanmale_reference" "lod5_mutant_humanmale_reference"
}


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.

Code: Select all
$cdmaterials "models\Humans\Male\Group01\"
$cdmaterials "models\Humans\Male\"


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.

Code: Select all
$cdmaterials "models\Mutants\Male\"


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.

Code: Select all
$includemodel "humans/male_shared.mdl"
$includemodel "humans/male_ss.mdl"
$includemodel "humans/male_gestures.mdl"
$includemodel "humans/male_postures.mdl"


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.

Code: Select all
$sequence idle "idle" loop ACT_IDLE 1 fps 30.00
$sequence idle_angry "idle_angry" loop ACT_IDLE_ANGRY 1 fps 30.00
$sequence idle_onfire "idle_onfire" loop ACT_IDLE_ON_FIRE 1 fps 30.00
$sequence Run "Run" loop ACT_RUN 1 fps 30.00 {
  { event AE_FASTZOMBIE_GALLOP_LEFT 5 }
  { event AE_FASTZOMBIE_GALLOP_RIGHT 9 }
}

//$sequence Leap "Leap" ACT_RANGE_ATTACK1 1 fps 30.00 {
//  { event AE_FASTZOMBIE_LEAP 8 }
//}

//$sequence LeapStrike "LeapStrike" loop ACT_FASTZOMBIE_LEAP_STRIKE 1 fps 26.00
$sequence LandRight "LandRight" ACT_FASTZOMBIE_LAND_RIGHT 1 fps 30.00
$sequence LandLeft "LandLeft" ACT_FASTZOMBIE_LAND_LEFT 1 fps 30.00
$sequence Melee "Melee" loop ACT_MELEE_ATTACK1 1 fps 30.00 {
  { event AE_ZOMBIE_ATTACK_RIGHT 3 }
  { event AE_ZOMBIE_ATTACK_LEFT 7 }
}

$sequence climbmount "climbmount" fps 30.00
$sequence climbloop "climbloop" loop ACT_CLIMB_UP 1 fps 30.00 {
  { event AE_FASTZOMBIE_CLIMB_LEFT 5 }
  { event AE_FASTZOMBIE_CLIMB_RIGHT 12 }
}

$sequence climbdismount "climbdismount" ACT_CLIMB_DISMOUNT 1 fps 30.00
$sequence JumpNavMove "JumpNavMove" ACT_JUMP 1 fps 30.00
$sequence leap_start "leap_start" fps 30.00
$sequence leap_loop "leap_loop" loop fps 30.00
$sequence leap_land "leap_land" fps 30.00
$sequence BR2_Roar "BR2_Roar" ACT_FASTZOMBIE_FRENZY 1 fps 30.00
$sequence BR2_Attack "BR2_Attack" ACT_FASTZOMBIE_BIG_SLASH 1 fps 30.00 {
  { event AE_ZOMBIE_ATTACK_RIGHT 18 }
}

$animation a_Walks "a_Walks" loop fps 30.000000
$animation a_WalksE "a_WalksE" loop fps 30.000000
$animation a_WalkE "a_WalkE" loop fps 30.000000
$animation a_WalkNE "a_WalkNE" loop fps 30.000000
$animation a_WalkN "a_WalkN" loop fps 30.000000
$animation a_WalkNW "a_WalkNW" loop fps 30.000000
$animation a_WalkW "a_WalkW" loop fps 30.000000
$animation a_WalkSW "a_WalkSW" loop fps 30.000000
$sequence walk_all "a_Walks" loop ACT_WALK 1 fps 30.00 {
  { event AE_ZOMBIE_STEP_RIGHT 7 }
  { event AE_ZOMBIE_STEP_LEFT 16 }
  blendwidth 9
  blend move_yaw -180.000000 180.000000
 a_WalksE a_WalkE a_WalkNE a_WalkN a_WalkNW a_WalkW a_WalkSW a_Walks
}
$sequence ragdoll "ragdoll" ACT_DIERAGDOLL 1 fps 30.00
$ikchain rfoot ValveBiped.Bip01_R_Foot knee  0.774 -0.633 0.000
$ikchain lfoot ValveBiped.Bip01_L_Foot knee  0.000 0.000 0.000
$ikchain rhand ValveBiped.Bip01_R_Hand knee  0.759 0.651 -0.000
$ikchain lhand ValveBiped.Bip01_L_Hand knee  0.726 0.688 0.000


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.

Code: Select all
$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

Code: Select all
"F:\Program Files\Steam\steamapps\*****\sourcesdk\bin\ep1\bin\studiomdl.exe" "f:\Program Files\Steam\steamapps\*****\sourcesdk\PHOENIX SOURCE\modelsrc\Mutants\source\mdldecompiler.qc"

pause


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.

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.

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.

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.

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.

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.

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!

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!

PhoeniX1992
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Re: Switching Animations Between Models

Postby agent00kevin on Tue Apr 26, 2011 5:48 am

I have attempted this with failed results. Cannonfodder's MDL Decompiler absolutely refuses to decompile any Zombie model. I get a different error for each one, but none of them will decompile.

I have managed to make a citizen with metrocop animations and AI, as well as Combine, but as for the Zombies, its a no go.

Has anyone done this successfully lately?
agent00kevin
Member
Member
 
Joined: Fri Apr 22, 2011 5:52 pm

Re: Switching Animations Between Models

Postby Jordash on Tue Apr 26, 2011 6:51 am

Even when the decompiler works, the walking animations won't decompile properly (the x/y displacement is lost), so its better to use the
Code: Select all
$includemodel "Zombie/Fast.mdl"
method anyway.
User avatar
Jordash
Been Here A While
Been Here A While
 
Joined: Mon Sep 21, 2009 10:36 am
Location: Perth, Australia

Re: Switching Animations Between Models

Postby agent00kevin on Tue Apr 26, 2011 8:35 am

Jordash wrote:Even when the decompiler works, the walking animations won't decompile properly (the x/y displacement is lost), so its better to use the
Code: Select all
$includemodel "Zombie/Fast.mdl"
method anyway.


Yeah, I tried that too, but it crashes HL2.exe when the game loads with those models in. I take them out, it loads fine. I wanted to add fast zombie animations to a citizen model just like it said, then reskin it for a mod. (reskin is actually done) Unfotunately, I tried this a few months ago and the results were exactly the same this time, following the tutorial. Ive been able to give them all kinds of other animations, even the Zombine anims (though I didnt keep them) but for whatever reason fast zombie animations crash HL2 every time.

I suppose when I get back to work Ill come back and post the .qc file. Now, it is sleepytime :)
agent00kevin
Member
Member
 
Joined: Fri Apr 22, 2011 5:52 pm

Return to Tutorials

Who is online

Users browsing this forum: No registered users

cron