Getting your TF2 hat in game as a Physics prop
Many of you in the TF2 contribute thread have been having trouble getting your hat in game to view so I've decided to make a short tutorial on how to get your hats in game. This tutorial won't cover how to get your hat in game for other players to wear but it will get your hat in game as a prop_physics so you can view the TF2 shaders on your hat which is what really matters. I'll be going through this tutorial from the point of view of a Max user but the information should apply to any modeling application. Enough talk, let's begin!
Here's a list of what you'll need to complete this tutorial:
-A SMD Exporter for you respective modeling program. You can get the 3DSMax one
HERE. I'm not sure if there's a working one for Maya but the free XSI Mod Tool should have one.
-
GUI Studio MDL. This is used to compile your model from your .QC file. Before starting this tutorial, open this and set the correct paths to the bins. There are directions inside the program on how to do this.
-
VTFEdit. This is used to convert your textures from TGA/PNG to .VTF (Valve Texture File). You can also use it to edit your .VMT.
-Source SDK. You can download this for free from the Tools tab in your Steam Library.
-A textured model of your hat in your modeling program.
-A collision model
-TGA/PNG file of your diffuse map
-A folder where you'll store your TGA, .QC and .SMD files for this particular hat. This is not much of a requirement but it's good to keep your files organized.
Now that you've got all the items listed above, we'll begin exporting/converting all of the files that you'll need to get your model in TF2.
We'll begin by converting your model's mesh and collision mesh to get your 3 SMD files.
Before you convert your model to .SMD you must have a material with the same name as the VMT file you'll be using applied to your mesh. This is very important because if the texture applied to your model in your modeling application has a different name than the VTF on your final model the texture will not show up in game.
Here's how your model should be before exporting.
![1.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/1.jpg)
I've got a simple purple diffuse map applied to my model named testhat and a bone named hatbone applied to the mesh. It's not necessary to name your bone but it's a good practice.
Now it's time to export your reference and idle models. Go to File/Export and select "Source SMD" in the Save as Type drop down menu and choose to save it in the folder you'll be keeping your QC/SMDs in. Name the hat whatever you want your hat to be named without spaces. In my case I'm naming it testhat. Click Save. A menu should appear on your screen. Select "Export Reference SMD" as pictured below.
![2.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/2.jpg)
Click OK. After the bar has scrolled all the way to the right, click OK again. You've now exported your model's reference SMD.
Now you need to export your idle animation. Go to Export again, choose to Save as Type "Source SMD" in the same folder you saved your reference SMD. Name this file the same as your reference SMD but with _idle at the end. In my case I'm naming it testhat_idle. Click Save. The same menu as before should appear on your screen. This time select "Export Sequence SMD" and set the Export Range from 0 to 1 as pictured below.
![3.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/3.jpg)
Click OK. After the bar has scrolled all the way to the right, click OK again. You've now exported your model's idle animation SMD.
Now that you've got your reference and idle SMDs all that's left for you to do in your modeling application is export your Collision Mesh to get your Phys SMD.
Open your Collision Model or build your collision model over your hat model. Your collision model MUST be a convex shape or a combination of convex shapes with the same smoothing group applied to the entire model. Be sure to also apply the same diffuse map your model uses to your collision model. Now apply a bone to the collision model. Your bone and your collision model should be placed in the same spot relative to the origin of your 3D space, otherwise your collision will be off center to your hat while in game. Here's what my hat looks like after I've completed these steps.
![4.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/4.jpg)
Now you need to export your collision model to SMD. Go to Export, find the folder where your other SMDs are saved and select Save as Type "Source SMD". Name the file the same as your reference SMD but with _phys at the end of it. In my case I'm naming it testhat_phys. Click Save. Select "Export Reference SMD" as pictured below.
![5.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/5.jpg)
Now you're done exporting models!
We're now going to convert our texture files from TGA/PNG to VTF. Minimize or close your Modeling Application and open a browser to the folder where your TGA/PNG files of your textures are. Remember before you convert to VTF, place your Phong map in the alpha channel of your Diffuse map. Right click on your diffuse map, go to Open With and select VTFEdit. A window should pop up on your screen that looks like this.
![6.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/6.jpg)
Don't mess with any of the settings. Click OK. Go to File, Save As. Go to Program Files/Steam/Steamapps/[Your account name]/Team Fortress 2/tf/materials/models. Here you need to make a new folder with the name of your hat. I'm naming mine testhat. Save your texture in that folder with the EXACT same name as the texture you had applied to your model in your modeling application.
Don't worry about making a normal/spec map for your hat as Valve most likely won't use them. They'll use a flat normal map that's used on all the hats. If your hat truly benefits from a normal map then Valve will possibly use it but for the purposes of this tutorial I'll be using the flat normal map Valve uses on their hats.
Now it's time to set up the VMT for your material. This is a text file that tells Source where the textures for your hat are located and what shaders to use on that texture/model.
We're going to be using VTFEdit to create our VMT. Open VTFEdit and go to File/New. You should get a screen like this.
![7.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/7.jpg)
Copy this code into your VMT and replace "testhat" with whatever your hat is named and make sure that the file paths lead to the folder where your materials are.
"VertexlitGeneric"
{
"$baseTexture" "models\testhat\testhat"
"$bumpmap" "models\effects\flat_normal"
"$phong" "1"
"$phongexponent" "25"
"$phongboost" "5"
"$lightwarptexture" "models\lightwarps\weapon_lightwarp"
"$phongfresnelranges" "[.25 .5 1]"
"$basemapalphaphongmask" "1"
"$rimlight" "1"
"$rimlightexponent" "4"
"$rimlightboost" "2"
[FONT="]}
[/FONT]If you have any questions or want to learn a bit more about what these commands are, search through the
VDC.
Once your VMT has all the correct paths and names, save it with the same name as your diffuse VTF in the same folder that the diffuse VTF is located in.
Now that we've got our VMT, VTF and SMD files created, all that's left if to make the .QC file and compile our model.
Copy the code below into a fresh Notepad file and replace testhat with the name of your hat.
$modelname "testhat/testhat.mdl"
$model "Body" "testhat.smd"
$cdmaterials "models/testhat"
$sequence idle "testhat_idle.smd" fps 30.00
$collisionmodel "testhat_phys.smd" {
$concave
$mass 4.0
$inertia 1.00
$damping 0.00
$rotdamping 0.00
}
[FONT="]$keyvalues { prop_data { "base" "cloth.Small" } }
[/FONT]Make sure the paths all lead to the correct folders where your files are located. Below are short descriptions on what the commands you must change do.
-CDMaterials references the folder where your materials are located. Mine is located in TF/Materials/Models/Testhat so I put "models/testhat" as the location of the folder.
-Modelname is what you want the QC to name the model when it's run and the location of the model. I want my hat to be named Testhat so I put "testhat/testhat.mdl". You MUST create a folder for your hat in the Team Fortress 2/tf/models folder for your model to go in before compiling your QC file or else you'll get errors. The program will NOT create a folder for you.
-Model, Sequence Idle and Collisionmodel reference your SMD files. Your QC file should be saved in the same folder as your SMD files.
-Prop_Data tells Source what sounds and physical properties to give the model. I'm using cloth.Small for my hat. A list of commands available for this is located
here.
Once you have all of the correct paths and file names in your notepad file, save it as [hatname].qc. I've named mine "testhat.qc". Putting .qc on the end of the filename while saving automatically makes it a QC file that GUI Studio MDL will recognize instead of a notepad file.
Now that we've got your QC file made, it's finally time to compile your model. Open up GUI Studio MDL. Select Orange Box and select Team Fortress 2 from the dropdown menu as pictured below.
![8.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/8.jpg)
Open up your QC file and hit Compile. If everything went smoothly it should look like this.
![9.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/9.jpg)
Now your model is ready to be place in a testmap as a prop_physics or loaded into the Model Viewer! To view your model in the Model Viewer, open up Source SDK, select Orange Box for the engine and Team Fortress 2 for the game. Then double click on Model Viewer. Go to File/Open and find the folder where you told the QC to place your model. Double click on it and then double click on the model.
![10.jpg](https://dl.dropbox.com/u/3360480/TF2%20Physics%20Hat%20Tut/10.jpg)
Now that you've got your model in TF2/Model Viewer you can see how it looks with TF2's shaders and easily change the phong settings to test how they look with Source's shaders. While in the Model Viewer you can press F5 to quickly refresh your model with your latest VMT/VTF.
You can read up on how to modify the phong settings in your VMT to get what you want
here or just copy Valve's settings from their hats until you find one you like.
Hopefully this tutorial helped you understand the complex process of getting a model into Source! Good luck with your hats!
Replies
It organizes your code and colorizes the text making things easier to see whats going on.
Also tabbed browsing of QC files.
It'll definitely save you from making the stupid mistakes of forgetting to close a bracket or a typo or something like that. It's not fun recompiling over and over only to find it's something lame like that.
notepad ++
http://notepad-plus.sourceforge.net/uk/site.htm
Language file for QC editing
http://steamreview.org/external/vdc/npp-vdf.zip
Here's a pic:
EDIT: Can you explain how to install the QC plugin for Notepad++ for Windows 7? I tried it using the method for Windows Vista but it didn't work.
Awesome tutorial, definitely easier to understand than the one in the steam forums
Only one minor thing. You actually have to make sure it's the same name as your .vmt shader file. It doesn't look up the names of the vtfs, those are all defined in the vmts.
Ah ok thanks. I always just assumed it was the VTF because Valve's and my own textures always have the VTF and VMT named the same thing. I'll change that now.
Also can you explain how to install the QC Plugin for Notepad++ on Windows 7?
Put in in the same folder as the vista one, and then in the top tool bar in notepad++ select language > VDF-QC
Windows is hiding that folder from me though and it won't let me extract from WinRar to it. Do you know how I can bypass Windows hiding it?
You don't have to put the .vtf in max, it's defined in qc and vmt. So you can use your psd directly in max for example, as long as it has the right name.
Now just add some lines to explain how to replace an official hat in-game and i think it's totaly overcomplete
Basicaly, just by renaming in the qc
$modelname "testhat/testhat.mdl"
by some existing hat name like
testhat/pyro_domination.mdl" or smthing.
Not sure if it has to be in C\Steam\steamapps\blabla\team fortress 2\tf\materials\models\player\items\ to work properly ?
Again, big thanks to you, coz tutorials are lots of work.
The error GUIStudioMDL gave me is:
I removed the "read only" check on the sourceSDK folder, but it's still not working. I think it might be the weird switch between back slashes and forward slashing in the paths, but I have no idea why it suddenly changes to forward slashes or how to change it.
Any help is greatly appreciated
edit1: For some weird reason polycount won't let me use back slashes in my paths.. so I replaced them with a ~
edit2:
I just noticed that the slash switch is being caused by the .qc file (since the code i got from polycount uses forward slashes instead of backwars slashes).
The problem is that GUIStudioMDL also seems to use forward slashes.
edit:
Oh I'm sorry I fail.... If I did a better job reading I would have noticed that mine are in tf/materials/models instead of tf/models.
Thanks Surfa, that fixed it... Gah I feel stupid now...
:S
EDIT: GOt it sorted.
If anyone's a modo user, I've written an SMD exporter for it. Static mesh only at the moment (no animation or bones) but it should do fine for static props and collision meshes.
http://www.farfarer.com/resources.htm
Off the top of my head I think you have to run the game once for the gameinfo.txt to show up in the root TF2 folder. You also have to set the path to the gameinfo.txt in guistudio. Since it handles both Orange box and HL2 if you haven't installed or launched HL2 it will always complain. it should be fine to set it to TF2 and compile.
Anyone have a tutorial on how to get stuff actually inside the game? (without overwriting the current stuff?). I've been browsing google for a bit but it's not all that easy to find a good tutorial.
I'm mainly thinking weapons here.
Everything looks like it works fine but then when I try and view the model i get "error loading model". Further investigation shows the .mdl files are very small
So my first troubleshoot was to try re-importing the smd into maya. Looks fine, there's an extra joint that has appeared at origin with the model name but that's it.
The only way that I can see I've deviated from your guide is by using the idle from an existing hat as suggested in this guide:
http://forums.steampowered.com/forums/showthread.php?t=1109465
(following this guide I get exactly the same problem)
The maya smd exporter only has "export as reference" and "export each model as separate body group" as tick box options. So I cant change the export range.
Any suggestions as to what my next step should be would be gratefully recieved. I'm running out of ideas.
Also I'm fixing the image links now
sorry new to all this not sure what im doing...
if i have to bake it can someone please direct me somewhere to learn how to do this?
thanx
Finally I have some free time and decided to try get my items in game.
I've done and re-read this lesson a dozen times:poly105:, but in result always getting a model with Purple / Black Checker instead of my textures. All the possible errors that can be found through Google, I checked.
So I went through all actions with two of my models. And also tried to add my hat by using the name testhat, to use your vmt and qc codes unchanged.
I use max2009 and all soft that you pointed.
Are your .VMT and .VTF files in the right location based off of what you put in the .QC and do they have the correct file paths?
If you're sure you did those and it still doesn't work then post your .QC and .VMT files on here.
I did everything again, the result is the same.
Please take a look on picture and my .QC and .VMT files (I used the name testhat, so they are actually yours).
VMT:
"VertexlitGeneric"
{
"$baseTexture" "models\testhat\testhat"
"$bumpmap" "models\effects\flat_normal"
"$phong" "1"
"$phongexponent" "25"
"$phongboost" "5"
"$lightwarptexture" "models\lightwarps\weapon_lightwarp"
"$phongfresnelranges" "[.25 .5 1]"
"$basemapalphaphongmask" "1"
"$rimlight" "1"
"$rimlightexponent" "4"
"$rimlightboost" "2"
}
QC:
$modelname "testhat/testhat.mdl"
$model "Body" "testhat.smd"
$cdmaterials "models/testhat"
$sequence idle "testhat_idle.smd" fps 30.00
$collisionmodel "testhat_phys.smd" {
$concave
$mass 4.0
$inertia 1.00
$damping 0.00
$rotdamping 0.00
}
$keyvalues { prop_data { "base" "cloth.Small" } }
"$baseTexture" "models\testhat\testhat"
should be
"$baseTexture" "models\testhat"
I knew that miracles do not happen and I over and over again repeat the same mistake. All turned out, thank you very much for help.:)
This is the message I keep getting:
After that nothing happens. Any of you have an idea of what I'm doing wrong?
The only error I get when starting GUIStudioMDL is:
But since I'm using orange box and not EP1 it shouldn't cause the problem right? (I'll see if I can fix the error either way)
Anyway, all the help would be appreciated, thanks!
I have a folder on my desktop that contains the:
testhat.smd
testhat_idle.smd
testhat_phys.smd
testhat.qc
And a folder in "...\team fortress 2\tf\materials\models\" called testhat containing:
testhat_diffuse.vmt
testhat_diffuse.vtf
Then I have a folder in "...\team fortress 2\tf\models\" called testhat which is still empty.
Could it be that GUI Studio is caps sensitive? Because max exports .SMD files and the .qc file says smd.
Also my smd exports use the tga as diffuse, not the vmt conversion.
$model "Body" "testhat.smd"
$cdmaterials "models/testhat"
$sequence idle "testhat_idle.smd" fps 30.00
$collisionmodel "testhat_phys.smd" {
$concave
$mass 4.0
$inertia 1.00
$damping 0.00
$rotdamping 0.00
}
$keyvalues { prop_data { "base" "cloth.Small" } }
I don't think I changed anything.
If that's not the issue then I think you might have installed GUIStudioMDL wrong or something. Looking at your original post it says "oran gebox\". That should be "orangebox\" although that could have just been a paste error.
The QC file and the smd files are in the same folder, and "oran gebox" was indeed a copy paste error.
I guess I'll just start from the start again, I must have messed up at some point.
Just making sure I got everything in the tutorial right:
When I create the bone it will always adds an extra bone, I deleted that last time So I just had the 1 bone. Is this the right way to do it?
Do I only link the bone to the object through the skin modifier on the mesh? Or do I also have to use the "select and link" tool?
Do the physics mesh and ingame mesh share the 1 bone? Or do I give both their own?
Sorry for the basic questions, just wanna make sure I do it right this time. Thanks again for the help.
You only have to link the bone to the object through the skin modifier if it's a single bone.
The physics mesh should use the same bone as the in game one.
If the bones are what's causing trouble, you can just not use any bones and remove the line $keyvalues { prop_data { "base" "cloth.Small" } } from your .QC and add $staticprop to the .qc after $cdmaterials. This will compile the item as a static prop so you can view it in Modelviewer the same as you would a physics prop or a hat.
First off, THANKS for the sweet tutorial. I was able to get everything working on the first try!
My problem is now viewing the model in-game. I've followed the instructions on this page:
http://www.polycount.com/forum/showthread.php?t=74078&highlight=compile
and I'm able to get my hat into the game by replacing the parasite hat for the sniper. Unfortunately it's not on his head, and it does not appear to be following his head movements, but rather his hips.
I'm a total noob with Source, but I'm pretty advanced with Max and Maya. I'm pretty sure the weighting information isn't being compiled because my hat does the same thing even if I delete the bone and skinning information altogether. It still sticks to the sniper's hips.
I've used the exact naming convention for testhat in this thread in my files and .qc file.
Any suggestions how I can get the hat to follow my sniper's head and not his crotch?
Thanks in advance!
Also... is there any way to unlock hats in-game without earning them? I tried last night to get unlock the Ghastly Gibus, but I'm such a noob I can't dominate $#!% let alone a guy wearing a specific hat.
I'm 3 years behind in TF2 skills.
Thanks for your help!
Even if you don't have any unlocked, you can test their attachment in HLMV (half-life model viewer) pretty easily. Just load up a character model (in models\players), then go to file -> load weapon and choose your hat model.
Also, an alternative to decompiling a hat is to import a character's SMD into max. You can find them in your source_sdk_content folder (assuming you have the source sdk installed). Then you can properly position your hat onto the character, link it to the proper bone, hide the character and export from there.
Here's something wierd. I was able to get the Ghastly Gibus, but for some reason it *sometimes* doesn't show up in my loadout. I loaded up the game yesterday and it wasn't there, but the day before it was... WTF?
Note: NEM's GCP Scape utility may not be able to extract TF2 content packages. Apparently it won't work at extracting TF2 data until this weekend when he sends out the latest update. I was wondering why I suddenly started getting errors.
http://nemesis.thewavelength.net/
I've book marked this until I can learn how to use 3DS MAX 2011