Left 4 Dead 2

Left 4 Dead 2

Not enough ratings
Compiling World Models
By Doktor haus
Learn to compile world models for weapons. All you need is a reference SMD, a basic QC and a batch compiler.

World models are any models which appear outside the player's first-person perspective. This term applies to map props, third-person survivor and infected models, but in the modding community, usually refers to weapons. To reduce confusion, I refer to physics-enabled weapons lying around in maps as "world models" and weapons seen in a third-person survivor's hands as "player models".
 
Rate  
Favorite
Favorited
Unfavorite
Reference SMD
By "reference" or "ref", I mean an SMD file containing your model/mesh, its skeleton and weights, but no animations. You need one before you can compile.

First, you need to decompile the default world model of the weapon you're replacing from pak01_dir.vpk. You'll see a few SMDs and a QC, but the only thing you need is the reference SMD. If it's not named "reference", "ref" or something similar, it's usually the largest of the decompiled files. Next, open your modelling program and import the ref (including its meshes, bones and rebuild smoothing groups if available), then import your replacement model's ref, but uncheck bones/animations.

Next, position the replacement model in the exact same area as the original. Now select the default ref, make note of how it's weighted and apply the same weights to your replacement. You can delete the original now and export the scene/project as a reference SMD.
QC
Here's an example QC.
$modelname "w_models\Weapons\w_rifle_m16a2.mdl" $body studio "ref.smd" $model studio "ref.smd" $lod 15 { replacemodel "ref" "lod1" } $lod 30 { replacemodel "ref" "lod2" } $lod 60 { replacemodel "ref" "lod3" } $lod 85 { replacemodel "ref" "lod4" } $lod 120 { replacemodel "ref" "lod5" } $shadowlod { replacemodel "ref" "lod6" } $cdmaterials "models\w_models\twinke_m16a2\" $cdmaterials "models\w_models\other_junk\" $hboxset "default" $attachment "muzzle_flash" "ValveBiped.flash" 0.00 0.30 1.70 rotate -90 0 0 $attachment "flashlight" "ValveBiped.flashlight" -1.20 2.77 -0.80 rotate -0 0 0 $attachment "shell" "ValveBiped.weapon_bone" -0.40 2.90 5.10 rotate -0 -180 90 $surfaceprop "weapon" $keyvalues { prop_data { "base" "Metal.Medium" } } $illumposition 0 0 0 $sequence idle "ref.smd" ACT_IDLE fps 30.00 $collisionmodel "ref.smd" { $concave $mass 10.0 $inertia 1.00 $damping 0.00 $rotdamping 0.00 }

Now let's break some things down.

$modelname - The name of the MDL you're compiling to and its path relative to the root models directory. Mine is "w_models\Weapons\w_rifle_m16a2.mdl", so it replaces the default rifle. If you're unsure of the names, navigate to steamapps\common\Left 4 Dead 2\left4dead2 and open pak01_dir.vpk using GCFScape. Expand models\w_models\Weapons to see all the default world models.

$model studio "ref.smd" - Your reference SMD. If your ref has attributes such as LOD or face flexes, use $model. If it doesn't, you should use: $body studio "ref.smd" You can have multiple $model or $body lines on different lines.

$lod - This assigns LOD (level of detail) replacements to your ref. Essentially, these are lower-detail versions of your ref which you see the further away you are from the model in-game. In my example, I have 6 different LOD refs appearing at a distance of 15, 30, 60, 85 and 120 units. For example, $lod 15 replacemodel "ref" "lod1" replaces ref.smd with lod1.smd at a distance of 15 units. LODs are nice to have and increase performance, so use em if you got em. If all you have is 1 ref SMD though, just leave out this section altogether.

$cdmaterials - The path to your model's materials folder. This is where so many new modders get stuck because they forget or misuse this section. All you have to do is enter the path, relative to the materials folder, to the VMT and VTF files your model uses. If my materials are in materials\models\haus, then it should be $cdmaterials "models\haus\". Make sure you pack these materials into your addon's VPK! If you're viewing your model in HLMV (Half-Life Model Viewer), you'll need to copy the materials to your root left4dead2 materials folder. You can have multiple $cdmaterials on different lines.

$hboxset - Specifies the hitboxes for your model. Unless you know what you're doing, leave this as default.

$attachment "muzzle_flash" "ValveBiped.flash" 0.00 0.30 1.70 rotate -90 0 0 - Creates an invisible point on your player model, mainly for the purpose of attaching sprites and particle effects. muzzle_flash is for muzzle flashes, flashlight for the flashlight beam and shell for ejecting empty shells/brass. This example attaches muzzle flash to the "ValveBiped.flash" bone. The 1st 3 numbers are position and the next 3 rotation. You can always attach these to your weapon's frame/receiver, just remember to tweak the position and rotation to make it look right. BTW, if you already have shell ejection on your view model, I recommend leaving it off the world because two sets of shells will generate for each shot fired!

$surfaceprop - Defines what sounds your model makes when it hits the ground, gets knocked around, shot etc. See this.

$keyvalues - You can do some nifty things with this, but I mainly use it for surfaceproperties too. See this.

$illumposition - Sets the illumination position of the model relative to its origin. Most of the time, you can leave this out. The only time you really want to change it is if your weapon turns dark under in-game lighting. See this.

$sequence idle "ref.smd" ACT_IDLE fps 30.00 - Even though weapon world models don't have their own animations, you need this to compile them. ALWAYS re-use your reference SMD (not idle.smd or LODs) for the idle sequence. This gave me a lot of headaches because once I got the world model rotation correct, the player rotation was incorrect, and vice versa. That's why you re-use the ref.

$collisionmodel - I included this block in the example QC for completeness, but it's not important and is fine to leave out entirely. This generates a .PHY file for your model and, well... DON'T include .PHY files in your mods unless you really know what you're doing. Physics simulation is very demanding, so unless you've made a proper collision model (low-poly and simple as possible), just leave them out. The default ones work fine. I suspect custom .PHY files are often the cause of crashes.
Compiling
The easy way
The simplest way to compile models is with Crowbar, a tool made by my good friend Zeq. You can drop a QC file onto the program window, hit compile and that's basically it.

The manual way
But for completeness' sake, I'll still include the old method: using a Batch file. Making one is easy. Create a new text document and paste this inside:
"C:\Program Files (x86)\Steam\steamapps\common\left 4 dead 2\bin\studiomdl.exe" -game "C:\Program Files (x86)\Steam\steamapps\common\left 4 dead 2\left4dead2\" -nop4 YourQCGoesHere.qc pause
Be sure to change "YourQCGoesHere.qc" to the name of your QC file. If you have a 32-bit system, remove the (x86) and if you have L4D2 installed to a different hard drive, change the paths accordingly.
With Notepad open, select File > Save As, change the file extension to all files, then add ".bat" at the end of the file name and save it. Place a copy of the newly-created .bat file in the folder which contains your QC and reference SMD.

Now open Steam, hover over LIBRARY, then select TOOLS. Find "Left 4 Dead 2 Authoring Tools" and double-click to install it. Once it's finished, double-click it again to run, then run Model Viewer. You can exit both now.

Now you should be able to double-click the .bat file and compile your model. If everything goes right, you'll see "YourQCGoesHere.qc completed" and can press any key to close the CMD window. You'll find your compiled models in your root left4dead2/models folder.
Positioning
Getting started

So, your gun is clipping through NIck's hands and the muzzle flash emits from Rochelle's mouth? No worries.

Copy the materials and models folders from your addon VPK to the root left4dead2 folder. Open HLMV and load up your weapon. (Remember to create the folder structure if HLMV complains that it doesn't exist.) But, wait... It always loads the default model. I don't know why, but here's an easy fix: Recompile it under a new name (That is, one not already used by the default models) and open that.

Repositioning the reference
How about that misplaced weapon model?
First, you'll want to load a default survivor model. Click "load model", navigate to models\survivors and select one. Next, choose "load weapon" and select your replacement model. Next, hit the "sequence" tab and select an animation from the 1st dropdown menu below. Remember that there are different third-person "hold types" for different weapons; what looks great in the rifle post may look completely wrong in the pistol pose, so make sure you choose one which matches what you're replacing. If you're unsure, open pak01_dir.vpk again, expand "scripts" and extract the appropriate weapon_something.txt file. Open that and look for "PlayerAnimationExtension". If that's not helping, look for "ResponseRulesName". Mine had "rifle", so I know to use the rifle animations. Idle_Standing_Rifle, Idle_Calm_Rifle, Idle_Crouching_Rifle etc. You should see a survivor holding your replacement weapon.

Now you have observe how your model looks in the survivor's hands, reposition it in your modelling software, then re-do the weights/skinning, export the ref SMD, recompile it, then go back to HLMV and hit F5 to reload. It's a tedious process, but it works.

Repositioning attachments
How about that misplaced muzzle flash, flashlight or spent brass attachment?
Go to the attachments tab and select the attachment you want from the bottom left list. You should see red, blue and green lines somewhere on your model - that's the attachment point. Now all you have to is tweak the Translation and Rotation numbers until your attachment point lines up where you want it. Position is easy enough, but how do you know what the rotation should look like? Just open the default model you're replacing, take note of how its colors are rotated, then match that rotation on your replacement. If you modify the reference after this point, you'll have to adjust the attachments to match the changes. :P

Finishing up
Once you're satisfied with your reference and attachment positions, remember to change the $modelname in your QC back to the MDL you're replacing, then compile.

Also, DELETE ALL .PHY FILES from your mod. :P
< >
11 Comments
The VikinG Oct 21 @ 4:49am 
So what is the actual process of "make note of how it's weighted and apply the same weights to your replacement" does it involve the vertex groups too? 1 vertex group (ex: trigger) for 1 bone+weight?
ZeqMacaw Oct 8 @ 11:30am 
Ha! Just noticed Dok added mention of Crowbar.
¤ ҉Richard҉ ¤ Jul 3, 2016 @ 3:17am 
Nice guide. Helped me understand a few things I wasn't sure about.
ZeqMacaw May 5, 2016 @ 1:34pm 
+1,000,000 for being good friend. :D
ZeqMacaw Aug 26, 2015 @ 6:28am 
-1 No mention of Crowbar. :P
FB||NoT||Gamer man casejar.com Jul 12, 2015 @ 6:51pm 
thanks haus but to bad i got steam way 2 late 2 add u
(ѦØѦ)titanplatine Nov 28, 2014 @ 3:26pm 
awsome guide thx for your time do the same aplies to survivors ? thanks again for this guide have a nice day :)
love me>3 Nov 22, 2014 @ 4:28am 
first!
Rex The Impaler Nov 21, 2014 @ 8:55pm 
I would love to see how to make v_models since every v_model I compile turns into some nightmare fuel with stretched out arms
MUTANT BLOODLORD Nov 19, 2014 @ 11:38am 
2/10 "Its okay" -IGN