Cleanup is going to take awhile, so the site is back up but editing has been disabled.

Max To HL2 Animated

From HalfLife 2 Knowledge Base

Jump to: navigation, search

This tutorial will show you how to export a model from 3dsMax to Half-Life 2 without any hassle, AND also how to set-up the animations. I spent the past few days hacking away at how to do this. And finally got it to work, so I thought I would share my knowledge.

I assume you have set-up a VPROJECT envrionment variable to the cstrike_sample_content directory in you SourceSDK folder, all my links and paths will refer to this directory. To set up VPROJECT just right click on My Computer and hit properties. Then go to Advanced and hit Environment Variables button in system variables click New Variable Name = VPROJECT, then set Variable value to C:\Steam\SteamApps\account@account.com\sourcesdk\cstrike_sample_content ensuring you replace account@account.com with your account name, and obviously correct address.

For this to work you need 3dsMax 6 or 7, I tried using Max6 with the exporter but it threw up an error, not sure whether this is me or not. It works perfectly fine in Max 7. First things first is to set-up and example folder to place all your exported files into, this just makes life easier. On the desktop make a folder called anything. I called mine Cylinder (duh! because I'll be making a cylinder). Now download the plugin here (Really it's a Maxscript) http://games.nad.qc.ca/smd_export.zip a All credit goes to PerPixel for this exporter, I thank him for it. For now extract the plugin. I suggest just placing it on your desktop because when you have lots of animations or whatever and you want to export them, then you need to find it and open it, so quickest place to navigate to is the desktop. So now you should have smd_export.ms on your desktop.

Also when working save your model you are working on in 3ds Max, try not to turn Max off just to keep work flow. But save it.

Let's make a sample texture so we can prove that it's working. Later on you can make a proper texture. For now just make yourself a little 512x512 texture in photoshop or wherever, you must make sure that it's in .tga format. Name it whatever you want, test.tga will be fine. *Make sure its .tga* I suggets placing this .tga file in the folder you created on your desktop.

Now fire open 3ds Max. I think I'm right in saying that 1 unti is max, is equal to 1 unit in HL2, which is an inch, so your ideally aiming to produce character models which are 72 units tall in Max.

Lets go make a cylinder, in top view drag out the cylinder. Now go in and input the values, lets make this 8 foot high, so in height put 96, and in radius put something like 6. Lets give this model some more height segments for animation later so it's nice and smooth. In Height segments put say 12. and number of sides doesn't really matter. Now right click on the cylinder and Convert To: Editable mesh (You MUST always work with Editable mesh, nothing else works)

Image:Max2HLImage1.jpg

Now go into Polygon sub-object mode, select ALL faces (just hit Ctrl+A) then in the right toolbar go down to surface properties and In Material put SetId to 1. Also I'm not sure if the smoothing groups matter with this plugin, but hit the Clear all button, and then press the number 1 button.

Image:Max2HLImage2.jpg

Now press M or your keyboard (or just go to Material Editor), in slot 1, press the standard button and change to Multi/Sub-Object, hit kepp old material (This doesn't matter) Then hit Set Number and change to 1. Then click on 01 - Default.

Image:Max2HLImage3.jpg

Next to diffuse hit the button and choose Bitmap in the window that pop-up. Then go to the .tga file you created earlier and select that. Now in material editor go to the root of the material slot, by hitting the drop down box just below the row of horizontal buttons, And select the top Default - 01 option. Now click on the sphere in slot 1 in the mateiral editor and drag it onto the cylinder. Now the texture is applied to the cylinder. And we're ready for a test export. In the right toolbar go to Utilities, and hit the MaxScript button then hit Run Button and mavigate to the smd_export.ms file that you should have extracted to your desktop. And a window will pop-up with export options.

Image:Max2HLImage4.jpg

Just hit OK. And export to the cylinder folder on your desktop, call the file cylinder and hit save. Now we can test this. First things first is log into your steam account otherwise we can't compile or anything. Go to the folder

C:\Steam\SteamApps\account@account.com\sourcesdk\cstrike_sample_content\

In model_sources make a new folder called cylinder copy the exported file cylinder.smd into this directory. And in materialsrc make a folder called models, in there make another called cylinder and copy the texture you made, test.tga or whatever into this directory. Now go back to cstrike_sample_content and in models folder make a new folder called cylinder, and in materials folder make a new folder called models and in there make another folder called cylinder. Now go to the folderm materialsrc/models/cylinder folder, and in a new window goto the directory

C:\Steam\SteamApps\account@account.com\sourcesdk\bin\

and now drag the texture you made onto vtex.exe and wait, then hit a key when it has finished. Go to the materials/models/cylinder folder and make a new file called cylinder.vmt (Name it the same as what your .vtf has come out as. In there include these lines of text.

"VertexLitGeneric" { "$basetexture" "models/cylinder/cylinder" }

Save it. Now goto the folder, cstrike_sample_content\model_sources\cylinder\ and make a new file called cylinder.qc and put these lines of text

$modelname cylinder/cylinder.mdl $cdmaterials models/cylinder/ $scale 1 $body studio "cylinder.smd" $sequence idle "cylinder" loop fps 30

This will compile a model in cylinder.mdl in the folder cstrike_sample_content\models\cylinder. It will find the material for it in cstrike_sample_content\materials\models\cylinder. Kepp the exported scale the same, you could increment the size of the model in here retahter than going back to the modelling program and manually increasing the size. It will use as it's base model cylinder.smd, and use an idle animation from the same .smd file. I'm not sure why but you MUST have the sequence line. Even if you're model has no animations.

Ok so now we need to compile this model, open up a command prompt and type in

%sourcesdk%\bin\studiomdl %sourcesdk%\cstrike_sample_content\model_sources\cylinder\cylinder.qc

This will go through the compile, and will run seamlessly if you have ensured to set up VProject properly and to use the directory stucture correctly as I have suggested.

Now lets view our masterpiece. Goto

C:\Steam\SteamApps\account@account.com\sourcesdk\bin\

And double click hlmv.exe then goto File -> Load Model.. and goto the cylinder folder and open cylinder.mdl and it will load. If not check that you have exported the .smd file correclty, open it up in notepad and see if there is any triangle information, if there isn't check your model is an editable mesh. Other than that I can't think of anything to make you not view your model. If you can't view your texture ensure you have it in the correct directory. You materials MUST be in this directory

C:\Steam\SteamApps\account@account.com\sourcesdk\cstrike_sample_content\materials\models\cylinder\

Ensuring you have cylinder.vmt and cylinder.vtf in there. If not go back and sort it. Else everything should load perfectly. So we can now move onto animation.

Go back to 3ds Max, and on the right-hand toolbar make sure you have Create selected, then go into Systems, and click on bones.

Image:Max2HLImage5.jpg

Now draw out your bones make sure the width and height is both set to 10 so we can automatically assign the weighting without do it by hand, in Front view, draw out 4 bones, and right click to end the bone creation, a 5th bone is created, this is the end effector (I think) you MUST NOT delete this bone, otherwise you will always be one bone short in your skeleton.

Image:Max2HLImage6.jpg

Now select the cylinder model and go into the Modify tabe on the right-hand toolbar. Then in the Modifiers roll-out scroll down and select Skin. New properties will appear below. Click on the Add button and select the 5 bones. The weighting for each bone should have already been set up automatically by the Modifier, if not then just hit the big button that says Envelope and then adjust the cage. Now export the model again overwriting the old cylinder.smd to the cylinder folder on your desktop. This time the model will export with bone information the exporter takes a little while, and may seem to be doing nothing. Just wait and it will eventually finish, will take a minute or 2. Move this exported model to cstrike_sample_content\model_sources\cylinder and overwrite the current model.

Ok now right click on the little play button on the bottom right of the screen. And change the length value to 60. Now you can make any sort of animation you want. Infact the length doesn't even need to be strictly 60. Could be any length you want. I won't go thorugh the ins and outs of animation. Once you've made the animation export using the script. Now this time click on the roll out and select Skeletal Animation (.SMD) then export the file naming it cylinder_idle.smd then move this file to cstrike_sample_content\model_sources\cylinder.

then open up cylinder.qc and replace the line

$sequence idle "cylinder" loop fps 30

to

$sequence idle "cylinder_idle" loop fps 30

The number 30 sets the playback speed in frame rate. If you designed your model to playback at 60 fps, then change this value to 60. And go back to command prompt and type to recompile the model.

%sourcesdk%\bin\studiomdl %sourcesdk%\cstrike_sample_content\model_sources\cylinder\cylinder.qc

Then go back to the Model viewer and load the model again. This time the animation will play. So well done you have successfully exported the model with an animation. Not too hard now was it. I'm going to work on a port of the Vehicle tutorial for 3ds Max. I have run into some issues with vertex weighting which I need to try and resolve it.

Cheers, d0Cd

Personal tools