under construction

This tutorial was originally written by Dan Krueger. I did not in any way write this tutorial. Edits were made to be compatible with the wiki, but the original content stands. I apologize for breaking the internal links, but for some reason they don’t work in the wiki.


Crrrazydan’s MDL Tutorial - Making MDL models for use with TrueVision using Milkshape 3D
Written 01/10/03 by Dan Krueger

1) Exporting the mesh
2) Exporting the animations
3) Making the QC file
4) Compiling the model
5) Opening a compiled MDL
6) Hitboxes
7) Bodyparts
8) Controllers & Bone Rotations

A lot of TrueVision 3D Engine users seem to ask about how to make an MDL model, so here is the hmm... “official” tutorial. This tutorial will not tell you how to model, that is a completely different aspect that can be applied to any model format. This tutorial will however tell you how to correctly compile an MDL, and show you how to do a couple advanced things that I know are hard to find resources on.

MilkShape 3d Modeling software to the casual observer appears to not be able to export MDL’s. That is because MDL’s are made up of many different files which are compiled together. Actually one of the reasons Milkshape was created for was Half-Life MDL editing, so obviously it should let you make your own MDL.

1) Exporting the mesh An MDL can be made up of more than one mesh file, known as bodyparts, but for right now we will just work with a single mesh that makes up the entire character. Both mesh and animation files will be exported as SMD files. So when you have your character fully constructed and coupled with a skeleton, you can export it. Note that if even a single vertex is not assigned to a bone, you will not be allowed to export. Also, all textures must use a 256 color palette or you will later find the compiler will complain. Upon exporting, it is a good idea to name the mesh SMD file something that will later be easy to differentiate from all the animation SMD’s. For example, name the mesh SMD file “character1-MESH.smd” instead of just “character1.smd”. When you click OK on the Save As dialog box, another box will pop up asking whether you want to export as Reference or Sequence. Click Reference, because the reference SMD is the mesh file, and any sequence SMD’s are the animations.

2) Exporting the animations You can have as many animations as you would like, and each will be exported as a separate SMD file. You may notice in some of the professional Half-Life models, there are over 100 animations! One thing you must keep in mind throughout the animating process with MDL’s- never move the skeleton when out of animation mode! Otherwise you will wind up with a wildly contorted model. To export an animation, do it the same way you would for the mesh. Export it as an SMD, only this time be sure to click Sequence instead of Reference after the save dialog.

3) Making the QC file The QC is simply a special text file readable in Notepad that tells the MDL compiler how to compile your model. Every QC file will have most of the same elements, but every model’s file will be different most likely. For a template QC file, you can click “Tools > Half-Life > Generate QC File” in MilkShape, or copy the following one.

// Output .MDL file path and filename
$modelname "C:\Your Game\mdl model temp\Character1.mdl"

// Directory of .SMD files
$cd "\Your Game\mdl model temp\"

// Directory of .BMP textures
$cdtexture "\Your Game\mdl model temp\"

// Model's master scale value
$scale 1.0

// Mesh SMD Bodygroups: use path from $cd
$bodygroup body
studio "character1-MESH"

// Sequence SMD's: all sequences are in $cd
$sequence InGameAnimationName1 "SMDfilename1" fps 30
$sequence InGameAnimationName2 "SMDfilename2" fps 30
$sequence InGameAnimationName3 "SMDfilename3" fps 30
// etc...
// Double last sequence line!
$sequence InGameAnimationName3 "SMDfilename3" fps 30

There you have it, a simple skeleton for a QC file. Save it just like you would a txt with Windows Notepad, but instead of .txt at the end, make it .qc -Some things to note: The Mesh SMD bodygroups stuff is for multiple meshes, but for right now you are just using a single Reference SMD file, so just fill in “character1-MESH” (no .smd at the end!) with your SMD filename. InGameAnimationName1 is the name TrueVision or any model viewers will diplay for the name of the animation. The SMDfilename1 is the filename that the actual SMD sequence is stored in (with no .smd at the end). I don’t know if TrueVision still has the following bug or not- the last animation wont work unless you double the last $sequence line. You may as well put it in there anyways, it wont hurt anything.

4) Compiling the model To compile the model, you can use the Milkshape built-in compiler, or you can use the DOS utility studiomdl.exe that comes with the Half-Life SDK. For basic models Milkshape should work fine, but for advanced things like hitbox coordinate dumping, you will need studiomdl.exe (downloadable here - 112kb) To compile in Milkshape, click “Tools > Half-Life > Compile QC file”. The compiler will then grab everything according to how you specified it in your QC file, and spit out a nice new shiny MDL. If you are compiling with studiomdl.exe, the easiest way to do it is to drag your QC file directly onto the studiomdl icon in windows explorer, and it will do its stuff. Remember, MDL’s can only use 256 color textures, so you will have problems when trying to compile with 16, 24, or 32 bit textures.

5) Opening a compiled MDL With an MDL you made, you can just import the individual SMD files into Milkshape. But if you want to import an MDL from an outside source, you will have to decompile it. That is easy, just click “Tools > Half-Life > Decompile Normal HL MDL File” in MilkShape. It will then spit out all the SMD’s and BMP’s and even the QC file contained in the MDL, so you can then import each file individually.

Thats about all you need to know for basic MDL making, read on for details on more advanced features.

6) Hitboxes If you want body-area specific collision detection for your character, primarily for use with seeing if the character has been “shot”, you will need hitboxes for accurate health depletion. Fortunately studiomdl.exe (downloadable here - 112kb) will automatically detect hitbox areas for each group in your model. The easiest way to do this is to have studiomdl write all hitbox coordinates out to a text file. The way you do that is in DOS, so open up the DOS prompt, and set the current directory to where studiomdl lies. You can do that by typing cd\”My Game\mdl model temp” Then you will type this studiomdl.exe -h character1.qc >hitboxes.txt and then all the $hbox lines you need are in hotboxes.txt. Just copy and paste into your qc file. If you want different hitbox groups, make sure to change the first integer after $hbox, that is the hotbox index. So have 0 for the head, 1 for the chest, and 2 for all the limbs for example. That way if the bullet hitbox collision in TrueVision returns a 1, you will know the character was shot in the chest, and you can deplete their health accordingly.

If you compile your model with MilkShape, then uncompile it with MilkShape, it will also write out the hitbox coordinates. That may be a better route for you if you don’t like using DOS (even though I told you everything to type :)

7) Bodyparts You can have interchangable meshes in incorporated into your MDL, called bodyparts. A good example of this is the Half-Life scientist model, it has interchangable heads, and a syringe. In Snowboard Assassins, the weapons are in the character’s MDL file, listed as interchangable bodyparts, so we will use that model for an example. To properly export a sub-mesh of the main mesh, take only its skeleton and attach the weapon or head or whatever to the appropriate spot on the blank skeleton. Export the mesh as a Reference file. Then you need to update the QC file with your bodyparts. For multiple weapons, or heads, etc. that will replace each other, your QC will look like this: // Mesh SMD Bodygroups: use path from $cd $bodygroup body { studio “character1-MESH” }

$bodygroup weapons { studio “pistol-MESH” studio “uzi-MESH” blank } The pistol and uzi bodyparts are the mesh files, and the “blank” simply means nothing will be there. So in TrueVision you can switch between the pistol, the uzi, and no weapon using Actor1.SetModelInBodyPart

8) Controllers & Bone Rotations Controllers are only needed if you are using Actor1, and the only reason you would need to use Actor1 is if you are using Bodyparts. A controller used to be the only way to programmically rotate a bone in-game. Now Actor2 has SetBoneRotation. Anyways, to enable a controller on a joint, add this to your QC file. $controller 0 “LeftArm” XR 0 540 That will allow you to call “Actor.SetProgrammicController 0, angle” in game. The “XR 0 540” means the controller will rotate on the X axis, with a range of 0 to 540 degrees. Since 0° = 360°, I start the controller off at 360, allowing it to go backwards.

For Actor2’s: If you are wondering which bone integer corresponds to the one you want to rotate, open any sequence SMD in Notepad, and you can easily see the bone indexes next to the bone names.

Well that about does it for MDL’s and TrueVision. I learned a few things while writing this actually- I even had to go back and change stuff with my newly aquired knowledge. So who knows, you might find a mistake in here. If so you can always tell me and I will update this. Not bad for someone who’s never even played Half-Life :) Until then, enjoy your MDL model!


tutorialsarticlesandexamples/export_mdl_characters_from_milkshape_for_use_in_tv3d.txt · Last modified: 2013/11/22 13:32