- Jan 11, 2009
Creating and Exporting Warcraft MDL models with Blender
Have you ever wanted to create your own awesome 3D models for Warcraft 3? Up until now, the only officially supported tool has been 3ds Max5 with Blizzard's Art Tools plugin, which is problematic considering that this version of 3ds Max is over 15 years old and very hard to get your hands on. Another awesome plugin - NeoDex - has been made by @BlinkBoy to support newer versions of 3ds Max, but this has also been limited to users who are either willing to pay upwards to 3000€ a year, have a student license, or are unscrupulous enough to download it illegally. Other tools like MDLVis and Vertex Modify have helped produce a lot of appreciated content over the years, but creating models in these is tedious since they can't leverage the great variety of tools provided by proper 3D-modeling software.
For this reason, i started developing an MDL exporter plugin for Blender, which although still a work in progress, is now ready to see some use. Blender is an amazing, free, open-source 3D art program with great capabilities, and learning it can be useful for more purposes than just Warcraft modding. I this tutorial i aim to teach you how it works and how you can use it to export cool 3D models for Warcraft 3.
For this tutorial, you will need the following programs:
- Blender MDL Exporter Plugin: khalv/mdl-exporter
- MDLX Converter: MDLX Converter
1. Getting Started
Once you have installed Blender, visit the github page for the MDL exporter. The readme contains most of the instructions covered in this tutorial and is good for quick reference. For now, just click the button that says "Download or Clone" and press "Download Zip".
Next, unzip it, and enter the folder so that you see the three files shown above. Right-click the folder called "export_mdl" and go to Send To>Compressed Folder. Open up Blender, go to File>User Preferences and press "Install Add-On from File..." in the bottom bar.
Select your newly created zip folder and restart Blender. If you go to File>Export, you should now see "Warcraft MDL" as an option. Note that the first time you install the plugin, you will need to activate it from the import/export plugins list by ckecking the box next to it.
By default, Blender uses right click for selection and left click for moving the 3D cursor. Since this is completely counter-intuitive to what you know from any other software, you might want to go to File>User Preferences, hit the "Input" tab, and set "Select With" to "Left Click".
2. Creating your model
Teaching all the aspects of creating a model in Blender is beyond the scope of this tutorial, but my recommendation is to check out BlenderGuru on youtube and start from there:
My plan is to later create a tutorial on 3D modeling techniques as well. For this tutorial, I'll make a simple wine glass without going too much in details on how to use the Blender UI - therefore i recommend that you at least watch the first two episodes of the series i linked before you start. If you already have a model which you want to export, you can skip this part.
To start off, press the A key to select everything, then press X for delete, and click to confirm. This leaves us with an empty scene. Next, hit Shift+A to open the "Create" menu, go into "Mesh" and select "Cylinder". Our cylinder will appear at the current location of the 3D cursor, which unless you have accidentally misclicked should be at the center. In the bottom left corner of your screen, there's now a small window where you can configure the parameters of our cylinder. Here, I'll set it to have 8 segments, a radius of 0.05 and a height of 0.2. Set "Cap Fill Type" to "Nothing" to get an empty tube. It can be helpful to configure Blender to use real-world units, you can find instructions on how to do so here.
To make it easier to create smooth shapes, we will be using a Subdivision Surface modifier, which essentially smooths the mesh while adding more polygons. Press the tab which looks like a wrench in the menu to the right, press "Add Modifier", and select "Subdivision Surface". You can also just press CTRL+1 to add it automatically. You will notice how the cylinder looks more smooth. To make it even smoother, you can press the little button which says "Smooth" in the middle of the left toolbar, under "Shading" - this makes the model look smooth by averaging the normals without actually adding any more geometry. You can also set an angle threshold for the smoothing by pressing "Auto Smooth" in the "Object Data" tab (which looks like a triangle).
With our cylinder selected, hit TAB to toggle edit mode. Press A to deselect everything, and then CTRL+R to enter "loop cut" mode. If you hold your cursor over the cylinder, you will now see a purple line dividing it. As you press, this line will become yellow and follow your cursor as you slide up and down. Move it to where you want and click again to place it. With the vertices selected, you can now scale them by pressing the S key and moving your cursor around. If you ever want to select the same loop again, you can hold the Alt key while clicking one of the edges to select the whole loop. Remember that the A key deselects everything (or selects everything, if nothing is selected). Put down some loops and scale them until you have something which looks like a glass. You can also press G (for "Grab") to move vertices around, and also press X, Y or Z to lock movement to that axis. Notice how the Subdivision Surface modifier smooths out the shape - if this creates smoothing where you don't want it, try adding an extra cut close to the edge you wish to preserve.
- CTRL+RMB+DRAG: Paint a selection loop with your cursor. This is great for precision.
- C: Circle select. Use the scroll wheel to shrink/grow the circle, and drag with LMB to "paint" selection with it. Press RMB to stop selecting.
- B: Box select, lets you drag a box.
- SHIFT+LMB: Add to selection.
- ALT+LMB: Select loop.
And now we are pretty much done! If you want to create an inside for the glass, you can select the top loop (again, by ALT+clicking it) and press E and S to extrude it and scale inwards. Pressing F while a loop is selected will seal it off with a polygon, so you can use this to fill the bottom. Another final thing we might want to do is to move the model so that the base is at the origin point - do this by pressing G followed by Z (to lock to Z axis), move it up, and then click to place.
Next, we need to map how the texture should be applied to the model in 2D space - think of it as unraveling a paper model and flattening it to fit onto a piece of paper. This process is called "Unwrapping".
Similar to how clothes have seams where the fabric is cut, we can add seams to define where to cut up our model when unwrapping it. In our case, this is as simple as ALT-clicking along one of the vertical lines of our glass and press CTRL+E (E is for Edge Options), and select "Mark as Seam" from the menu. If you have sealed off the inside and added a bottom cap in the previous step, you will also need to mark the loop around the polygon as a seam. Seams are marked with red.
Next, press A two times so that you have your entire mesh selected. Now press U and select Unwrap. It may not look as if anything has happened - but that's just because what we need to see is in a different UI screen. Notice the little cube icon at the bottom left of your window? Click it to open a drop-down menu with different screens, and select "UV/Image Editor" (hotkey for this is Shift+F10). Now you see how it looks when the model is unfolded! To get more overview, you can pull the little corner at the top left of the window to split it into two and have one as the UV editor and one as the model (you can press T and N in the UV editor window to toggle off both the toolbars if it gets cluttered). In the image editor, you can press the button which says "Open" to select an image to use as background - this way we can move the vertices around to match the texture we want to use. In this case, we will be using a plain white texture, so we won't go into the details of this.
Finally, hit TAB again to toggle back into object mode.
L - Select Linked
G - Grab
S - Scale
R - Rotate
Y - Separate
G - Grab
S - Scale
R - Rotate
Y - Separate
3. Material setup
In order to export properly, our model needs a material. Go to the Material tab in the properties window and press the button which says "New". At the bottom of the panel, some settings will appear labeled "MDL Material Settings". MDL Materials consist of one or several texture layers, which can be blended together for different effects. To create one, click on the "+" button next to the empty box which says "Layers". The property inspector below displays the properties of the currently selected layer - here, we want to enter "Textures\white.blp" as the path, "Additive" as filter mode, and make sure that "Two Sided" is checked. That's all we need for our basic glass material!
When you make your own models, you'll probably want to use other textures than "white.blp" - you can then use Magos Model Editor's MPQ browser to browse through and preview all the textures which exist in the game files. When right-clicking on a texture in the list, you can choose to "copy path to clipboard" and paste the path into the texture field in Blender.
You might notice that there's an option called "Texture Type" for the material - here you can choose whether to use an image as texture, a team color, or a replaceable texture (such as a cliff or tree texture). To add team color to a unit model, you create two layers - one bottom layer set to "Team Color", and one top layer with filter mode set to "Blend" and a texture path of your choice - the team color will then shine through where the texture is transparent (determined by its alpha channel). Note that the layer list goes from bottom to top, so layers at the top of the list are rendered under those below them in the list.
Some models, such as the Water Elemental, use texture animations to make it seem as if the water is moving across its body. The exporter allows you to make texture animations by adding a Mapping node to the node graph, naming it the same as your layer, and then animating its values. This way you can preview the animation by feeding it into the texture slot of your actual material (MDL materials are just data containers and won't affect how the mesh is rendered in blender). To edit the shader graph, open the graph editor in a window (hotkey: Shift+F3) and press the button which says "Use Nodes" in the material panel. You can create nodes by pressing Shift+A. You can rename nodes by selecting them and typing in a name in the panel to the left of the graph viewport.
4. Animated color tint
Warcraft 3 materials can have a tint which is applied as a vertex color to the whole mesh. In Blender, we can get the same effect by animating the "Object Color" of our glass. Our color won't actually be changing anything during the animation - but for the exporter to recognize it as a color tint, we need to apply it as an animation. First of all, in order to export animations, we need to define their start and end times. To do this, we mouse over the timeline at the bottom, and right click in it (or left, depending on your mouse settings) to move the cursor. Set it to frame 1 (or 0, whichever you prefer) and press M to place a timeline marker. Next, press CTRL+M to rename it - let's just name it "Stand". To mark the end of this animation, we move the timeline cursor to frame 100 and repeat the same process again - making sure to also name this one "Stand" (each animation NEEDS a start and end frame or the exporter will report an error). If you ever want to have multiple sequences, you can just place another pair of frames somewhere else in the timeline and name them something else - as long as they don't overlap with each other. Note that although the exporter will also export rotation, scale, and translation animations, this is currently buggy and might not always present the correct result. Most other properties can be animated, though - see the readme for more info.
The next step is to make our actual animation. To do this, go to the "Object" tab in the right toolbar (the icon looks like an orange box) and find a field which says "Object Color". We will change this field to be a light blue color. Then, with the timeline cursor at frame 1, mouse over the color field and hit I on your keyboard to insert a keyframe. You will notice that the color field now gets a yellow border - this means that its values are keyed at this frame. Move the timeline cursor to frame 100 (or whatever your end frame is) and repeat the process. Note that ALL animations need to have start and end frames to display properly - however, the exporter currently won't notify you of these are missing, so it's your responsibility to remember to add these.
On the topic of animations - if you ever need to animate whether you want to show or hide an object, you can easily do this by animating the render visibility. You do this by mousing over the little camera icon you see next to the object in the outliner (top right corner) - click the camera to toggle on/off, and press I while mousing over it to set a keyframe. It is also possible to create a custom property called "visibility" and render its value.
NOTE: As of the current version, animating render visibility is bugged, in the sense that the values are inverted. In other words, keying render visibility to "on" will result in the geoset being hidden, and vice versa. This will be fixed soon.
When you feel done with the model, go to File>Export>Warcraft MDL and save it. Note that you have some options in the left panel:
Selected objects: if this box is checked, only selected objects will be exported.
Forward/Up: This is used to rotate the model as it is exported to correct for the different conventions of Warcraft 3 and Blender. By default, it should make it so that the forward view in Blender corresponds to the forward direction of Warcraft 3 (you can set the viewport to view "Forward" perspective by pressing 1 on your num pad).
Scale: This is used to apply a global scale to all objects in the scene. In Blender, one unit corresponds to one meter, while in Warcraft, it is a much smaller distance. To correct for this, the default value is set to 60, which is roughly half the height of Jaina (my reference), so this means that if you model a character to be 2 meters tall in Blender it will become about as tall as her (which is probably not her real height, but it's a nice round number).
Normally, there's no need to change these values, and it should be safe to simply export. If you encounter any errors in this process, please write them in the comments and i will try to address them. Finally, convert your model to MDX using MDLX for a smaller file size. Now you can admire your model in a MDL/X viewing software such as Magos Model Editor!
So... that's it! Have fun! I will update this tutorial further on as i update the plugin, make sure to keep the exported updated - you do this simply by checking if there's recent activity on the github page, and if so, just install it again using the steps described. Don't hesitate to ask questions in the comments or by PM.