creating a v_model using 3dsmax

Upload: alfatih-jundullah

Post on 06-Jul-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 Creating a V_Model Using 3dsMax

    1/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 HL2game. 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•  Cannonfodder’s 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 doesn’t 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 thetextures 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.

    1

  • 8/17/2019 Creating a V_Model Using 3dsMax

    2/12

    Extracting Information and ResourcesFirst, 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 SteamSteamAppsfolder. 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 themodels folder and then open up the weapons folder inside there. Now, at this stage you haveseveral options. If you want some reference for how v_models work, you can select any weaponthat is preceded by a v_. For example, if you are replacing the pistol, you could select all thev_Pistol filetypes in the models folder. (NOTE: to select multiple files at the same time, use theright window). If you know how you want your gun to work, you could also just extract all filesthat 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.

    2

  • 8/17/2019 Creating a V_Model Using 3dsMax

    3/12

    Fig. 02

    To extract these files, you can either right click and choose extract, or you can drag toyour created folder. Either way, extract these files to your folder. Once the files are in there,

    close out GCFScape and restart Steam.

    DecompilingOnce Steam is completely loaded, open Cannonfodder’s StudioCompiler. (NOTE: THIS

    IS IMPORTANT. Open up your Source SDK under your tools section in steam, and make surethe Current Game is Half Life 2. You can find this section at the bottom of the SDK menu). Goto the Model Decompile Tab located just under the top line of StudioCompiler. Type in the pathof your .mdl weapon file that you are decompiling. So, for this tutorial, I would decompilev_Pistol.mdl. Select the desired location for the decompiled weapon. For simplicity, keepeverything 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.

    3

  • 8/17/2019 Creating a V_Model Using 3dsMax

    4/12

    Fig. 03

    Possible Problems

    •  You don’t 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 aren’t 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 checkout information regarding the decompiled model. This information can be found in the .qc file. 

    4

  • 8/17/2019 Creating a V_Model Using 3dsMax

    5/12

    A Quick Explanation of the .QC FileStudioCompiler 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 themodel, the textures of the model, the animation (also known as sequences) of the model, anyattachment 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 morethoroughly once we reach the point where we create our own .qc file.

    Importing into 3dsMaxOpen 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 choosingyour .max file that holds your weapon. At this stage, you can place the gun anywhere, but youwill 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 engineto 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 youstandardize naming conventions to keep yourself and others from getting confused. This followstrue 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 follownaming conventions.

    So, for the first bone you created, name it v_weapon.WEAPONNAME_Parent, whereWEAPONNAME is the name of your weapon. So, for my weapon, it would bev_weapon.Pistol_Parent. (NOTE: If you have your own naming conventions, feel free to followthem). 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 placemy 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, Icreate a bone for the slider, hammer, and trigger and name them following my namingconvention (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.)

    5

  • 8/17/2019 Creating a V_Model Using 3dsMax

    6/12

    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 muzzleflash 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 theend of my weapon’s barrel and name it v_weapon.Pistol_muzzle. I also create a bone at the shellejection 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 addthe respective bone that you wish to move it. Attachment bones do not get skinned, they areused as a reference for the engine only.

    Creating a reference fileOnce 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 fileanywhere you want. I suggest making a new folder to hold your created .smd files. Once youclick 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 andtexture information. The texture that you have on your weapon at the time of exporting will beused 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 yourweapon, and move it into about the position that you want. Make sure the weapon is in front of

    6

  • 8/17/2019 Creating a V_Model Using 3dsMax

    7/12

    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, andsave your file as v_WEAPONNAME_idle. Select FileExport and export this as an .smd file tothe 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 berotating around the parent bone, select all of your bones you created for your weapon, go toCharacter Bone 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 FilesOpen 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 wikito make sure yours is supported, or just use a .jpg or .tga to be sure). Save this file in yourSteam\steamapps\USERNAME\half-life 2\hl2\materials\models\weapons folder, whereusername 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 ToolsCreateVMT File. This will open up a dialogue box with 2 tabs. The first tab, Textures, allows you tospecify the locations for different textures. This will not be covered in this section. What youshould have is the location of the first base texture. Now, simply select the second tab that saysOptions. In the first drop down box, change the type of shader to VertexLitGeneric. Do notchange any other options (all other dialogue boxes should be empty and all checkboxes should be unchecked).

    Fig. 04

    7

  • 8/17/2019 Creating a V_Model Using 3dsMax

    8/12

      After creating your .vmt and .vtf files for each of your gun’s textures, you will need tochange 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 theSteam\steamapps\USERNAME\sourcesdk_content\hl2\materialsrc\models\weapons folder (ifsome of these folders don’t exist, create them).

    Editing the QCAfter 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 yourweapon. For this tutorial, our .QC file will be very simple. It will consist of a model name, adirectory for the materials, a single sequence and some information for attachment points. Tocreate 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. Ihave chosen to name my model v_pistol.mdl, which will replace the current pistol that is in thegame, and place it in the weapons subdirectory of the Half-Life 2 models folder. The reason thismodel will be placed there is that this is a relative path, and since our game that we chose tomodify 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 havea 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 ourscale should be proportional to the hands, which have already been scaled correctly, go aheadand make the value that follows this 1.0.

    The next command, body, tells the compiler what the main body of the gun is. The firstvalue that follows the command is the name of your body, and the next value is the directory thatholds your reference file for that portion of the body. Note that this path is absolute. Had I placed my .smd’s that I exported inside my Half-Life 2 folder, I would not need to use anabsolute path. To ensure a safe compile, copy down the absolute path of your reference .smd andinclude the name of your reference .smd.

    The next command, attachment , lets the compiler to know the bones that will be used asattachment points. The first attachment point I created in my .QC was the muzzle, so I properlynamed 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 getthe name of this attachment point absolutely correct. The next 3 numeric values represent thetranslation 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

  • 8/17/2019 Creating a V_Model Using 3dsMax

    9/12

    up (-) and down (+)). If your attachment point’s position needs tweaking, you can adjust thevalues in HLMV and copy the new line of code and replace it in your .QC, but for now leavethese values as all zeroes. Following the translation amounts is the sub-command rotatefollowed by the rotation amounts, again in the order X Y Z. Leave these values as zero. Do thesame for any other attachment points that you have in your model.

    The next command, surfaceprop, tells the compiler what kind of material your texturesare 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 ourHL2\materials\models\weapons folder, we can simply put models\weapons as the value thatfollows this command.

    Our model is made up of multiple parts (the arms and the gun), and there may bedifferent locations that the textures are placed. Fortunately for us, when we decompiled thev_Pistol.mdl, we were given the information that we needed to locate the directory that the armtextures are located. To view this information, open up your mdldecompiler.qc file (this fileshould 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 armsand hands that are used in your model. We did not need to decompile these textures and placethem 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 itdoes 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 isthe name of the sequence. The next value is the location of the .smd that holds the sequencesmotions. This .smd must be a skeletal animation. The rest of the line holds the name of theevent to run when running that sequence (in this case, AE_VM_IDLE), the amount of times torun it (1) and the fps to run it at (fps 16.00). (NOTE: I mistakingly have a 1 where I should haveloop. The value loop makes the animation repeat over and over, where 1 will make theanimation only play once.)

    Problem with My .QC

    Did you notice a problem within my .QC? The name of the bone for my secondattachment point is incorrect. It should read v_weapon.USP_eject, but instead it readsv_weapon.USP_release. This weapon will not compile. I will need to go back and fix mymistake.

    Compiling the .QCOnce 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 mycase, 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 (NOTSTUDIOCOMPILER!!!). 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

  • 8/17/2019 Creating a V_Model Using 3dsMax

    10/12

    •  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 Steam’s Tools tab, and select Model Viewer locatedunder Applications. Once HLMV has loaded, select File Load Model, and traverse to yourweapons 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 sothat you can see the model before you load it. If that is the case with your model, just search forYOURMODELSNAME.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, trymoving the view around with the mouse buttons. If you see a model but it isn’t yours, go backand make sure you completed all the steps previous to this correctly. If you see your model, but

    it isn’t textured correctly, check below for possible problems.

    Fig. 06

    10

  • 8/17/2019 Creating a V_Model Using 3dsMax

    11/12

    Possible Problems

    •  The reference .smd file points to a different texture. Open up your reference .smd fileand scroll down until you see the name of your gun texture that you applied to your gunin 3dsMax. Make sure this name is identical to the file you placed in yourmaterialsrc\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. Thename of the texture should not include the file extension.

    •  Make sure you are using a supported texture file type.

    Checking Viewmodel ModeOnce 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 youcannot 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

  • 8/17/2019 Creating a V_Model Using 3dsMax

    12/12

    Moving a Model with the $origin CommandIf 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 ofzeroes represents the movement of the origin left and right (X), the second set of zeroesrepresents 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 forX is negative, in for Y is negative, and up for Z is negative). Play with these values, recompileand keep checking the Viewmodel Mode of your weapon. Tweak these values until the gunlooks about right.

    Checking Model In-GameTo 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 theoptions menu. Press the ~ button (usually located above the tab), and type in “mapd1_canals_03”. Once the map has loaded, open the developer console again and type “sv_cheats1”, hit enter, and then type “impulse 101” and hit enter. Close the developer console and scrollthrough all the weapons until you find yours. If you don’t find yours, you probably did not usethe same model name that the game uses. If this is the case, open your .QC file and rename yourmodel in the top line as the same model name that Half-Life 2 uses.

    12