Creating worldmodels from viewmodels
Creating a world model from an existing view model
This tutorial teaches you how to create a world model from a view model. It does not teach you how to do modelling or how to work with a model editor. Even though the screenshot shows 3ds max 7, the same can easily be done in all other model editors if you got sufficient knowledge of them.
Note: Even if this tutorial uses a view model for demonstration a world model should have a lot less polys and / or LOD models to ensure best performance ingame.
Setting up your model
If you'd just take your model and compile it like a physics object, the engine will not know where to put it onto the playermodel. The result can be somewhat hilarious but is most likely not what you are looking for.
To change this, load your view model (without hands) into your favorite model editor. It will be helpful (but is not necessary) to remove all bones that you needed for animating your view model, so you end up with one object/bone.
Now there are two ways to go. The first one is if you are doing a new model (not a replacement model) or if you don't have the model you want to replace decompiled:
Create a new bone with the name ValveBiped.Bip01_R_Hand. Place it so that it is in the position you want the right hand of the playermodel to be. Now link your model to the bone. (If you move ValveBiped.Bip01_R_Hand now, the weapon moves with it.)
In case you have a decompiled model you want to replace, move your new model into the position of the old one, delete the old one and link your model to the ValveBiped.Bip01_R_Hand bone.
Now you are ready to export your model. Compile it like any other physic prop (however without $staticprop because that would collapse your bones).
Just for reference I'll post my .qc here but it's rather random:
$modelname weapons/w_m4a1.mdl $cdmaterials models/weapons $scale 1 $keyvalues { "prop_data" { "base" "metal.medium" } } $model w_m4a1 "w_m4a1.smd" $sequence idle "w_m4a1" loop fps 15 $collisionmodel "w_m4a1.smd" { // Mass in kilograms $Mass 3.0 $concave }
Now start the model viewer, load a playermodel of your choice and your world model. Most likely your weapon will not be perfectly sitting in the hand, might range from some fingers going through the weapon to weapon pointing in a completely wrong direction.
Go back to your model editor. The actual position of the weapon or of the bone doesn't matter at all! Everything that counts is the relative position towards each other. In some cases you need to rotate. I'd advise not to rotate the weapon model but the bone. Either unlink it and link it later again or edit it without affecting children bones (for max you can find this setting in the hierarchy tab).
If you have aligned everything perfectly, your model will hopefully look like the Alyx model with the M4 of our example.
In case you want to add attachment-bones, like for a muzzle flash, add a bone with an according name (e.g. ValeBiped.muzzle flash) and link it to ValveBiped.Bip01_R_Hand.
Technical explenation of what we've just done
If you want to have a little bit extra knowledge that helps you to understand what we've just done, read on.
The engine merges the bone ValveBiped.Bip01_R_Hand of your playermodel with the a bone of the same name in your world model (in case it's the root bone). All bones that are a child of this bone will naturally move with it, that's why we have linked the weapon and the muzzle flash to it. The skeleton of the player model and of your world model have become one! When you have loaded both in the model viewer and you activate Bones in the render tab you can easily see it.
To make sure the you got this correctly, you can also look into your .smd file.
If everything is correct, it should start like this:
version 1 nodes 0 "ValveBiped.Bip01_R_Hand" -1 1 "m4a1" 0 end skeleton time 0 0 # # # # # # 1 # # # # # # end
As you can see, in nodes the ValveBiped.Bip01_R_Hand is defined as the root bone while the bone called m4a1 is a child of it. In the skeleton part the position of both are defined.