Since this has been asked I want to show you how to export and compile an *.mdl modelfile for GoldSRC from Blender, using the following tools:
Before we start:
"blender": (2, 66, 0),This should tell you which Blender version the SMD Tools support.
Basically a model which you want to compile for the GoldSRC engine will need to fulfill the following conditions:
In case you dont want any animation you can completely skip the skeleton/bone part and just export the model as an SMD. You will however need to have something like a blank idle.smd you can use for the most basic animation, which is mostly just the model in a static state.
A blank idle.smd may look like this:
version 1 nodes 0 "origin" -1 end skeleton time 0 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 end
Using this empty idle.smd will only work for models that have no bones (or maximum ONE bone – bone “0″) attached to them in Blender, since the Blender SMD Tools are not made for exporting (fully) GoldSRC-compatible SMD files. This causes that all polys will be attached to bone “0″.
What this means for models with more than 1 bone I will explain later.
First of all you gonna need a model.
As an example I will use a model that already has some animations and one controller, a little toycar version of the Black Mesa SUV.
I am sure you have already seen it on top of this article.
When you open the project files directory you will find a number of subfolders, which divide the project files in a clean and well-arranged way.
You can of course choose your own way of arranging project files into subfolders. In any case: DO IT AT ALL (!), because it will become essentiall when there are a lot more different files and filetypes for complex models like those of NPC characters.
Navigate to the blend directory and open the file toycar.blend in Blender (in case blend-files are not associated with your Blender yet, you should do that manually now).
When you have opened the file, this is what you will see (might differ when you told Blender to not load window configuration of blendfiles):
At the moment the only interesting objects for you are the skeleton “Armature” and the model “toycar“, which is already connected to the skeleton in 2 ways: an Armature-Deform-Modifier and by physically being parented to it. This was done by first selecting the toycar, then the Armature and then pressing CTRL+P and choosing - .
How this is done in detail I will cover in a separate tutorial.
If you havent already done that, press the smallbutton left of the armature in your scene navigator to see the underlying objects.
If you select the armature you can also see that there is already an animation sequence associated with the armature. As you will see later, there are even more sequences.
You can already play the current animation by moving along the timeline with the right mouse button pressed.
If you want to see how the toycar mesh is parented to the armature, you can navigate to the Object-Modifier tab in the middle of the Properties-panel:
Try to turn off the Armature-Modifier by either unchecking “Bind to: Vertex Groups” or pressing the little eye-button in the armature-header area, then move the armature around (select it, press G and drag).
You will see that the toycar is still following the transformation of the armature-object. This is because it is still bonded to the armature physically by being parented to it.
You could dissolve this relationship by selecting the toycar and then pressing ALT+P .
In the navigator the toycar will then not underlie the armature object anymore.
If you want to redo the relationship between these two objects, first select the toycar, then the armature and then press CTRL+P- (considered you still have the Armature-Modifier added to the toycar, if not: choose ).
To see all of the associated animation sequences of the armature, you will have to create a new window (or rather create one out of another).
For this navigate to the bottom left corner of your timeline until your mouse cursor changes into a little cross.
Grab and drag this cross to create a new window. You will probably have to resize both of them.
Turn the new window into a.
Where it saysin the menu bar of the Dopesheet window, choose instead.
You can now flip through the various actions of the armature and watch them by moving the timeline.
So far so good, but now you probably want to learn something about the relevant stuff.
With every new version the SMD Tools have changed a bit, both in their features and interface, so if you are using another version than 1.6.5. you will probably have to translate the following steps to your version.
The Blender SMD Tools are made for exporting Blender files into the Source SMD file format. However the Source and the GoldSRC smd format are pretty close to each other, so it is still possible to export smds for simple models (e.g. without animation or only 1 bone) without any further steps (as I explained above).
What does this mean for our example toycar model? Maybe it gets a bit more clear if we look at the difference between these two formats.
Here are some lines of the reference-SMD file of our toycar in Source format (as it will be exported by the Blender SMD Tools):
body.bmp 0 1.000000 -1.362009 1.847306 0.163518 -0.346416 0.923704 0.231964 0.684915 1 1 1.000000 0 1.239749 -1.346065 1.771808 0.856990 -0.159764 0.489914 0.230389 0.651338 1 1 1.000000 0 1.031438 -0.038912 2.795163 0.690054 -0.216895 0.690451 0.450439 0.675454 1 1 1.000000
These are the same lines, just that they are now compatible to GoldSRC:
body.bmp 1 1.000000 -1.362009 1.847306 0.163518 -0.346416 0.923704 0.231964 0.684915 1 1.239749 -1.346065 1.771808 0.856990 -0.159764 0.489914 0.230389 0.651338 1 1.031438 -0.038912 2.795163 0.690054 -0.216895 0.690451 0.450439 0.675454
The most important difference (which makes a Source SMD file useless for us in the first place) is, that all triangles are assigned to bone zero (the first number of each line), instead to the correct bone number.
Instead you will find the bone and weight information for the Source format at the end of the line, where it is usually ignored by common GoldSRC model compiler.
How we will overcome this issue, I will tell you in one of the next steps.
… and scroll down to the bottom. Here you will find the settings of the SMD Tools.
The SMD Tools will let you export seperated objects (e.g. “toycar.smd”) as well as the whole scene (which means that all available meshes and actions will be exported unless you say otherwise) by pressing one of the first two main export buttons.
If you just want to export the actions of a selected armature, you can either choose to export only the action that is currently shown in the timeline (or NLA) or all actions of the armature, by choosing the Action Filter option.
The export button will then say something like “All actions (4)”.
In our case, choose , to export all actions that are associated with the armature.
To define wether objects are exported by the-button or not, just check or uncheck those objects at the section. Usually you will just want to export your final model meshes and its animation.
In this case there are just two objects shown, the armature (actions) and the toycar-mesh and we want both to be exported.
This is what we probably should have done in the first step (remember to slap me for that). If you dont specify an output folder, the SMD files will be exported to the root of your current working directory, since Blender uses relative paths a lot (what I like a lot by the way).
We want our “smd”-folder to be the output folder in this case.
You can as well just type in something like that:
This is a relative path to the SMD folder as recognized by many other windows programs (as I suppose). It says “from the current root folder (//) move one directory back (..\) and then enter the smd-folder (smd\)” (I just put two and two together here, dont take me too serious).
By the way, by default, animations will be exported to a seperate folder called “anims”. As I realized it before, there is no way around this (but its not so bad either).
Since I have gone a lot into detail and messed up your mind, let me recap the steps for exporting our toycar-scene again:
In case the smd export was sucessfull, you should now find several new files inside your smd folder:..\smd\toycar.smd
Most of these files can already be used to compile your final model with, but, as I explained earlier, there is one exception.
Because of the Source format we will now have to convert the reference-smd (toycar.smd) into a GoldSRC compatible smd format.
As there is no other (practical) method I know about, I will now tell you how to convert your Source SMD file into a GoldSRC compatible version by using Milkshape 3D.
Basically its as simple as just importing your reference-smd into an empty MS scene and then exporting it again under the same name (maybe into another folder, e.g. “..\smd\fixed\“).
But just to be sure, once again:
In the menu choose- to reset the scene.
In the menu choose- - while leaving all settings checked (Triangles, Skeleton and Rename Bones, even though I consider the last one is not doing any difference).
Now just export the scene again no Vertex Weights)- - using the settings (but
And that was the whole process of converting a Source SMD into a GoldSRC SMD.
You can now move on to creating a QC-file.
QC files define the properties of the compiled model and put together everything, that has been created so far – your model (the reference smd files), its animation (the animation smd files) and its materials.
Additionally you can specify things like bone-controller (e.g. for controllabe heads and mouths), body-groups, texture-groups, advanced settings for animation sequences and attachments (e.g. for sprites like muzzleflashes or the gargantua eye glow). You can also specify Hitboxes, the position of the entities eyes and even more stuff I dont remember right now (I am not a brainman, you know).
For now, we will be satisfied with setting up a simple QC file, where we define some paths, the animation sequences and one controller.
For more detailed informations about setting up QC files, please google for any Half-Life SDK (2.3 seems to be the latest). It will contain a doc-file similar to “Modelling for Half-Life.doc”.
Basically I can tell you, that the qc file contains information in the form of commands that begin with a $-sign. Dont get scared and associate this with coding though!
In the root project folder create a textfile and rename it to something like “built.qc“.
The following lines are more or less important for the compiling process to be successful. Put those into your qc-file:
$cd smd $cdtexture mat_index
Paths can be absolute or relative. Relative paths are relative to the position of the qc file.
Absolute paths should look like this:
$modelname D:/Modelling/blender_smd_tutorial/toycar.mdl //or (in case folder names contain spaces): $modelname "D:/Modelling Projects/blender_smd_tutorial/toycar.mdl"
Relative paths can look like this:
$modelname toycar.mdl $cd smd
Note: If you dont have any subfolders, you can as well completely leave out
$cd will be the base for all further paths where smd files are involved (e.g. those of
Usually, if the models scale is already matching the final ingame size, you can skip this command.
$body studio "fixed/toycar"
Here you just place the path and name of the reference-smd that contains the models mesh.
Note: Any declaration of files (except
$modelname) happens without adding the file-extension! Thats why “toycar” is not “toycar.smd” and sequence-paths are specified like “anims/walk” and not “anims/walk.smd“.
This is where it gets a bit more confusing and complex, even without having a complex character model.
$sequence static "anims/static" fps 10 $sequence idle1 "anims/idle1" fps 30 LOOP ACT_IDLE 1 $sequence driveslow "anims/walk" fps 30 LX loop ACT_WALK 1 $sequence drivefast "anims/run" fps 30 LX loop ACT_RUN 1
I would also recommend that you take a closer look at existing qc-files (which can be generated out of any compiled models by decompiling them, e.g. using the MDL decompiler by Jed, OR you just look at those that are shipped with the Half-Life SDKs).
Just to explain this one a bit closer:
$sequence driveslow "anims/walk" fps 30 LX loop ACT_WALK 1
driveslow– This is the name of the sequence that is visible in the final mdl-file. This name can also be used by various entities in hammer, like the scripted_sequence.
"anims/walk"– This is the name and the path of the animation-smd for this sequence.
fps 30– This is of course the framerate for this sequence (here it finally gets specified – remember that specifying FPS in Blender hasnt any effect on the exported animation).
LX– This short value defines, that the transformations of the model during these sequence are affecting the characters actual location and rotation in-game, which is important for a lot of animation-sequences where the character covers a distance (e.g. a simple walkcycle).
loop– This indicates, that the animation is an endless cycle (e.g. like an idle-animation).
ACT_WALK 1– When you use this on a sequence, the characters AI will be able to use this sequence for its usual in-game behaviour, like walking, turning around, getting hit and attack. The last number specifies the possibility for playing the sequence.
$sequence command can as well look like this:
$sequence idle1 "anims/idle1"
And at last there will be a controller for the little Black Mesa logo on top of the SUV. Controller are named like the correspondent bone and put into groups, in case one controller controls more than 1 bone:
$controller 0 "logo" YR -90 90
0is the controller ID (0 – 3 are possible)
logois the name of the correspondent bone, which will then get controlled
YRsays that this controller controls the rotation of the Y-axis of this bone (X, Y, Z)
-90 90– these are the minimum and maximum limits of rotation
When you have set up your qc-file so far, you can finally give it a shot and compile the model. If there is still anything wrong at this point, GUI StudioMDL will hopefully tell you what, so you can fix it.
But for this to happen (or not to happen, depends) you will first have to install GUI StudioMDL. When done, just navigate to your project folder, where you created the qc-file, and run it (that is, if qc files are associated with GUI yet. If not – try it manually).
If the compile process was successful, you can now open the toycar.mdl.
You can try using it in-game.
I went a bit further and replaced my barney.mdl with this and it worked just fine. The game even uses the logo-controller for Barneys head-movements.
Well, I know I have left out a lot of information, but think about it. I can hardly put all the details into one tutorial, that would be insane :)
I hope I was able to show you the principle of the process and even give you a bit background information.Information about QC-files
If you need more informations about QC-file setup, look for the Half-Life SDK on the internet, it will be there, anywhere.
For example here.Blender Tutorials
If you want to learn more about Blender, look for Blender tutorials on the internet, its not that hard. Video tutorials are good for people who learn stuff better by seeing it (like me).
I am afraid this is a question where I dont know a good answer for. I thought of building a script that does the same as Milkshape, but I am not a coder of course. Unfortunately the author of the Blender SMD Tools doesn’t seem to find it necessary to built in this little feature (maybe hes just not aware of it?!).
If somebody knows a good alternative or way to do this, please leave me a message and my special thanks goes to you!