Saturday 25 April 2009

Making Physics Props for use in Hammer - Tutorial

Created and Written by Adam Parker.

To see the full version of this tutorial with all supporting images and material, download it from the following link!


Click Here to download Tutorial.

Hey, whoever’s reading this. You might have guessed what this guide is for, so I’ll not waste time with introductions. Basically, by the end of this you should have a working prop_phys for use in the Hammer design tool.

First up, this is what you’re going to need before you start:

- Hammer - obviously.

- 3D Studio Max (this tutorial is for this specific piece of 3D model software. It might not work with others and you probably need different plug-ins.)

- Photoshop (or any other image editing program.)

- StudioMDL (if you’ve got Source, you should have this. I’ll get to where you can find it in a moment). This is used to compile SMD files into an MDL file, which is the actual model.

- VTFEdit (The thing you use to make custom textures.)

- 3DSMax SMD Exporter plugin (This is needed to export your 3DSMax files as SMD files, the format Source uses to compile models.) You can find it at http://www.wunderboy.org/3dapps.php#max_smd

Optional stuff

This stuff isn’t needed for the process, but they do make this whole thing easier. They’re recommended.

- GUI StudioMDL. The normal StudioMDL runs in the command window, which closes as soon as it’s finished. This makes it hard to find out if any errors have occurred. This is exactly the same thing, except it runs in a proper window, letting you check for errors. It’s up to you which you use. You can find it at http://www.wunderboy.org/apps/guistudiomdl2.php


- Source MDL Texture Info. The most common problem with making a model is that the textures won’t be applied to it, causing the model to have a purple & black chessboard pattern. This is commonly due to an error in the file paths in the .vmt or .qc files. This tool will read these files and tell you which file path they are using to find the texture (.vtf) file, making this problem easier to correct. You can find it at http://www.fpsbanana.com/tools/384


-----------------------------------------------------------------------------------------------


Once you’ve got all these things downloaded & installed, you can start setting up the folders needed to make models.

First up, make your way to the C:\Program Files\Steam\SteamApps\YourNameHere folder. It’s a good idea to make a Desktop shortcut to the YourNameHere folder as you’ll be using it a lot.

Next choose which game your model is being made for. In this tutorial, I’m making mine for Half-Life 2 (note that any models made for Half-Life 2 can also be used for its expansions, Team Fortress 2 and Portal). From here, go to the hl2/models folder. In this folder, make a new folder called Custom Models. In the Custom Models folder, make another new folder with the name of whatever your model is called. The full name isn’t important; just make it something recognisable (I’ve called mine steamtank, for reasons which will become clear)

Go back to the hl2 folder, and open the materials folder. In here there should be a folder called models (if there isn’t just make one) and in the models folder make another folder called Custom Models and in this one, another folder with the name of whatever you’re making (steamtank again for me)

Finally, go to your YourNameHere folder, and go into sourcesdk/bin/ep1/bin. In here, find the studiomdl.exe and make a shortcut for it on the Desktop. Do the same for the GUI studiomdl.exe if you’re using that. Also in here is the hlmv.exe, which is the Model Viewer. It’s handy for checking if your model compiled correctly, so it’s helpful to make a shortcut for that too.

(All these shortcuts are to save time, instead of delving into all these folders constantly)

If you’ve got all these folders & shortcuts sorted out, you can start making the actual model!


-----------------------------------------------------------------------------------------------


The first step is to make your model in 3DSMax. In true Blue Peter tradition, here’s one I made earlier. It’s a steam powered tank.

An important thing to note is the grid that appears under the model. Valve uses this for scale, as you can see when you choose the World Model for props in Hammer. As a rough estimate, Dr. Freeman’s height is about equal to three of those squares. You can get a better estimate by carefully looking at the models in Hammer and how they relate to the grid.

Once your model is finished, put the bones in. If your model has no moving pieces, it only needs one. The bones are important as they affect how the model pivots in relation to the world it is in.

Next, go to the hammer tab on the very right of the screen, and click Reset Xform, then pick your model. Click the Reset Selected button in the Reset Transform dialogue that appears. After this, go to the Modify tab, right click Xform, select Collapse All and pick Yes.

After this, go to the Modifier list and pick Unwrap UVW. Do all the usual stuff that ends you up with your unwrapped .jpg to create the texture on.


Open this in Photoshop (or whatever you use) and texture your model as you would normally.


When you’ve done this, save your texture as a .tga file in your half-life 2\hl2\materials\models\custom models\YourModelName folder. Make sure you save it with the same name as your model. Once that’s done, close Photoshop and apply the texture to your model.


Now you can export your model. Go to File and pick Export. You need to save your model in the hl2/models/custom models/YourModelName. When you save it, name it the same as your model but add a _ref to the end of the name (So mine would be called steamtank_ref). Save it as an .SMD file and click Save. The SMD exporter window will pop up, click Okay on this window and the exporter will compile your model into an SMD file.

When it’s done, do the same process again but put _idle at the end of the name instead of _ref. The reason for this will become clear soon.


-----------------------------------------------------------------------------------------------


Next you’ll need to create a collision model for your model. A collision model is a very simple version of your model, only just the basic shape of it. See the picture for an example of a collision model.


As you can see, the collision model for the steam tank is a very basic wedge shape, with a box on the back for the chimney. When you’ve made the collision model, put the texture file onto it. It will look stupid, but that doesn’t matter because the collision model won’t be seen.

Use the SMD exporter to export this model to the same file as the others, but this time put _phys on the end of the name.

3DS Max can be closed now.

So now you should have a texture file in Targa format, and three SMD files. I’ll explain what each one is for now.

The _ref file is what you see in the game. It’s pretty simple.

The _idle file dictates animation. Models with animating parts will have more files for each part of their animation, but models with no moving parts only need a _idle file. Even though it won’t animate, a model still needs a _idle file because it also tells the game when and where to put damage like bullet holes.

The _phys file dictates how the model interacts with the geometry. It isn’t seen in game, but it is very important as it tells the game where things like other models will bounce off it, and where it will lie flat on the world.


-----------------------------------------------------------------------------------------------


Okay, the next step is to make the .vmt and .vtf for the model’s texture. This uses VTF Edit and is exactly the same process for making textures for geometry.

Open VTF Edit and import the Targa file for your texture. Click Okay on the box which pops up, and when your texture is loaded, save it as a .vtf file in the hl2/materials/models/custom models/YourModelName folder. Make sure you give it the same name as your model.

Next, open up Notepad and copy and paste this into it:

"VertexlitGeneric"

{

"$basetexture"

"$surfaceprop"

}

The $basetexture tells the vmt which texture it’s searching for, so put “models/custom models/YourModelName/YourModelName.vtf” just after it. $basetexture automatically starts its file path search in the Materials folder, so there’s no need for the full file path. The quote marks around the file path are important!

The $surfaceprop tells the vmt what type of texture it is, from cardboard to wood to metal. The following page has every type of $surfaceprop you can use, but you can only use one

http://developer.valvesoftware.com/wiki/Material_surface_properties

Pick which type is most suitable for your model and put it after $surfaceprop in quotation marks.

Save the file you just made as a .vmt file in the hl2/materials/models/custom models/YourModelName folder. The texture is now finished!


-----------------------------------------------------------------------------------------------


Next you’ll need to create a .qc file which is used to compile all the different parts of your model into a working thing you can put into Hammer. Copy the following into Notepad to get started.

$modelname "custom models\nozzle\YourModelName.mdl"

$body nozzle "YourModelName_ref.smd"

$staticprop

$surfaceprop

$cdmaterials "models\custom models\YourModelName"

$sequence idle "YourModelName_idle.smd" loops fps 15

$collisionmodel "YourModelName_phys.smd" { $concave }

$keyvalues

{

prop_data

{

base

}

}

After you’ve copied it, replace all instances of YourModelName with, well, the name of your model.

You also need a value for the $surfaceprop. This can be the same as the one entered in your .vmt file. Finally, you need an entry for the base value which is embedded in the $keyvalues property. You can find a complete list of base values at http://developer.valvesoftware.com/wiki/Prop_Data#Generic_prop_data

Pick the one most appropriate for your model.

This is the most basic .qc file, they can be much more complicated depending on what you want your model to do.

Here is the .qc file for my steam tank as an example

$modelname "custom models\steamtank\steamtank.mdl"

$body nozzle "steamtank_ref.smd"

$staticprop

$surfaceprop metalpanel

$cdmaterials "models\custom models\steamtank"

$sequence idle "steamtank_idle.smd" loops fps 15

$collisionmodel "steamtank_phys.smd" { $concave }

$keyvalues

{

prop_data

{

base Metal.Large

}

}

Once your .qc is finished, save it as a .qc file in the same folder as your exported SMD files.


-----------------------------------------------------------------------------------------------

Now to see if it all works. Drag and drop the .qc file into the GUIStudioMDL shortcut on your desktop. Once it’s loaded, click Compile. If all is well, there will be no errors and your model will have complied. A bunch of new files will have appeared in the same folder as the SMDs. Don’t mess with these unless you want to mess up something.

To see if it works, open Hammer, make a hollow box (or whatever you want to put it on) and put a prop_physics into the level. Open the prop_physics properties, click World Model and open the model browser. Find the custom models tab in the browser & click on your model name. If its all gone according to the tutorial, it should work!