Team Fortress 2

Team Fortress 2

148 oy
How to make a custom weapon in Blender [Beginners]
Wircea tarafından
A guide that will introduce you to the basics of making a custom weapon model, exporting it, creating a texture and getting it in-game.
2
2
   
Ödül
Favorilere Ekle
Favorilere Eklendi
Favorilerden Çıkar
Before we start
Please note the following:

-I am new to Source modding and Blender itself, so a few things may be done wrong, please correct me if you know any better
-The only reason I am making this guide is because there is no one around
-The images I will post will be low quality so they are compressed in order to save page load time
-The Workshop, at the time of making this guide, does NOT support custom weapons, so you will not be able to get a "certified compatible" tag
-In this guide I will make a poorly designed (not designed at all) model, because something happened and I lost the screens I made for my first attempt.
-I will also try to introduce you to Blender and some of the basic methods if you're new to modelling.

However, here's another weapon I made following the steps you will find on this guide:
http://steamcommunity.com/sharedfiles/filedetails/?id=376507925

Also my first Workshop entry:
https://steamcommunity.com/sharedfiles/filedetails/?id=514742455
Tools needed
You will need the following software:

-Blender[www.blender.org]
-GCFScape[nemesis.thewavelength.net]
-Crowbar
-Any image editor that supports transparency (alpha channels). The ones I recommend the most are Photoshop, Paint.NET and GIMP. Note that you can't use Paint.NET for modifying the alpha channel by itself. So no envmap for you, boi.
-VTFedit[nemesis.thewavelength.net]
-Notepad++[notepad-plus-plus.org]

After installing Blender, you will need to install the Blender Source Tools[steamreview.org].
More details on how to install here

Here's an image of the installation section in-case you don't see it:

Preparing our project
For the sake of staying organised, make a folder you will use as reference and name it whatever you want. I will name mine "ditto". I'm not sure why, but it doesn't really matter.
Next, make 2 folders inside and name them input and output.

This is not actually needed, but it's better to stay organised.

This is how your project folder should look like:

Next, navigate to your Steam directory. Mine is on the B: directory (yeah, I know).
Proceed to SteamApps>common>Team Fortress>tf

If you scroll down, you will see a bunch of .VPK files.
Keep scrolling and search for "tf2_misc_dir"
Now open it.
If it states that the file type is unknown, make sure you have GCFSape installed and/or select it manually as a default program to open .VPK files with.
Getting started
In order to ensure that our item has the right proportions, the best thing to do is to actually get a model in our editor so we can use it as reference. This will prevent CLIPPING a lot, because your item will use the same animation as whatever you decide to replace. So keep track of what your class is touching while holding, shooting and reloading the weapon so it doesn't get in the way.

For this tutorial I will edit the Direct Hit.
The reason I choose the Direct Hit it's because it's the easiest model to go by, with no animations or bones (other than the root and weapon_bone, which every weapon has)
Let's just say it's better than editing a melee weapon.

So, hit ctrl+f while having tf2_misc_dir open and type in "directhit"
A bunch of folders will show up.
Now drag the indicated files into your input folder you made earlier.


Decompiling the reference model
In order to get the model into Blender, we have to decompile it.
That's why we have crowbar.

Open up crowbar and browse for the .mdl folder from your input directory.
Check the "Full path" radio button and browse for the output directory.
After you're done, press "Decompile .MDL File"

You should get this compile log. If you don't, make sure you have dragged all of the needed files into the input directory.
Importing our decompiled model into Blender
Pretty much everything starts here.
Open Blender and load up a new session.

Select the cube (right click on it) and press Delete on your keyboard.
You don't need it.

Now go to File>Import>Source Engine(.smd, .vta, etc.)

A browser will appear.
Navigate to your output folder and select (single click) the file with the biggest size, in our case c_directhit_reference.smd
The rest are lower-quality versions of the model so I guess you won't need them for now.


Before clicking import, make sure that "Up axis" is set to Y.


Now click import.

This is what you should see:

If you're not familiar with Blender, you can move the camera around by using Mousewheel, ctrl+Mousewheel, shift+Mousewheel, along with others. Experiment yourself or use Google.
Also SHIFT+F will bring a better navigation with WASD and mouselook controls.

Now head to the right upper corner and click the little orange outlined triangle next to the c_direthit_reference_skeleton

Editing the model
In order to be able to edit our reference model, press the Edit Mode button located on the Footer, and check "Edit mode"(TAB is a handy hotkey).



Now, a little trick is to convert the triangles into squares, so you will have a better view over the model.
This is completely optional but I recommend it. To be noted that Source will convert the model into triangles automatically.

First, press A until you will see everything highlighted with orange/yellow

Now, press ALT+J.


In case you don't see any differences, compare the 2 images above.
Some basic Blender elements(Optional)
If you're new to Blender or any modeling program (or simply forgot everything about it), then read this section.
I will not get into detail. If you need more help, then use Google.
I will use this section to explain how to edit the model and add additional meshes.

First, a list of elements:

Vertice= a point in a 3d space
Edge= a straight line between 2 vertices.
Face= area resulted from 3 or more edges that connect (e.g: triangle, square, etc)
Mesh= multiple faces that connect

SELECTORS

There are 3 buttons, somewhere on the lower right corner, each for selecting vertices, edges and faces respectively.

For instance, if you choose the "Select Faces" one, right clicking anywhere on our model will highlight a face.


If, while having a face selected, pressing CTRL+Right_Click on another face will result in all consecutive faces between these 2 to be selected:


If you want to manually select multiple faces, use Shift+Right_Click


EDITORS
With the editors you can manipulate certain actions over the selected region.
You can find them near the Selectors


I don't think I'll have to illustrate what these do, the first one will enlarge the selected region to a certain direction, the second one will rotate the selection, and the third one will enlarge the selection in 2 opposite directions at once.

Now something important:
If you will select a region, like below

if you will use the first editor, you will notice that our modification also affects the nearby edges, creating some ramps around.

If you don't want that to happen, simply press E before editing. This will create a clone of your current selection, so you can edit it without worrying anything around will change. Warning tough, as it will increase your polycount. This process is called EXTRUDING.


Create additional meshes

Easy as it it, just head to the "Create" tab on the left and select a mesh that you need.

Just a tip: Press Left_click somewhere to set a spawn point of your mesh, so you don't have to move everything just to reach your mesh that spawned outside of the camera. SHIFT+C resets the point back to 0,0,0.
UV Wrapping
Using the tips above, I made a really quick model.

The only things I did where to sightly edit the back-end region (it's now enlarged) and add that little turd on top.

You can however make a serious model if you want, just don't waste too much time, because this is supposed to be a test item.

Now, what is UV Wrapping.

Think about it like how clothes are made, you get a big piece of material and cut certain shapes, then place them together to get your pants, T-shirt or whatever.

That's how it works, and it's main purpose is to make texturing way easier.

To begin, drag that triangle to like half of the screen

Careful not to open more than one, because I have no idea how to close them.

On the new window, look at it's left lower corner and click on the button with a cube on it, then select UV/Image Editor

You should now see a grid.


If you will select your entire model (press A in the model viewer) you will see the way Valve or whoever made the model unwrapped it.

It looks really well organised and ready for a texture to be drawn on, doesn't it?

Allright, remember when I said that thing about clothing and the way you have to cut certain shapes? Well, these cut markers, or cut edges are also available in Blender and are called seams.

Seams are the way to tell Blender where to cut around.
For instance, look how I unwrap the mesh above the directhit.


I made a simple line all along so Blender will spit it into 2 simetric shapes.

While this is the simplest way to unwrap a model, it's not that efficient, as you may find it easier to unwrap it in a such manner you will only get one shape.

You'd better look out on Google how to unwrap if you can't figure it out by yourself, but this is yet the only hard thing you will encounter.

Back to our model, in order to mark our selection as a seam, press ctrl+E and select Mark Seam.



Unwrapping
In order to unwrap a selection, just select everything you need, in my case the mesh above the directhit, then press U and check Unwrap.


This is what I got:


I will now proceed and also unwrap using the same method the main mesh of the launcher.
If you want to, you can unwrap everything you need in a such manner to get the most efficient seams, but I will just do the quickest unwrap.



Optimization

Let's say that I want the mesh above my directhit to get the most detail from the texture.
In order to do that, I'll have to enlarge it.

Because my unwrap is really inefficient, I can barely tell which shape represents my mesh anymore, so I will select it on the model viewer to find it.



By using the selector indicated by the arrow on the picture below, you can move each shape (island) independently. You move stuff with G, rotate with R and scale with S.

Alternatively, press E and your selection will be unwrapped again separately, which seems to do the job for me.
Baking Ambient Occulusion
Ambient Occulusion (AO) is a feature that casts shadows in order to be used along your texture.
This saves alot of performance because the engine won't have to render the shadows on the texture everytime a model is loaded.

In order to prepare for the bake, use the settings on the image below:


Before we can Bake, we have to create a new image.


Set a name, and make sure the resolution is not too big, or you will have to wait a lot of time for it to render.
512x512 is usually enough.


After the bake, this is how it looks for me like.

The reason it is so mesy it's because my unwrap was awful.

You can see how your bake turned out by switching to Object mode (press Tab) and switching to Texture mode.
If you're not happy of your result, feel free to repeat the UV process.

As you may have noticed, my mesh is quite blocky.

How do I make it look smoother?

Go back to Edit mode and highlight your desired selection.
Now head for the Shading/UVs tab on the left, right under Create.

Now press Smooth.

If we are going to bake again, this is the result:


It's really important to know when to use Smooth or Flat, as certain areas may not look right with either of these.

VERY LATE EDIT: I made this guide back when I did not know about HARD EDGES. Go ahead and google about them, ♥♥♥♥♥♥♥.
Texturing
Before we can texture, we need our Baked Ambient Occulusion.

Just go to Image>Save as image and save it somewhere, preferably on your main project file that you made at the beginning of this guide.

To be noted that in this section I will be using Paint.Net because it was the closest I had to my hand, but these also apply for GIMP and Photoshop.




Now open your image editor, in my case Paint.NET and proceed to open your AO file.


What you should do now is add a new layer.
If you're using Paint.net, hit F7 so your layer menu will appear and press the new layer button.

Now you have to edit the properties of your new layer by setting the Blending mode to Multiply


As you can see, whatever you paint now on the new layer will bend with the AO, making it way easier to texture because the shadows will stay here.


So go ahead and make a nice texture, experiment with the sliders from the layer properties to get better results and when you feel ready to test, then go ahead and save.

This is how my texture turned on

As I said before, the texture will be easier to create depending on how good your Unwrap was and in my case it would have been really hard if I tried to actually put effort into it.

Now save your image as a .png or any other image extension (.png is still preferred)


Back in Blender, go to Image>Open Image and select your new texture

Now look at your creation and see if there are any problems.

If you're happy with it, then get moving. (I'll get moving anyways)


Getting everything ready
If you finally decide to test your item, them you will have to set some thing up first.

First of all, move all files from your output folder to you main project folder (in my case, ditto)



You can also open the c_directhit_reference.qc file using Notepad++ and play with some values.
But if you don't know what you're doing, better don't.

That's how my .qc file looks like (only removed some lines)


Here's the code in text format:
$modelname "weapons/c_models/c_directhit/c_directhit.mdl" $bodygroup "c_directhit_reference" { studio "c_directhit_reference.smd" } $cdmaterials "models\weapons\c_items\" $cdmaterials "" $attachment "muzzle" "weapon_bone" 0 6.6 21.43 rotate -90 0 0 $attachment "backblast" "weapon_bone" 0 6.69 -40.73 rotate 90 0 0 $surfaceprop "metal" $contents "solid" // NOTE: The following commented-out $definebone lines might be needed, as is often the case for view models. When needed, simply remove the two slashes '//' from the start of each line. // $definebone "weapon_bone" "" 0 -2.245433 -2.109874 0 0 0 0 0 0 0 0 0 $sequence "idle" "c_directhit_anims\idle.smd" { fps 30 } $collisionmodel "c_directhit_physics.smd" { $mass 1 $inertia 1 $damping 0 $rotdamping 0 }

Now go to your Steam>Steampps>Team Fortress 2>tf>custom and create a new folder and name it whatever you want.
I named mine tutorial.


Back to Blender, go to object mode and right click your entire model (it should get an orange highlight) then follow these setting on the picture below:

The export path should be set on your main project folder, in my case ditto.

Click export when done.

Now another important step comes up.
I lost my screenshot of this step but I hope I'll be able to guide you.

Go to Steam>SteamApps>Team Fortress 2>bin and scroll down until you will find a file called studiomdl.

Now go to your main project directory and DRAG your c_directhit_reference.qc (or the .smd one, does not matter) over studiomdl.

This is the process of compiling.

Now if you go to Steam\SteamApps\common\Team Fortress 2\tf\models\weapons\c_models\c_directhit you should see a bunch of files that look like the directhit ones before being decompile.



Now back at our file that we made at the beggining of this section from the tf>custom directory (in my case tutorial) make a directory inside like this models>weapons>c_models>c_directhit and drag the compiled files here.


Now go back to the "tutorial" folder and make a directory materials>models>weapons>c_items

These 2 directories are really important and if you don't set them right your model won't show up in-game.

The last thing we have to do is to add the texture.
Open up VTFedit and go to File>Import and browse your Texture

Now proceed and go to File>Save and save it in your tf>custom>yourfilename>materials>models>weapons>c_items as "c_directhit"

The very last thing you have to do is to go back to the tf directory and open tf_misc_dir again, search for "directhit" (again) and copy c_directhit.vmf next to your vtf file.




LATE EDIT: The way I've assigned the texture is not that good. I didn't really know how and somehow still got it to work. You have to name your .vtf and .vmt as the assigned material from Blender. Don't forget to modify the .vmt too.
Final result
After joining the game, you will have to create a server (or join a server that has sv_pure 0) and equip the directhit.

The result:



Hopefully it worked for you too, and if it didn't, then feel free to ask what's going on.
I don't guarantee you that I will know what to do but it's worth trying.

Good luck.


139 Yorum
Bad bigy 6 Nis @ 9:26 
@Helvetical My fix was to put all the relevant files (.qc ; anim@idle.smd ; physics.smd ; reference.smd) in the binary folder (where you compile), and then compile using the .qc file. If it still doesn't work, remove the directory on top of your file explorer and type "cmd", then in the command prompt type "studiomdl.exe <the .qc file you are trying to compile>" and press enter, check what the errors are.

I haven't figured out how to properly apply the texture, I see no vmf files in misc_dir.vpk.
Shadow Wizard Money Gang 31 Oca @ 7:59 
@Helvetical I had the same issue and my fix was that I reduced the amount of vertices in my blender model using the decimate modifier
Helvetical 25 Kas 2023 @ 16:37 
I don't know if you're still accepting questions, but when I drag the files into StudioMDL.exe they don't ever show up in the models folder.
Krissygal 9 Eki 2023 @ 9:38 
It didn't work and I don't know where I went wrong... the model in game is exactly the same, no new model or texture. Anyone have any idea as to what went wrong? I'm trying to replace the model of the Scottsman's Skullcutter
Mastcharub 14 Eyl 2022 @ 6:15 
worked!
gable 26 Ağu 2022 @ 4:29 
ik im late af but i cant seem to get the texture to work....
Woodlands Wolf 16 Nis 2022 @ 23:44 
Only the cq file can be used to compile, if anyone is having trouble.
proobo 28 Mar 2021 @ 15:48 
it was earlier mentioned that there are better, up-to-date tutorials for learning how to do this online and yet, throughout my searching, I have found nothing to this level of detail. All of my searches only take me to making SKINS not MODELS. If anyone could help me with this that would be appreciated.
Xx_SpliffBurton_xX 16 Şub 2021 @ 7:10 
is he on windows 8
you (but stronger) 9 Oca 2021 @ 15:38 
you might wanna add an update, as several parts of this are now outdated.