Snarkpit Articles


Today I will be helping you setup and export a simple model into Half-Life 2. I will be exporting a static model, although a lot of properties between the types (physics, dynamic, detail, ragdoll) are shared. Before we begin you will need the following tools:

VTFEdit (used for converting .tga to .vmt / .vtf; Some people use the Photoshop plugin, I however, do not)

Milkshape 3D (Milkshape is a free [trial] program that allows for quick and easy exporting of Half-Life 2 SMD's without any trouble. You can also use 3DS Max or Maya, but I havenot gotten them to work correctly so we will use Milkshape. NOTE: Milkshape 3D crashes. I mean, a damn lot. Be sure to save your work every time you make a change just to be safe)

Photoshop (Paintshop is fine too, anything that can export 32-bit .tga's).
There is another tool I don't use, but is widely used by the community, so I will be listing it. It is Cannonfodder's Studio Compiler which makes updates to the studiomdl compiler. The only real changes are aesthetic that make it easier to navigate and compiler (it gives you individual options for each model format).

Now that you have all of your tools we can get started.

Step 1: Creating your model (if you already have a completed model skip over this section). Some of you may not want to destroy their models trying to convert them so I will be creating a basic block in Milkshape 3D. If you are not familiar with the interface then just follow directions and look at the pictures. Start by opening Milkshape 3D and selecting the Box tool.

image
Now go to your 3D View (if you do not have a 3D View just right click on any of the four viewports, roll over Projection and select 3D). Create a box that's four units wide and two units tall.
image

There you have it. Not hard, was it?

Step 2: Creating a skin

First open up Photoshop (or program of choice). Half-Life 2 will only read skins that are a multiple of 16.

16, 32, 64, 96, 128, 256, 512, 1024, 2048
Create a new file with a skin that is 128 x 128 (or whatever you want ? bigger skins for larger objects and smaller skins for smaller, more detailed objects). I won't be creating a detailed skin, just writing the words SKIN a couple times in the canvas. When finished it looks something like this:

image
Your skin does not need to look like this. It can be anything you want. Now we need to export it. Go to File > Save As. Save it as a .tga with the name ?skin? (or, once again, anything you want). A new panel (Targa Options) should pop up. Choose 32 bits/pixels and do not select Compress (RLE). Now you have an exported skin (Note: Any file type [for skins] can be imported into Milkshape 3D or any other modeling program you have. You can either use the .tga we just exported or a .jpeg, .gif, .bmp ? anything you'd like. I am merely setting up our skin so we can import it into VTFEdit).

Step 3: Skinning and rigging your model

Now it's time to skin the model. Go back to Milkshape and select your block (Ctrl+A selects all). Go to the Materials panel. You will see a few options, one of which says New. Select it. You now should have a new Material called Material01. You can rename this if you'd like but it is no essential. Select one of the tabs that says <none> (not the one to the right that says None, the one's with the < > symbols).

Browse and open up your skin file. Once open, while still in the Material panel, select Assign. You have applied your skin, but you cannot see it. Right click on the 3D view and select Textured. Your skin is now in place!

image
Now it's time to rig. Go to the Model tab and select Joint. Position the joint in the center (I do not know too much about rigging therefore keeping the joint [also known as a Bone] in the middle is something to avoid problems).

image
Now select both the joint and your model (Ctrl+A) and go to the Joints tab. You will see your joint called joint1. You can (if you'd like) rename your joint, however it is not necessary. With your joint and box still selected hit Assign. You've now assigned your joint to your box and are ready to export!

Step 4: Exporting, converting and running ingame

Now you are ready to get this bitch ingame. Select File > Export > Half-Life SMD. Name this ?box_reference? and export it as a Reference (without any Vertex Weights). Now, do the same thing, expect name this one ?box_idle? and select Sequence. You can now close Milkshape 3D as it is no longer necessary.

If you'd like (to make it easier to manage) you can place all of your model files into a folder. I will place mine in a folder called ?Box Model?.

image
You should have all the files you see in this picture (you may not have ?Tutorial.ms3d? which is my Box saved as a Milkshape 3D file. This is not necessary for actually compiling the model). Now we need to create the .qc file. Copy and paste the following into Notepad:

// Output .MDL
$modelname "custom/box.mdl"

// Directory of your textures (the .vtf and .vmt)
$cdmaterials "models/custom/"

$staticprop
$scale 1.0

// Your reference model
$body studio "box_reference.smd"

// Your animation sequence
$sequence idle "box_idle" loop fps 30

// In this case we are using a plain, square model, so we can just use the reference model
$collisionmodel "box_reference.smd"
Now save this as ?Box.qc? (or, once again, anything you'd like). Now it's time to compile.

Navigate to your Steam folder, and go to youremail@provider.com/sourcesdk/bin. Drag and drop Box.qc over studiomdl (NOTE: Due to a recent Steam update Cannonfodder's tools were broken. While this can be fixed and I could write the tutorial around using his tools I will not. It is good to know the most basic way to compile a model incase a future update breaks the custom tools once again). If you are not using a batch file then the box will speed by and you will not be able to read what the text says (which is bad incsae you have a model problem). The only way to make sure your model was compiled is to check the relative /models folder (in this case check models/custom/ for box.mdl). If you would like to use a batch file just use Google for information on creating one.

We're almost done. All we need to do now is convert the textures. Open up VTFEdit. Go to File > Import and select your .tga (NOTE: VTFEdit can actually import any file type - .bmp, .jpeg, .gif; etc. but I tend to import .tga's just to be safe). You will be hit with a variety of options, none of which matter. Just hit OK.

image
Don't bother with any of the options that you see before you right now, as this is just a tutorial on importing models. You can toy around with these later. Go to File > Save and save it as ?skin? (or whatever your skin name was that you applied to your model). Next, go to Tools > Create VMT. You'll notice that Base Texture 1 already has your .vtf selected, so click the Options tab. Deselect any boxes that may be checked (since we are using a simple skin) and go to the Shader drop down. From the list select VertexlitGeneric. You can now select a Surface if you'd like, it is not, however, required. Once ready hit Create and save it as skin too.

Go to the folder where you saved the two skin files. If you have not dealt with .vtf or .vmt

files then this may be confusing. The differences between the two are:
.vtf: Valve Texture File. This is the actual texture itself.
.vmt: Valve[/b] Material File. This is a file which we can edit (and will) in Notepad. This controls the properties of the .vtf (what's the surfac type? Where is the texture stored? Etc).
Open up the .vmt in Notepad, and you will see a parameter that says ?$basetexture? with a path. Change this to ?models/custom/skin? (or wherever your models textures are stored. NOTE: You do not put /materials in this. Never). Now, select both of these files and drag / drop them into materials/models/custom/.

Congratuslations: You have created, skinned and compiled a model. Now take the proper steps to import it into Half-Life 2 (this requires Hammer, usually [prop models], which I will not go into).

image
When you import the model into Hammer the bounding box may be a bit bigger than the model. You can fix this by exporting a third .smd (usually named collision but it does not matter) and determine it using $collisionmodel. Hope this tutorial was helpful.


Post ReplyView Topic
Discussion
0 starsPosted by Blargdaniel on Fri May 9th 2008 at 9:18am

You need to have &quot;$model=1&quot; in the VMT file after the location the the texture or else it will be invisible in game and an error saying that exact thing will be scrolling in the console. Oh, and that includes the &quot; mark.

But it was a good tutorial, I don't like this part &quot;Now you are ready to get this bitch ingame.&quot; It is just weird, well, yeah, weird.
0 starsPosted by Ark on Tue Oct 23rd 2007 at 11:30am

Looks like all the image files have disappeared for this tutorial.
0 starsPosted by david1994 on Thu Nov 9th 2006 at 11:35pm

0 starsPosted by Orpheus on Tue Apr 4th 2006 at 2:23am

Doesn't matter Vash. If this, or tuts like this promote it.. It served its purpose.
I envision a day where all maps will be models... Entirely prefabricated constructs.
[author]
Posted by Vash on Tue Apr 4th 2006 at 1:45am

Don't expect them from me. I can &quot;get around&quot; modelling a bit, but other than that I'm just using small hacks to somehow get my crap to work.
0 starsPosted by Orpheus on Tue Apr 4th 2006 at 1:44am

I am the trusting sort... More/Less.
We really do need these modeling tutorials.
Nice job Vash.
[author]
Posted by Vash on Tue Apr 4th 2006 at 12:51am

Removed pre tags, fixed images.
0 starsPosted by ReNo on Tue Apr 4th 2006 at 12:27am

You could easily fix that just by removing the preformatted text sections (or by entering line breaks in them manually to stop them being so wide).
[author]
Posted by Vash on Mon Apr 3rd 2006 at 11:34pm

G.Ballblue: The model format wasn't different. $basetexture is always necessary, no matter what texture type you are using (Lightmapped, Unlit, Vertexlit; etc). The difference between UnlitGeneric and VertexlitGeneric are:

VertexlitGeneric uses lights a model using Vertex lighting
UnlitGeneric makes the basetexture fullbright, and when used on a model must have the &quot;$model&quot; 1 setting in the vmt
0 starsPosted by Anthony on Mon Apr 3rd 2006 at 11:15pm

Good tutorial. I'm pretty sure most of this can be applied to 3dsmax, so I'll be checking it out soon. Glad there's a simple modelling tutorial out there.

Opera has Small Screen Rendering, which fixes it up nicely.
Post ReplyView Topic