Cleanup is going to take awhile, so the site is back up but editing has been disabled.
Creating Characters with 3dstudiomax part 1
From HalfLife 2 Knowledge Base
Writen by Sean Mcbride (n30g3n3s1s).
Contents |
Introduction
An informal How-to on importing your character into halflife2 using a custom rig. If you need to import a character into hl2, hl2:dm, or CS:S open the character models in hlmv using the SourceSDK and write down the animation names. I'll be writing more tutorials on the specifics of animations and other things but this is how to get your character in-game and ragdolls working. Also, once I figure out importing the xsi rig into max so you can use the packaged animations i'll be writing a tutorial for that.
This is a very advanced Source tutorial so please read and understand the static models tutorial and the ragdoll tutorial before moving on to this one. I wont be explaining animation, rigging, or skin weighting techniques in this tutorial because those can be found other places. Also, I'm looking at the SDK character files found in sourcesdk_content\cstrike\modelsrc.
Also, make sure you are using cannonfodders newest version of the SMD exporter for max, the old ones only export skin weights of 1 and 0. http://www.chaosincarnate.net/cannonfodder/cftools.htm
Please download the character referance. Your character scale must be correct before you start the tutorial. You must be logged in to download the zip file. If someone wants to mirror the file it would be much appreciated. http://www.hl2world.com/bbs/here-vp382362.html#382362
Setting up your character
My character
Just an example. This is somewhat yours should look like.
1) Apply Material id's, in edit poly or edit mesh modes, to the sections of the model you want to have a specific texture. (You MUST do this even with 1 texture).
2) Make a multi/sub-object material in the material editor and apply it to your object. (You MUST do this even with 1 texture).
3) Set the number of textures you have in the multi-sub object and apply it to your model.
4) Load the textures in TGA format into your multi/sub-object in TGA from anywhere.
5) Import the given 3ds file. Its the CS:S Urban model so you can size your character to the right scale for halflife2. (http://www.hl2world.com/bbs/here-vp382362.html#382362)
6) Setup your rig. I used character studio's rig because it was easy and quick. It works perfectly in halflife2. also its so similar to the rig valve used that the naming isn't hard to setup. I renamed all my bones to be short names like r_foot and l_thigh. Here's where working with a custom rig gets tricky... if you want weapons from halflife2 and counterstrike source to work with the character you MUST name the hand bones the same! In the weapon models they are rigged to ValveBiped.Bip01_R_Hand. For akimbo weapon models like the dual elites from CS:S the second model is rigged to ValveBiped.Bip01_L_Hand.
7) Apply skin weighting. Since this isn't a modeling/animation tutorial i'm not going to go into that. Just look up tutorials on physique or skin. Make sure you have all your weighting done before you continue.
8) Since your character is still in its base "reference" pose go ahead and export if your done with your rigging. File->Export and select Valve SMD. Export to somewhere in modelsrc\players\*charactername* and save as a reference. We'll come back here later to write our qc files.
9) Now that we have our character exported as a reference its time to do some base animations. As of now this will be just his ragdoll pose. Save your weighted reference max file. Since each animation has to be a different SMD file we need to create copies of the max file and for the sake of simplicity lets name them the same as our exported SMDs. Choose save as and name this next file "*charactername*_ragdoll". Click the "time configuration" button and set the end frame to frame 1 so we have a single frame animation. File->Export and select Valve SMD. Name the file "*charactername*_ragdoll" and save it where you saved your reference SMD. This time leave skeletal animation selected so it'll export the bone and frame information.
Thats what i'm going to cover for the time being. There are tons and tons of animations to cover but just load them up and copy down the animation names and recreate them. I'll write another tutorial later on for using the rig that comes with hl2 to use the packaged animations.
Creating the collision model
My collision model
On top of the character model for referance in size.
1) Open your reference pose max file again and choose save as again. This time save it as "*charactername*_collis" or whatever you like, thats just the name I use.
2) Select your model and hit alt-X to turn on transparent mode. Now we are going to create the model that the physics engine uses as the collision model. Basicly its an extreamly simplified version of your model. I used modified cylinders and boxes. Look at the picture below as a reference. Its ok to overlap some of the boxes and its also ok to have small gaps inbetween them. I have gaps between the elbows, wrists, knees, and ankles for easy rigging. Basicly what your doing is created phys boxes to represent the bones that will be ragdolled. Not all of the bones will be set to ragdoll mode because the game can't handle that much physics processing. So usualy you have 2 spine boxes (one for the pelvis/lower back and one for upper chest/shoulders), 3 boxes for the arms/legs, one for the head, and finaly one for any other large object on the model for example the big backpack that my character has.
3) Take all the boxes and make them one model using the attach tool. Then using the polygon selection select all of the faces and set them to smoothing group 1. Also, with all the faces selected still set all of them to material ID 1. Now drop your material that you used for your character onto the collision model.
4) (Try johnny's note below, use this step if that dosn't work) If your done with your collision model apply skin or physique to it and weight the verts as an absolute 1.0 to each bone that they are going to represent. They can't be weighted to blend between bones or they wont compile correctly. So basicly just go through and weight them to the bone that they represent.
-- Helpful Tip from Johnny Blaze --
Im not sure the Wiki etiquette here and hope I'm not stepping on any toes adding to this, but I found something rather helpful and time saving when it comes to collision models. After reading Valve's spotty documentation and experimenting while fixing a ragdoll problem, I found that your collision model doesn't need to be one skinned object; it just needs to be in the hierarchy. I left all my boxes seperate (with smoothing group and material 1 on all meshes) and just linked them to their respective bones and it worked great, no weighting or per-vertex BS required! This was with Max 7, biped and CannonFodder's exporter. Your mileage may vary.
- Thanks Johnny! I didn't relize that. Great Tip/Time saver. :)
5) So you saved this as the "*charactername*_collis" right? ;) Delete your character but leave the bones/collision model there. Now export the smd and name it the same as the max file. Be sure to export as a reference.
Writing your QC files
The Physics tab of hlmv
Where you'll be doing most of your tweeking.
This part is pretty complex and it really helps if you have a coding background. If you have problems, refer to the qc files that come with the sample SDK content.
1) Go to the directory where you saved your SMD files. Create a txt file and rename it to *charactername*.qc. Here's a sample of what mine looks like:
// Output .MDL $modelname "player/govLeader/govLeader.mdl" // Directory of .TGA $cdmaterials "models/player/govLeader" $model "govLeader" "govLeader_ref.smd" $include "hierarchy.qc" $include "ragdoll.qc" $surfaceprop "flesh" $sequence default "govLeader_ragdoll" fps 1
This is the very basic player qc file. No animations or anything, just a static pose. Later on if you want to do animations they are done like the ones in sourcesdk_content\cstrike\modelsrc\animation\cs_player_shared.qc.
2) Next is our hierarchy.qc. Put it in the same directory as your other QCs. I did this because i was having problems with my spine1 bone not having a parent for some odd reason. So you just tell the engine that its parent is the pelvis.
$heirarchy "Pelvis" "" $heirarchy "Spine1" "Pelvis" $root "Pelvis" $heirarchy "L_Clavicle" "Spine3" $heirarchy "R_Clavicle" "Spine3" $heirarchy "L_Thigh" "Pelvis" $heirarchy "R_Thigh" "Pelvis"
3) Finaly is the huge complex ragdoll.qc. Again, put it with the rest of your qcs. Its the most complex one of this tutorial and what the focus was really. Here's mine, yours will be different depending on the bone names. I'll go over how to generate your own below my example.
//govLeader_collis is the smd.
$collisionjoints govLeader_collis {
$mass 81.0
$inertia 10.00
$damping 1.00
$rotdamping 2.50
$rootbone "pelvis"
//these are the bone names that exported from your model in max.
$jointmerge "pelvis" "spine1"
$jointconstrain "r_thigh" x limit -10.00 10.00 0.00
$jointconstrain "r_thigh" y limit -35.00 15.00 0.00
$jointconstrain "r_thigh" z limit -60.00 85.00 0.00
$jointconstrain "r_calf" x limit -15.00 15.00 0.00
$jointconstrain "r_calf" y limit 0.00 0.00 0.00
$jointconstrain "r_calf" z limit -102.00 0.00 0.00
$jointconstrain "l_thigh" x limit 0.00 0.00 0.00
$jointconstrain "l_thigh" y limit -17.00 35.00 0.00
$jointconstrain "l_thigh" z limit -60.00 85.00 0.00
$jointconstrain "l_calf" x limit -15.00 15.00 0.00
$jointconstrain "l_calf" y limit 0.00 0.00 0.00
$jointconstrain "l_calf" z limit -102.00 0.00 0.00
$jointconstrain "l_foot" x limit 0.00 0.00 0.00
$jointconstrain "l_foot" y limit -3.00 3.00 0.00
$jointconstrain "l_foot" z limit -35.00 17.00 0.00
$jointconstrain "spine1" x limit 0.00 0.00 0.00
$jointconstrain "spine1" y limit 0.00 0.00 0.00
$jointconstrain "spine1" z limit -20.00 30.00 0.00
$jointconstrain "spine3" x limit 0.00 0.00 0.00
$jointconstrain "spine3" y limit 0.00 0.00 0.00
$jointconstrain "spine3" z limit -20.00 30.00 0.00
$jointconstrain "r_upperarm" x limit -80.00 80.00 0.00
$jointconstrain "r_upperarm" y limit -25.00 135.00 0.00
$jointconstrain "r_upperarm" z limit -80.00 60.00 0.00
$jointconstrain "r_forearm" x limit 0.00 0.00 0.00
$jointconstrain "r_forearm" y limit 0.00 0.00 0.00
$jointconstrain "r_forearm" z limit -120.00 0.00 0.00
$jointconstrain "l_upperarm" x limit -80.00 80.00 0.00
$jointconstrain "l_upperarm" y limit -135.00 24.00 0.00
$jointconstrain "l_upperarm" z limit 0.00 0.00 0.00
$jointconstrain "l_forearm" x limit 0.00 0.00 0.00
$jointconstrain "l_forearm" y limit 0.00 0.00 0.00
$jointconstrain "l_forearm" z limit -120.00 0.00 0.00
$jointconstrain "l_hand" x limit -90.00 90.00 0.00
$jointconstrain "l_hand" y limit -25.00 25.00 0.00
$jointconstrain "l_hand" z limit -90.00 90.00 0.00
$jointconstrain "head" x limit -48.00 48.00 0.00
$jointconstrain "head" y limit -41.00 41.00 0.00
$jointconstrain "head" z limit -30.00 30.00 0.00
$jointconstrain "r_hand" x limit -90.00 90.00 0.00
$jointconstrain "r_hand" y limit -25.00 25.00 0.00
$jointconstrain "r_hand" z limit -90.00 90.00 0.00
$jointconstrain "r_foot" x limit 0.00 0.00 0.00
$jointconstrain "r_foot" y limit -3.00 3.00 0.00
$jointconstrain "r_foot" z limit -35.00 17.00 0.00
}
$sequence ragdoll "govLeader_ragdoll" FPS 1 activity ACT_DIERAGDOLL 1
// ragdoll is the name of the sequence the game uses. govLeader_ragdoll is the smd file.
This example is missing the mass settings but for my models I usualy take the masses from the CS character (found in sourcesdk_content\cstrike\modelsrc\urban.ragdoll) and tweek them to my liking.
To create generate a ragdoll file of our own create a ragdoll.qc like this:
$collisionjoints *charactername*_collis {
$mass 81.0
$inertia 10.00
$damping 1.00
$rotdamping 2.50
$rootbone "pelvis"
}
$sequence ragdoll "*charactername*_ragdoll" FPS 1 activity ACT_DIERAGDOLL 1
This will allow the model to be compile. Once compiled open the model in hlmv and go to the physics tab. You should have a listing of all the bones that you asigned
to your collision model.
4) After doing that if you compiled the model would show up in game, but you would have rigid model. All the joint constraints are set to no movement. So, go back into hlmv, go to the physics tab again. Check the "Highlight" box and flip through the list of bones you have. It will show you the collision boxes you created and what bone they are applied to. Move the "test" slider to the right and then move the max slider around. This sets the maximum movement on the axis that is selected. After you set the max angle for that joint slide the "test" slider back to the left and play with the min setting. You have to do this for each joint and axis you want to move. Otherwise they will be locked. Also, you have mass bias, inertia, damping, and rotation damping to play with. All of these settings are remembered by hlmv untill you close it. Get everything set the way you like it, click "Generate QC" go to your ragdoll.qc file and hit ctrl-V. Be sure you do this before you close, or it will loose all of its settings! now, go to the first line that was generated. it should be:
$collisionjoints ragdoll {
change that to
$collisionjoints "*charactername*_collis" {
then go to the bottom of the file and find
$sequence ragdoll "ragdoll_pose" FPS 30 activity ACT_DIERAGDOLL 1
change that to
$sequence ragdoll "*charactername*_ragdoll" FPS 1 activity ACT_DIERAGDOLL 1
Now, save your ragdoll.qc and recompile. you don't have to close hlmv.
5) At this point it should compile fine. Go to file->refresh in hlmv and it will update the model. Check your physics tab and see if it kept all of your settings.
If it did then you're good to go!
The final result in hlmv
Conclusion
This was just a step in the right direction really. There is so much information to go through that its really impossible to walk someone through all of the steps of getting a character in halflife2. I'll be writing more tutorials on how to get animations and other things in-game soon. My suggestion is just play around! it is after all how I figured all of this stuff out.
If there are any major problems, you have questions, or an ideas. Write me an email!
- Sean McBride n30g3n3s1s@comcast.net

