Posted 05/07/2014 16:18:19 in Blendering for Unity
Updated 08/20/2017 19:15:34
UV mapping is the process of telling whatever is rendering your model where to get its texture data. A simple way to look at it is to imagine taking a cardboard box and cutting and unfolding (or "unwrapping") it into a flat shape. When you have a more complex shape like we do with our character, you want to make sure it unwraps into a usable form. You can do this in Blender by marking "seams," which would be the edges that you cut in the cardboard box analogy. The Blender wiki has a good but lengthy explanation of this process, but here you'll find the simple and condensed way that I do it.
First off, you'll want to jump back into Edit Mode (Tab) and make sure that Edge Selection is enabled (Ctrl-Tab). Open up the "Shading/UVs" tab in the Tools panel on the left (press T to open the panel if you closed it earlier).
We're going to create a "UV Island" for the face of our character. A UV Island is a completely separated area of the model, and it's useful to split things up. For example, in Sail, the sail in the boat model was a separate UV island from the mast, even though they resided on the same texture. This should make more sense when you see the final UV map.
Select the edges around the face of our character, and click Mark Seams. That's all there is to it! You'll notice the edges become red, indicating that they are now marked.
Next we'll create a seam around the center of the character so that the round shape doesn't end up distorted too badly. Remember the edge loop concept in the modeling part of this tutorial? A useful feature in Blender is the ability to select an edge loop, which is just what we need right now! Select two of the edges along the central edge loop. Now open up the Select menu at the bottom of the viewport frame, and click "Select Edge Loop." Bam! The whole edge loop is now selected, and you just avoided manually clicking each and every edge around the model! Click Mark Seam to mark it. Note: A useful shortcut to avoid having to go through the "Select" menu is to simply Alt + Right Click on an edge.
We don't want the face UV island to be split into two, so go ahead and select the marked edges in the middle of the face and click "Clear Seams" in the Tools panel. Another way to have dealt with that problem would have been to deselect those edges before marking the edge loop.
We can create some UV islands for the legs as well. Try to visualize how it will unwrap when you mark the seams.
Now that all the seams are marked, we're ready to unwrap the model! Pull out a second frame from the left (remember, you can click the triangular icon at the bottom left of the 3D viewport and drag it to create a new frame) and make it about the same size as the viewport. You may want to use N to close the number panel in the right viewport to give yourself a bit more viewing room.
Click on the Window Type Selector in the bottom left of the left viewport, and change it to the Image/UV Editor. Now that we'll be able to see our UV map, select all of the edges of your model (remember that keyboard shortcuts work for the frame that your mouse is in, so hover over the 3D viewport!) and click "Unwrap" in the tools panel. Select the basic Unwrap option, and you should see a flattened version of your character in the UV frame!
I want to quickly mention a technique that works pretty well for more geometrically-shaped objects. Instead of manually marking seams, you can simply select all and choose the "Smart UV Unwrap" option. Blender will make its own seams based on the angles of the edges! Another thing to keep in mind is that Blender will only unwrap the faces that you have selected, so make sure you select all before unwrapping (unless you plan on using multiple textures for your object, but that's beyond the scope of this tutorial).
Now that the model is unwrapped, you can select, move, rotate, and scale the UV islands just as you can with elements in the 3D viewport. The selection mode system in the UV frame is similar to the 3D viewport, allowing you to select vertexes, edges, faces, and, additionally, entire UV islands. Set the mode to Island, and move the islands around until they're where you want them (the G, R, and S shortcuts will all work the same in this window, along with the X and Y axis lock shortcuts). Middle Click will pan the view around, and the Mouse Wheel will zoom you in and out.
I put the UV islands for the legs on top of each other, which is a pretty handy way to save space when you have parts of the model that will use the same texturing. Just make sure to scale and rotate so that the vertices are as close to the corresponding vertices on the opposite leg as possible!
We can check how this mapping will actually look on our model by having Blender create a test color map for us. Click on "New Image," and choose Color Grid. You'll see it pop up in the UV screen, but our model in the 3D viewport won't show it yet. In the 3D view header, you can change the display mode to Textured and it will show up.
Hooray! Our model is ready to be textured! It's useful to look around for any extreme stretching and to use the color coding and letter/number grid to figure out which UV islands correspond to where on your model. The way mine turned out, there was more stretching in the legs than I would've wanted, but that's fine for now since we're planning on making them a solid color anyway. To fix it, you could play around with the shapes of the leg islands, or even re-mark those seams and repeat the unwrapping process.
The last thing to do is to export the UV map so that we can use it in our respective image editors of choice! In the UV frame, open up the UV menu and select Export UV to save it! (I called mine characterUV.png). Typically, you'll want to make it extremely large (I did 2048*2048), since Unity will scale down your color maps based on the quality settings in your game.
One last note: if you want to put multiple models on the same texture (like all the pieces of a house, or several small creatures), you can accomplish this by leaving room for the other models in your UV map. The color grid makes this pretty easy; you can segment off an area (e.g. A1-C4) and put all the UV islands for a particular model there and leave that space blank when you unwrap other models. You can then layer the exported UV .png files in your image editor to create the actual texture.