Professional Documents
Culture Documents
INTRODUCTION __________________________________________________________________________1
TOOLS YOU WILL NEED _____________________________________________________________________1
REQUIREMENTS ____________________________________________________________________________1
EXTRACTING INFORMATION AND RESOURCES ____________________________________________________2
DECOMPILING _____________________________________________________________________________3
Possible Problems ________________________________________________________________________4
A QUICK EXPLANATION OF THE .QC FILE _______________________________________________________5
IMPORTING INTO 3DSMAX ___________________________________________________________________5
RIGGING THE WEAPON ______________________________________________________________________5
Side Note: Naming Conventions for Bones_____________________________________________________5
CREATING A REFERENCE FILE _________________________________________________________________6
CREATING AN IDLE ANIMATION _______________________________________________________________6
CREATING VMT AND VTF FILES ______________________________________________________________7
EDITING THE QC ___________________________________________________________________________8
Problem with My .QC ____________________________________________________________________9
COMPILING THE .QC________________________________________________________________________9
Possible Problems ________________________________________________________________________9
USING HLMV (HALF-LIFE MODEL VIEWER) ___________________________________________________10
Possible Problems _______________________________________________________________________11
CHECKING VIEWMODEL MODE ______________________________________________________________11
MOVING A MODEL WITH THE $ORIGIN COMMAND _______________________________________________12
CHECKING MODEL IN-GAME ________________________________________________________________12
Introduction
For this tutorial, we will replace a weapon that is currently in the single player HL2
game. You can create weapons for your own mod or add new weapons to HL2 by using code,
but for this tutorial we will keep it simple. This tutorial is used to create a very simple v_model,
and should be used by beginners.
Cannonfodders StudioCompiler we will use this tool strictly for decompiling purposes (LINK:
http://files.filefront.com/StudioCompilerexe/;5191522;;/fileinfo.html) (NOTE: This is the fix for the
broken studiocompiler, if that doesnt work, try this http://www.forum.ecct2.com/index.php?showtopic=4 )
VTFEdit we will use this tool to create the .vtf and .vmt files we will need for HL2 to recognize the
textures for the model (LINK: http://nemesis.thewavelength.net/index.php?c=178#p178)
GCFScape we will use this tool to extract files that are found within .gcf file types
(LINK:
http://nemesis.thewavelength.net/index.php?p=26)
SMD Importer/Exporter for 3dsMax we will use this tool to import/export .smd filetypes (LINK:
http://www.chaosincarnate.net/cannonfodder/cftools.htm)
Requirements
Once inside the source models.gcf, you will be directed to a root folder. Inside the root
folder will be a hl2 and a reslist folder. Open up the hl2 folder. Inside that folder, open up the
models folder and then open up the weapons folder inside there. Now, at this stage you have
several options. If you want some reference for how v_models work, you can select any weapon
that is preceded by a v_. For example, if you are replacing the pistol, you could select all the
v_Pistol filetypes in the models folder. (NOTE: to select multiple files at the same time, use the
right window). If you know how you want your gun to work, you could also just extract all files
that start with v_hands. (NOTE: decompiling the v_Pistol.mdl will give you these hands, but
will also give you a reference for how the gun works)
For this tutorial, I will be extracting a current gun that is in the game: the Pistol. So, I
select all the files that start with v_Pistol in the right window.
Fig. 02
To extract these files, you can either right click and choose extract, or you can drag to
your created folder. Either way, extract these files to your folder. Once the files are in there,
close out GCFScape and restart Steam.
Decompiling
Once Steam is completely loaded, open Cannonfodders StudioCompiler. (NOTE: THIS
IS IMPORTANT. Open up your Source SDK under your tools section in steam, and make sure
the Current Game is Half Life 2. You can find this section at the bottom of the SDK menu). Go
to the Model Decompile Tab located just under the top line of StudioCompiler. Type in the path
of your .mdl weapon file that you are decompiling. So, for this tutorial, I would decompile
v_Pistol.mdl. Select the desired location for the decompiled weapon. For simplicity, keep
everything close by creating a subfolder inside the folder you extracted your weapon files. Once
you have done that, click extract. If the weapon does not extract, check the checklist below for
possible problems.
Fig. 03
Possible Problems
You dont have all the files needed to extract. Close out steam and open up GCFScape
and make sure all of the files for your weapon are in your extraction folder.
You arent decompiling a .mdl file. You only need to decompile the .mdl file.
Once the model has been completely dumped into your decompile folder, you can check
out information regarding the decompiled model. This information can be found in the .qc file.
Fig. 03a
You will now need to create bones for the attachment points. As I stated earlier,
attachment points are points on your weapon that the game will use for things such as a muzzle
flash or a shell ejection point. YOU MUST REMEMBER THE NAMES OF THESE BONES,
YOU WILL NEED THIS INFORMATION FOR YOUR .QC FILE. So, I create a bone at the
end of my weapons barrel and name it v_weapon.Pistol_muzzle. I also create a bone at the shell
ejection point and name it v_weapon.Pistol_eject.
Once all the bones are created, link all bones you created for your weapon to your parent
bone. Now, skin your meshes to these bones. Select any unmoving part of your gun, add a skin,
and select only your parent bone. Select any mesh that you wish to have move, skin it, and add
the respective bone that you wish to move it. Attachment bones do not get skinned, they are
used as a reference for the engine only.
your hands. Do not rotate the position of the hands, keep them facing in the same direction.
(NOTE: When animating, it helps to link the parent bone of your gun to the right hand bone)
Now, manipulate the bones in the hands so that it looks about right, animate it as you want, and
save your file as v_WEAPONNAME_idle. Select FileExport and export this as an .smd file to
the same folder as your reference .smd. Make sure you select Skeletal Animation this time.
If you are having problems when it comes to animating because the bones seem to be
rotating around the parent bone, select all of your bones you created for your weapon, go to
CharacterBone Tools, and open up the Object Properties dialogue found at the bottom.
Uncheck Freeze Length and Auto-Align and for Stretch select none.
After creating your .vmt and .vtf files for each of your guns textures, you will need to
change the location of your actual textures that you used to map your gun (your source textures,
i.e. .tga or .jpg). Place your texture(s) in the
Steam\steamapps\USERNAME\sourcesdk_content\hl2\materialsrc\models\weapons folder (if
some of these folders dont exist, create them).
Editing the QC
After creating your reference, animations and creating your texture files, the time comes
for you to create the QC for your weapon. The QC file tells the compiler how to compile your
weapon. For this tutorial, our .QC file will be very simple. It will consist of a model name, a
directory for the materials, a single sequence and some information for attachment points. To
create a .QC, first create a new .txt document and rename it to YOURWEAPONSNAME.qc.
(NOTE: Make sure you have Hide Known File Extensions unchecked in your folder options)
Fig. 05
Any command in a .QC file must be preceded by a $. So, our first command,
modelname, tells the compiler where to place the model and also gives the name of the model. I
have chosen to name my model v_pistol.mdl, which will replace the current pistol that is in the
game, and place it in the weapons subdirectory of the Half-Life 2 models folder. The reason this
model will be placed there is that this is a relative path, and since our game that we chose to
modify in our Source SDK was HL2, it will place it in its models folder. Make sure that you
place the value that follows the modelname command within quotes (NOTE: If you do not have
a weapons subdirectory in your models folder, you will need to create it).
The next command, scale, tells the compiler at what scale to make the gun. Since our
scale should be proportional to the hands, which have already been scaled correctly, go ahead
and make the value that follows this 1.0.
The next command, body, tells the compiler what the main body of the gun is. The first
value that follows the command is the name of your body, and the next value is the directory that
holds your reference file for that portion of the body. Note that this path is absolute. Had I
placed my .smds that I exported inside my Half-Life 2 folder, I would not need to use an
absolute path. To ensure a safe compile, copy down the absolute path of your reference .smd and
include the name of your reference .smd.
The next command, attachment, lets the compiler to know the bones that will be used as
attachment points. The first attachment point I created in my .QC was the muzzle, so I properly
named it (the name of the attachment is the first value that should follow the attachment
command). The next value will be the name of the bone that is represents the attachment point.
In my case, the bone name was v_weapon.USP_muzzle. Open up 3dsMax to ensure that you get
the name of this attachment point absolutely correct. The next 3 numeric values represent the
translation of the bone to position it properly in the order of X Y Z (NOTE: X will move your
point left (-) and right (+), Y will move your point in (-) and out (+), and Z will move your point
8
up (-) and down (+)). If your attachment points position needs tweaking, you can adjust the
values in HLMV and copy the new line of code and replace it in your .QC, but for now leave
these values as all zeroes. Following the translation amounts is the sub-command rotate
followed by the rotation amounts, again in the order X Y Z. Leave these values as zero. Do the
same for any other attachment points that you have in your model.
The next command, surfaceprop, tells the compiler what kind of material your textures
are made from. For simplicity, keep this value as metal.
The next command, cdmaterials, represents the directory the materials for your weapon
are located. Since we saved our values for our textures already in our
HL2\materials\models\weapons folder, we can simply put models\weapons as the value that
follows this command.
Our model is made up of multiple parts (the arms and the gun), and there may be
different locations that the textures are placed. Fortunately for us, when we decompiled the
v_Pistol.mdl, we were given the information that we needed to locate the directory that the arm
textures are located. To view this information, open up your mdldecompiler.qc file (this file
should be located in the directory where you decompiled your model). Look for the line that
says $cdmaterials "models\weapons\v_hands". This is the location of the textures for the arms
and hands that are used in your model. We did not need to decompile these textures and place
them in our materials folder because they are already in the .gcf files for Half-Life 2. (NOTE:
The Source Engine first looks to the folders for information for the models, materials, etc. If it
does not find it there, it then goes into the .gcf files and searches there.)
The final command, sequence, tells the compiler of any animations that the model has.
All view models must have at least one sequence. The first value that follows the command is
the name of the sequence. The next value is the location of the .smd that holds the sequences
motions. This .smd must be a skeletal animation. The rest of the line holds the name of the
event to run when running that sequence (in this case, AE_VM_IDLE), the amount of times to
run it (1) and the fps to run it at (fps 16.00). (NOTE: I mistakingly have a 1 where I should have
loop. The value loop makes the animation repeat over and over, where 1 will make the
animation only play once.)
Problem with My .QC
Did you notice a problem within my .QC? The name of the bone for my second
attachment point is incorrect. It should read v_weapon.USP_eject, but instead it reads
v_weapon.USP_release. This weapon will not compile. I will need to go back and fix my
mistake.
Make sure your reference .smd was exported as a reference and your sequence .smd was
exported as a skeletal animation.
Make sure your weapons folder is created in your model folder for Half-Life 2.
Make sure you have all string values placed in quotes.
10
Possible Problems
The reference .smd file points to a different texture. Open up your reference .smd file
and scroll down until you see the name of your gun texture that you applied to your gun
in 3dsMax. Make sure this name is identical to the file you placed in your
materialsrc\models\weapons folder. If it is not, use replace all to replace the name of the
bad texture with the name of the actual texture. Save and recompile.
Make sure your .vmt has a shader type of VertexLitGeneric.
Make sure your .vmt has the relative path models\weapons\NAMEOFTEXTURE. The
name of the texture should not include the file extension.
Make sure you are using a supported texture file type.
11
12