Skip to main content

The How-To Guide To 3D Models In Doom - Part 1

This is a question that gets brought up a lot on the ZDoom and Doomworld forums. Whether its how to import a model, how to animate it, or how to just get the textures to show up correctly, in one way or another this question appears. I've been working on a mod that uses a heavy amount of 3D models and now I feel comfortable enough with GZDoom and Blender that I can write out a tutorial. When I first started importing models into my mod, I had zero knowledge on it. The ZDoom Wiki helps tremendously with 3D models, but not quite enough in my opinion. MODELDEF lacks some documentation on a few properties, like that damned SurfaceSkin property! That being said, you should still refer to it, as it is still the best documented and available resource for all things Doom.

Let's begin!

Pre-requisites

For this tutorial, I'll be using Blender to work with models and animations, and SLADE for working with GZDoom. I'd also recommend ZDL 3 as your Doom Launcher for testing your .pk3 out. Also, you'll of course want to use the latest version of GZDoom.

For Blender, you're going to need to download Nash's MD3 Exporter Plug-In and enable a few useful plug-ins. After downloading and placing Nash's plug-in into your plug-ins folder, go to File > User Preferences > Import/Export and check Nash's plug-in. Also, check any file formats you will want to be able to import (.obj, .fbx, etc...) and then save your preferences. It can also be useful having Noesis on hand if you need to convert models to other formats. That takes care of Blender.

For your mod, I recommend using the .pk3 format in SLADE. It's much easier to keep track of your files, and almost 100% required for doing models. This stuff is already more complicated than it needs to be, so we will just stick with .pk3 format. Go ahead and create a new archive in SLADE, and save it as a .pk3 file.

If you want to use my .pk3 as a reference, or just see what's going on inside, here is a download link.

Setting Up Our .pk3 In SLADE

First things first, create a folder and name it Models. You can technically name it whatever you want, but for now just name it Models. As you can tell from the name, we will be putting our models in here. Create another folder and name it whatever your model is. For example, the model I'm using is the Arm Cannon ripped from Metroid Prime, so I named my folder armcannon. Whatever you decide to name your folder, just know that inside there is where you will be putting the actual model .md3 file. Now, inside that folder, create another folder and name it Skins. This folder is where all the texture files on the model will be. I typically use .png, but you can use .tga and .jpg files too. Go back to the root of your .pk3. 

Now, create a new entry and name it MODELDEF. We will use this file frequently to define our models so GZDoom knows what to use in-game, so you might want to read up on the Wiki and get familiar with the properties. Remember, the sprite is king in the Doom engine; we're just kind of tricking it into loading a model.

That's it for SLADE, for now... Your .pk3 should look like this:



Blender: Models with mutliple textures (the SurfaceSkin way)

Ahhhhhh yes... the dreaded SurfaceSkin property! Believe it or not, it's not hard to use at all! It's just confusing at first because there isn't a "do this, then do that" guide to using it. You're going to want to use SurfaceSkin if your model has multiple materials. For example, the Arm Cannon model I'm using has 9 materials when I load it in Blender. So what does that mean exactly? It means we're going to separate the model into 9 pieces, or surfaces.

Ice Beam object with 9 Materials in Blender
First thing I usually do is rename the textures for each material, or check to see if Blender has appended numbers to materials using the same texture. If any two or more materials are using the same texture, Blender automatically appends a number to the end. For example, if I have Material_151 and Material_146 using texture.png, Material_151will have texture.png, while Material_146 will have texture.png.001. That won't work, because now our file has a totally different format; one that GZDoom will not recognize! The only solution is to make a copy of the texture, and rename it to something else. That way, both materials can have the same texture, but without appending a number to the end and messing up the file format. What I do, is I make a copy of all the textures my materials use, and I rename them to whatever the model is, followed by a number. Since this is the Ice Beam, I named all the copied textures to IBeam1.png, IBeam2.png, and so forth...

Next, what you want to do is rename the materials so that they follow the folder hierarchy in your .pk3. Remember how we made a Models folder, and then added another folder inside that for our model, and then added the Skins folder? That's the folder path we want for our materials. Since the first material is using IBeam1.png for the texture, I'm going to name my first material Models/armcannon/Skins/IBeam1.png. Now, I'm going to rename the other materials in Blender the same way:

See how they match?
Why do you have to do this? Well, this is the way that GZDoom reads the .md3 file. It's looking for the file path for each texture, for each material on the model. That way, it can render the model properly with the correct textures. That is why we name the materials this way. They have to follow the file path!

After you rename all your materials, it's time to separate materials on the model. This process is a little more involved, but don't worry! Go into Edit Mode in Blender and enable Face Selection. Now, were going to right click on the model's faces until we find out which one is using the first texture. If you watch to the right in Blender where it shows the materials, you'll see which material is actually selected when you select different faces. In my case, I'm looking for IBeam1.png, which I've found here:


Now, with that face selected, press Shift + G and select Material. Blender will select all the faces that use the texture IBeam1.png. Press P, and click Selection to separate that material from the model. We now have two models: Ice Beam, and Ice Beam.001:

Ice Beam is a model, and now Ice Beam.001 is a model!

Since the first material in Ice Beam.001 is using IBeam1.png, we can now delete the material using IBeam1.png from Ice Beam because it doesn't need to use it anymore. Get it?

What we're doing is separating the model into pieces, and each piece only has one material with one texture. You will find that when you separate each part of the model, all materials will carry over to the new piece. We don't want that either! So what do we do there? Just delete the materials for each piece and leave the one you actually need for that piece. For example, if Ice Beam uses IBeam9.png, then it should only have ONE material that uses IBeam9.png, and nothing else. In the end, you will have 9 models, each with 1 material:

See how each piece has one material? Also, each material only has one texture.
We're pretty much done with the model! But, how do we figure out which surface is which when we go to import this model into SLADE? Simple! GZDoom works backwards from Blender. Here's the SurfaceSkin numbers:

Yeah I know... it's kind of dumb.
So now Ice Beam.008 is now SurfaceSkin 0, while Ice Beam is SurfaceSkin 8. Get it now?

Great! This model is done! I'll cover weapons another time, but for now, let's pretend this is a model that will be purely for decoration in Doom. select all the Ice Beam pieces by holding Shift and clicking each piece until all 9 are selected, and go to File > Export > GZDoom MD3. Name your model accordingly and save it. Now import the .md3 into SLADE, into your Models/whatever folder. Make sure you import your textures into the Skins folder too.

We're done with Blender for the time being!

MODELDEF and DECORATE

Now it's time to define our model, and make it appear in-game! First thing we should do is open up MODELDEF as text. We're going to enter the following, and change each field to fit your needs:


FrameIndex is very important. With that, we're telling GZDoom what sprite lump name to use in game. Also, FrameIndex will be important later on when we do animations. 

Notice now we're missing SurfaceSkin here... We need to know the parameters of SurfaceSkin so we can implement it correctly. The general use is simple:

SurfaceSkin "model index" "surface index" "path to texture"

The model index number should be the same as what we used for Model up above. It will almost always be 0, unless you are doing a multi model actor. That's for another tutorial though... So make sure your SurfaceSkin entry has a 0 for model index. Surface index is what we really want. Remember our surface numbers from Blender? Those will be used for this part.

Using the picture above, fill in your first SurfaceSkin entry. For example, in Blender, surface 0 uses IBeam8.png, so my entry will be:


Makes sense now doesn't it? Continue to add SurfaceSkin entries until you've added all textures:


Easy! Now we're done with MODELDEF! Now we're going to make a DECORATE entry. So go ahead and create a new folder in your root directory and name it decorate. Inside this folder, make a new entry and name it Models.txt. Now on the root of your .pk3, make a new file and name it DECORATE. Why are we making another Decorate text file? This is purely for tidiness inside our .pk3 file. What we're actually doing is making our Models.txt file globally accessible. That way you can have a folder for your decorate scripts, and keep the root of your .pk3 nice and neat. So in the new DECORATE file you created, add this line:



Now, go ahead and open up Models.txt in your decorate folder. The main point behind all of this is that we are defining an Actor that Doom can use to display the model. That's why FrameIndex is important in MODELDEF. You're going to use whatever you defined for FrameIndex here. My entry looks like this, so add it in:

Simple, but it works. Notice how IBME is the same as what I used in MODELDEF.

Now, there's only one thing left to do: we have to patch IBMEA0 in TEXTURES. So add this to your TEXTURES lump:

Using a TEXTURES lump is outdated. It is not necessary anymore.

Save your .pk3. Now, were ready to see if it works! Go ahead and fire the .pk3 up in GZDoom with ZDL. Open the console with the ~ key and type summon yourdecorateactorhere. You should see your model with the correct textures:

Fancy!
That's all there really is to it. It seems very daunting at first, but it gets much easier once you develop your own workflow. I hope that clears up any confusion to using SurfaceSkin.

Blender: Models with one texture (the Skin way)

Even easier. If you have a model that is only one material, just name the material the same as your .pk3 file path like we did with the SurfaceSkin method. Instead of using the SurfaceSkin property in MODELDEF, just use Skin:

Skin "model index" "path to texture"

Often, you don't even need to have any Skin property if the model only has one material. For example:


This entry will work totally fine, despite not having any property to define Skin... which is totally understandable; GZDoom only needs to find one texture.

That concludes this tutorial. Next tutorial, I'll show how to use 3D models for weapons, how to make simple animations in Blender, and how to make brightmaps for our models!

Comments

  1. Thank you for your help, this information is very useful.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Can we use specular + normalmaps on these models?

    ReplyDelete
    Replies
    1. Yes! https://forum.zdoom.org/viewtopic.php?f=39&t=59473

      Delete
  4. Is there any restrictions like polygon limit, texture size? Also about creating animations for the models, how does one go about it? Like the walk cycle, attack animation, etc. How do we store them for use in the engine? Do we export an fbx,obj?

    Do we create separate objs for every animation? Can you go into detail about these?

    ReplyDelete
    Replies
    1. This will be covered in the next part, but for now, you can do the following:

      -You can make an animation in Blender, and every frame you use can be defined in MODELDEF with FrameIndex. If you have a shooting animation for example that's only 5 frames, you could do something like:

      FrameIndex SHOT A 0 0
      FrameIndex SHOT B 0 1
      FrameIndex SHOT C 0 2
      FrameIndex SHOT D 0 3
      FrameIndex SHOT E 0 4

      The last number represents the frame number in Blender, while the letters represent which frame to use in Doom.

      For making animations in Blender itself, you'll basically want to make frames for the model using Blender's animating tool. You can use keyframes to add some interpolation to speed up the process if it's something simple. There's a lot of good videos on YouTube that could teach you this better. You would also need different objects for each animation I think. It's important to note that each frame you have in your animation corresponds to the FrameIndex number in MODELDEF, as I demonstrated above.

      AFAIK, you can use .obj, but I haven't tested it myself, so I stick with .md3 format. So far I haven't encountered an issue with high-poly stuff with large texturing, although that might be slow in GZDoom if you use a lot of high-poly models.

      Delete
  5. Just a small heads up, you can actually save yourself a bit of effort: https://puu.sh/DqzYE/a6f56404c7.png

    Instead of selecting each individual set of faces and splitting them, you can save time by selecting the entire thing (press A in edit mode for those reading) and choose By Material instead.

    https://puu.sh/DqA1j/21eef1341f.png

    Blender will automatically separate the materials too so no need to go in and clean anything. It's all done for you.

    ReplyDelete
  6. I am struggling with models can you help me out please

    ReplyDelete
    Replies
    1. I have not found anything close to this tutorial for 3d models any way u would contact me and give me a hand understanding this. Shineshazaam@gmail.com

      Delete
  7. Are you going to ever make part II?

    ReplyDelete
  8. Yeah, can we have a part 2? Thisbis already super useful!

    ReplyDelete

Post a Comment

Popular posts from this blog

The How-To Guide To ZDL For GZDoom/Zandronum

The Problem You've seen it or have personally experienced it: You downloaded a cool Doom mod that has multiple files but, you have no idea how to load it. You drag and drop them all onto your GZDoom or Zandronum executable and that seems to work, but something is wrong! The mod isn't loaded correctly, or worse, it failed to load at all! The Solution If you are new to modding Doom or modding in general, this is obviously a huge frustration. You just want to play! One thing I've seen mentioned a lot online is that the mod files aren't in the proper order. A lot of times, a very brief explanation is given, and for a newbie these explanations can be jarring. I won't waste time explaining how to use a batch file or command line to run mods, that's not the scope of this article. Instead, I will show you how to use ZDL, a launcher for Doom. Where do I get ZDL? I personally like lcferrum's fork, which you can find the downloads here . I'm using Windows, so this