Blender Modelling Walkthrough

This tutorial covers creating a model in Blender and exporting it to Source. The model being made is a soda can, to make it we will be using Blender's mesh editing and texture mapping tools.
This tutorial was based on version 2.48 of Blender for Windows, but should be relevant with version 2.49 as well. The scripts and instructions listed here have not been tested with earlier versions of Blender.
== Installation ==
If you haven't already done so, please go through the instructions in the article Installing Blender to make sure you have everything set-up as needed to complete this tutorial.
The export plugin used for this tutorial was dvondrake's Exporter.
== Keys reference ==
Key	Key
 	Left Mouse Button
 	Middle Mouse Button
 	Right Mouse Button
 	Mouse Wheel
 	Mouse Wheel Up
 	Mouse Wheel Down
 	9 on the main keyboard
 	9 on the Number Pad
== Getting Started ==
Now, if you haven't already, load Blender. You should have the default screen, seen to the left.
For a brief over view, Blender's workspace is divided into different areas called viewports. Each viewport area contains a different "Window Type" that can be changed by clicking on the Window Type icon. Also, every "Window Type" has a header that can be relocated to the top or bottom of the window, or be removed entirely by clicking on it with the . Blender starts with three viewports open by default:
: 1. The User Preferences Window
: 2. The 3D View Window
: 3. The Buttons Window
Will be going over these more later, but that's it for now.
== Adjusting the preferences ==
The User Preferences Window is hidden by default with only the header visible. To make things easier to keep track of, lets turn on the view name option inside the preferences window. Position the cursor just under the "File Add Timeline... " header, it should change from a pointer to an up/down arrow. With the cursor as an up/down arrow, press the and drag the cursor towards down to about the middle of the 3D view and release it. If the "View and Controls" tab is not active, click on it, then click on the "View Name" button (to the left of the viewport) with the . The position name should now be visible in the top left portion of the 3D View. When you're finished setting the options, again position the cursor under the "File Add Timeline... " header, then drag it back up to the top of the screen with the .
== Creating the model ==
To start off with, save the image file below somewhere on you computer, and take note of the location. We will be using it later on in this tutorial to skin the model. For this tutorial, I've saved the image to "c:\Modeling\Blender\SourceSDK\Guide\".
Next, lets get rid of the light and camera, then delete the cube. To select both the light and camera, first select one of two with the , then select the other by holding and clicking on it with the . Now press to hide them both from view, you can unhide them later by pressing . Now select the cube with the and delete it by pressing and confirming the delete by clicking "Erase Selected" with the .
Add a cylinder by pressing , then choosing Add > Mesh > Cylinder (if you select the wrong item, just press to cancel the operation). When the "Add Cylinder" confirm window pops up, change the number of vertices to 12, then click "OK" to create it. The cylinder is created at the location of Blender's "3D cursor" 
Now to rename the cylinder. With the cylinder selected, switch to the edit buttons panel by pressing (or by clicking on the 4 dotted square), and then replace "Cylinder" with "BlenderSoda" in the ME: and OB: boxes.
=== Repositioning the object and "origin" (object center) ===
While the "center" of the cylinder (the small pick dot) should already be at the coordinates "0 0 0", it's also in the center of the geometry itself which we don't want. Instead we need to have it at the bottom of the object, to do this we will need to reposition the mesh. Change to the "front" view by pressing (or clicking "View" and choosing "Front") and if the cylinder isn't already selected, do so by clicking on it with the . To move the geometry and leave the center in place, go into edit mode by pressing . Make sure the entire cylinder is selected by pressing (unselct all/select all) until everything is highlighted, then press to go into grab mode, to limit movement to the Z axis, and to move the geometry up 1 unit.
=== Editing the mesh ===
Now while still in mesh edit mode, go down to the 3D Views toolbar and turn on occlusion by clicking the "Occlude Background Geometry" button (the cube icon), then change to "Face Edit Mode" by clicking on the "Face" button (the triangle next to the cube icon).
Rotate the 3D View so you can see the top of the cylinder by pressing and dragging down with the , you can also rotate the view by . Next, activate brush select by pressing twice, and then highlight the top faces by clicking them with the (in brush select mode selects, deselects). If the paint brush is to big, you can reduce it's size by rolling the . Now exit brush select mode by clicking the or by pressing . Move the selected faces up by pressing to grab, then press then to bring the selected faces up 1 unit along the Z-axis and then to confirm.
=== Opening the UV/Image Editor ===
Now we need to unwrap the model, to do this we need to first open the "UV/Image Editor" in a new viewport. To do this we have to "split" the 3D view in half; move the cursor down so its at the bottom of the 3D Views toolbar and it should change into "Up/Down" arrows, when it does press the and select "Split Area" with the . As you move the cursor around a vertical bar should now be following it, position the vertical bar in the center of the 3D view with the cursor and confirm the split position by clicking the . The 3D viewport should now have been split in two.
Open the UV/Image Editor in the right viewport by click on the "Window Type" icon with the , then use the again to select "UV/Image Editor".
=== Marking the Seams ===
Now we could select all the cylinder's faces and pressing to unwrap the model right now, but if we do we might get odd looking UVs. This is because Blender doesn't know where to separate the texture. To fix this we need to "mark seems" on the model. Move the cursor back into the 3D view and if you're not still in mesh edit mode for the cylinder, reactivate it by select the cylinder and pressing . Change to "Edge Select Mode" by holding and pressing , when the "Select Mode" menu pops up, release and , then click on "Edges" with the .
To select the first seem we will be using what is know as "Edge Loop Section". Make sure nothing is already selected by again pressing , then position the cursor so it lies near the center of one of the edges going around the top of the model. Now, while holding , press the to select a "ring" of edges going around the top of the model. After selecting the edges, hold and press to bring up the "Edge Specials" menu and click "Mark Seem" with the . The top ring of edges should now have an orange color to them indicating a seem. Now select just one of the edges going down the side of the cylinder and again use the "Edge Specials" menu to mark another seem. Rotate the view by holding and while the cursor is in the 3d View and dragging the cursor up until you can see the bottom of the cylinder. Now repeat the process you used to select and mark the first seem at the top of the cylinder.
=== Unwrapping the model ===
We should be able to now unwrap the cylinder. Switch back to "Face Select Mode" ( ) and press until all the cylinder's faces are selected. Next, press to bring up the "UV Calculation" menu and select "Unwrap" with the . The model's UVs should now show up in the UV/Image Editor viewport.
Now let's open the texture to map the UVs onto. In the "UV/Image Editor" viewport, goto the "Image" menu and hold down while clicking "Open" with the , doing this will open the file browser in "preview mode", allowing you to see thumbnails of images before opening them. Goto the location you saved the "RedSoda.png"
file to and use the to select it. The file name should now appear just under the directory location at the top of the file browser, click on "Open Image" to load the image into the "UV/Image Editor" viewport.
=== Mapping the UVs ===
Now it's time to map the cylinder's UVs onto the image. Select the right circular face by moving the cursor over part of its' geometry and press to select "linked geometry". The whole circular texture should now be highlighted, activate grab mode by pressing , and drag the object over the right circle on the image. Repeat this process for the left circular texture dragging it over the left circular image. Try and position the circular textures in the center of the image they're below, then scale them up until they mostly cover the circular parts of the image below them without going outside of the circle parts. Scale them by first selecting the coordinates with , then press to enter "Scale Mode". By dragging the cursor away from the object the size should increase, by dragging the cursor towards the object the size should decrease, hold to lower the change on scale when moving the cursor. (note: tip, the closer the cursor is to an objects center when activating a transformation, such as Scale or Grab, the greater the influence moving the cursor will have on the transformation). 
Once you finish with moving the two circular UV maps into place, press until nothing is selected, then press once to enter "Box Select Mode". Drag a selection box over just the top set of coordinates in the box shaped UV with the to select them. Then press and to limit their movement to the Y axis. Just as you did with the circular cooridinates, try to get this top row of coordinates as close to the top of the red box shape on the image without going off of it.
Once you're happy with how the coordinates are situated, choose "Images" then "Save As" from the UV/Image Editor's toolbar. Change the file name to "BlenderSoda.png" (the same name we're using for the model), press to confirm, and click "Save Image" with the . 
You can now see a preview of how the image is being mapped onto your model in the 3D view by clicking the "Draw Type" icon in the header and selecting "Textured".
=== Adding a material ===
Change to the "Shading" menu in the buttons window and click the "Materials" icon. Use to click the up/down arrows icon next to "Add New" and choose "0 Material" (if there's no "0 Material" listed, just click on the "Add New" button itself to create one). Change the name from "Material" to "BlenderSoda". 
To the far right of the panel should be a tab labeled "Texture", click on the tab next to it labeled "Map Input" and click on the UV button. This will tell Blender to use the models UV coordinates to align the material rather then the material settings.
=== Adding a texture ===
Now click on the "Texture Buttons" icon with the to bring up the texture buttons panel. As you did with the material, change the "TE:" name from "Tex" to "BlenderSoda". Click the bar under "Texture Type" and select "Image", two new button panels should show up. 
Under the panel to the far right labeled "Image", click on the up/down icon next to "Load" and choose the image we saved from the UV/Image Editor earlier, "BlenderSoda.png". Take note of where the texture is being loaded from (you can see the location by clicking the folder icon), we will need to go here later. If all has gone well, we should be ready to export the model.
== Exporting the model ==
:To export an animated model, see Animation in Blender.
For the model to work inside the Source Engine, we have to convert it and the texture it uses into the formats the Source engine uses. You will need an export script installed to continue.
 
Move the cursor back into the 3D viewport and change to object mode by pressing . Make sure only the cylinder is selected, then goto file, select "Export", then choose Half-Life 2 (.smd). 
An export window should pop up, select "Static Mesh", and change the export file name to "BlenderSoda.smd". Before clicking "Export", take note of where Blender is outputting the file to (in this example the folder is "c:\Modeling\Blender\SourceSDK\Guide\").
After exporting the file, goto the directory Blender used for exporting and copy the "BlenderSoda.smd" file into the games "modelsrc" directory. For this example, I'm copying to the Half-Life 2 Death Match SDK folder:
:C:\Program Files\Steam\steamapps\USERNAME\sourcesdk_content\hl2mp\modelsrc
=== Compiling the QC file ===
:Main article: Compiling a model.
In the same folder above were the SMD file ("BlenderSoda.smd") was copied, create a new text document, and open it with notepad. Copy and paste the following inside:
<nowiki>
$modelname BlenderSoda.mdl
$cdmaterials "models"
$scale 2
$surfaceprop metal
$staticprop
$body mybody "BlenderSoda.smd"
$sequence idle "BlenderSoda" fps 1
</nowiki>
 
After checking over the values used in the QC file, save it into the same folder the SMD is in as "BlenderSoda.qc". 
To compile the model, open the command prompt (on Windows XP, "Start > Run... > cmd"). Copy and paste the commands below into the prompt, be sure to replace USERNAME with your actual Steam login name before running the command:
<nowiki>
"%sourcesdk%\bin\ep1\bin\studiomdl.exe" -game "c:\program files\steam\steamapps\USERNAME\half-life 2 deathmatch\hl2mp" -notxbox "C:\Program Files\Steam\steamapps\USERNAME\sourcesdk_content\hl2mp\modelsrc\BlenderSoda.qc"
</nowiki>
The compiled QC files outputs should have been sent to the folder:
: "C:\Program Files\Steam\steamapps\USERNAME\half-life 2 deathmatch\hl2mp\models"
=== Converting the UV/Image to a VTF ===
:Main article: Creating a Material.
Now we need to convert the "BlenderSoda.png" file we used to texture our model with into Valve's Texture Format. To do so, refer to the tutorial Creating a Material.
The four important thing to note here are:
# The texture file has the same name as the model.
# The converted texture file is located in the proper folder:
#: "C:\Program Files\Steam\steamapps\USERNAME\half-life 2 deathmatch\hl2mp\materials\models"
# The texture file has a VMT file ("texturename.vmt") with the same name as the material model in Blender ("BlenderSoda.vmt") and folder location ("hl2mp\materials\models") as the texture file
# The VMT file has the proper values assigned to it:
<nowiki>
VertexLitGeneric
{
	$basetexture models/BlenderSoda
}
</nowiki>
=== Testing the model compile ===
Lastly, after you have converted the model and texture into the proper format, it's time to check and see if everything went according to plan.
 
* Bring up Steam, go to the tools tab, and open the Source SDK
* Make sure you have the right game engine and game selected in the Source SDK window 
* Open the Model Viewer, and with the , click on "File" then "Load Model".
* Using the model browser, locate the file "BlenderSoda", and open it. 
Hopefully now you'll be looking at your fully compiled and textured model.
Image:blender_walkthru_260.jpg|prop in the Model Viewer
Image:blender_walkthru_270.jpg|prop in-game
=== Additional Notes ===
Image Files:
*The Source Engine requires all image files to have a width and height that are a power of 2 (16, 32, 64, 128, 256, 512, etc). The image used in this tutorial "BlenderSoda.png" had dimensions of 256 x 256. If you want to make your own model texture, make sure it's dimensions follow this convention.
==== Other Source games ====
In this tutorial, the model was created for Half-Life 2: Deathmatch, but another Source game can easily be substitued. For the last steps, just use that games model and texture source directories instead of HL2DM's.
Eg: For Team Fortress 2 you would use:
*"C:\Program Files\Steam\steamapps\USERNAME\sourcesdk_content\tf\modelsrc
 "%sourcesdk%\bin\orangebox\bin\studiomdl.exe" -game "c:\program files\steam\steamapps\USERNAME\team fortress 2\tf" -notxbox "C:\Program Files\Steam\steamapps\USERNAME\sourcesdk_content\tf\modelsrc\BlenderSoda.qc"
*"C:\Program Files\Steam\steamapps\USERNAME\team fortress 2\tf\models
*"C:\Program Files\Steam\steamapps\USERNAME\team fortress 2\tf\materials\models
Eg: For Left 4 Dead you would use:
*C:\Program Files\Steam\steamapps\common\left 4 dead\sdk_content\modelsrc
 "C:\Program Files\Steam\steamapps\common\left 4 dead\bin\studiomdl.exe" -game "C:\Program Files\Steam\steamapps\common\left 4 dead\left4dead" -notxbox "C:\Program Files\Steam\steamapps\common\left 4 dead\sdk_content\modelsrc\BlenderSoda.qc"
*C:\Program Files\Steam\steamapps\common\left 4 dead\left4dead\models
*C:\Program Files\Steam\steamapps\common\left 4 dead\left4dead\materials\models
== See also ==
* Blender
* Modeling props with Blender
* Is Blender 3D Good for Source? - How to Start
* Model Creation Overview
== External links ==
Unwrapping a Mesh (Blender wiki)
Category:Blender