You are on page 1of 12

CREATING A V_MODEL FOR HALF LIFE 2 USING 3DSMAX

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.

Tools You Will Need

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

HL2 installed and ran once


Source SDK installed and ran once
A 3d weapon created in 3dsmax textured using UVW Mapping. All moving parts must be separate meshes.

Extracting Information and Resources


First, create a folder somewhere to hold the extracted information. Make sure Steam is
closed out, and open up GCFScape. Go to File Open, and go to your SteamSteamApps
folder. Once there, open up your source models.gcf file.
Fig. 01

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.

A Quick Explanation of the .QC File


StudioCompiler will create an mdldecompiler.qc file that will hold some important
information that HL2 uses when compiling the model. This information includes the name of the
model, the textures of the model, the animation (also known as sequences) of the model, any
attachment points of the model (which are used to signify points of importance, such as where to
place the muzzle flash or where shells are ejected). We will cover these details much more
thoroughly once we reach the point where we create our own .qc file.

Importing into 3dsMax


Open up 3dsMax. Select FileImport and select your hands_reference.smd. Once the
hands are in 3dsMax, merge your weapon into the scene by selecting FileMerge and choosing
your .max file that holds your weapon. At this stage, you can place the gun anywhere, but you
will need to create bones for the weapon.

Rigging the Weapon


Rigging a weapon means preparing the mesh to be used in game. In order for the engine
to understand the weapon, we must add bones that have significant meanings. To begin, create a
parent bone for the gun. The parent bone will act as the main bone for the weapon; all other
bones will be linked to this bone.
Side Note: Naming Conventions for Bones
When working with a group of people or even by yourself, it is important that you
standardize naming conventions to keep yourself and others from getting confused. This follows
true even inside max, where naming your bones in a uniform way will pay off later. While the
bones actually can be named anything, it is more organized and just better practice to follow
naming conventions.
So, for the first bone you created, name it v_weapon.WEAPONNAME_Parent, where
WEAPONNAME is the name of your weapon. So, for my weapon, it would be
v_weapon.Pistol_Parent. (NOTE: If you have your own naming conventions, feel free to follow
them). Create more bones for any moving part. In my case, I create a bone for my slider, clip,
hammer and trigger. Place these bones at the locations they will be most effective. For example,
I place my trigger bone perpendicular to the weapon so that I can rotate it easier, where I place
my clip bone inside the clip so that I can translate and rotate it easier. Any moving part MUST
be a separate mesh or at least a separate element to ensure smooth animations. So, for my gun, I
create a bone for the slider, hammer, and trigger and name them following my naming
convention (So, my slider name would be v_weapon.Pistol_slider. Take a look at the picture on
the next page for reference. Notice the orientation of the bones.)

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.

Creating a reference file


Once all the bones have been linked and skinned to their respective meshes, save your
3dsMax file as v_WEAPONNAME_ref. Select FileExport and export this as a .smd file
anywhere you want. I suggest making a new folder to hold your created .smd files. Once you
click save, it will ask what type of .smd file this is: a Skeletal Animation or a Reference. Make
sure you select Reference. References hold the information of the model such as bones and
texture information. The texture that you have on your weapon at the time of exporting will be
used in your reference .smd. HL2 does not support textures made in 3dsMax.

Creating an idle animation


Now comes the part where we create the animations (in this case, the animation) for our
weapon. Move the hands until they intersect the x plane at about elbow length. Select your
weapon, and move it into about the position that you want. Make sure the weapon is in front of

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.

Creating VMT and VTF Files


Open VTFEdit. Import your texture(s) that you used to map your gun, and save the file as
the same name as your texture (NOTE: HL2 only supports some filetypes. Check the HL2 wiki
to make sure yours is supported, or just use a .jpg or .tga to be sure). Save this file in your
Steam\steamapps\USERNAME\half-life 2\hl2\materials\models\weapons folder, where
username is your steam account name. The first time you do this, you will need to create the
models and weapons folder inside the materials folder. Once that is saved, go to ToolsCreate
VMT File. This will open up a dialogue box with 2 tabs. The first tab, Textures, allows you to
specify the locations for different textures. This will not be covered in this section. What you
should have is the location of the first base texture. Now, simply select the second tab that says
Options. In the first drop down box, change the type of shader to VertexLitGeneric. Do not
change any other options (all other dialogue boxes should be empty and all checkboxes should
be unchecked).
Fig. 04

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.

Compiling the .QC


Once you have completed the last step, save your .QC file. It does not matter what its
name is, but again, to avoid confusion, just name it the same as you named your model (in my
case, v_Pistol.qc). Now, right click on that .QC you just saved, go to open with, go to Browse,
and go to your Steam\steamapps\USERNAME\sourcesdk\bin and select studiomdl.exe (NOT
STUDIOCOMPILER!!!). The model should then compile. If it does not, check below for
possible problems.
Possible Problems

Check for any typos in your .QC file.


9

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.

Using HLMV (Half-Life Model Viewer)


Once your model has compiled, the time comes to check the placement of the model.
Open up your Source SDK under your Steams Tools tab, and select Model Viewer located
under Applications. Once HLMV has loaded, select File Load Model, and traverse to your
weapons folder and search for your models name (In my case I search for v_Pistol.mdl).
(NOTE: Most models that Half-Life 2 has in the game have .jpgs associated with their model so
that you can see the model before you load it. If that is the case with your model, just search for
YOURMODELSNAME.jpg. So, I search for v_Pistol.jpg). Select your model and choose open.
You should now see your model in the screen and fully textured. If nothing appears, try
moving the view around with the mouse buttons. If you see a model but it isnt yours, go back
and make sure you completed all the steps previous to this correctly. If you see your model, but
it isnt textured correctly, check below for possible problems.
Fig. 06

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.

Checking Viewmodel Mode


Once you are sure your model is there and it is completely texture, you can check its
location that it will show up in game. To do this, select OptionsViewmodel Mode. If you
cannot see your gun after doing this, it is in the wrong place. Scroll out to try to find its location
by right-clicking and dragging down.
Fig. 07

11

Moving a Model with the $origin Command


If the gun is not in the proper location, you will be able to move it by editing your .QC
file. Under the scale command in your .QC, type in $origin 0.00 0.00 0.00. The first set of
zeroes represents the movement of the origin left and right (X), the second set of zeroes
represents the movement in and out (Y), and the third set of zeroes represents the movement up
and down (Z). (NOTE: The first direction for each plane is in the negative direction. So left for
X is negative, in for Y is negative, and up for Z is negative). Play with these values, recompile
and keep checking the Viewmodel Mode of your weapon. Tweak these values until the gun
looks about right.

Checking Model In-Game


To check your model in game, begin by loading up Half-Life 2. Once it is loaded, go to
options, Keyboard options, and go to advanced. Enable the developer console and close out the
options menu. Press the ~ button (usually located above the tab), and type in map
d1_canals_03. Once the map has loaded, open the developer console again and type sv_cheats
1, hit enter, and then type impulse 101 and hit enter. Close the developer console and scroll
through all the weapons until you find yours. If you dont find yours, you probably did not use
the same model name that the game uses. If this is the case, open your .QC file and rename your
model in the top line as the same model name that Half-Life 2 uses.

12

You might also like