UV coordinates in Blender

From PioneerWiki
Revision as of 08:10, 21 January 2013 by Mikehgentry (talk | contribs)
Jump to: navigation, search

This page is intended for a crash course in UV coordinates in Blender.

Links to good tutorials are welcome, as are tips from veterans, but the plan is to make a solid run-through for an absolute beginner, so if you're dealing with advanced topics likely to confuse a beginner please either leave them at the end, or perhaps consider a different page.

Tested on Blender 2.65

TFM: http://wiki.blender.org/index.php/Doc:2.6/Manual

A tutorial which isn't particularly directly applicable, but gives you a sense of what we're aiming for: http://www.youtube.com/watch?v=1nwEcWGkWOM&t=3m30s

What is UV unwrapping?

Basically we're mapping a 2D texture onto a 3D mesh. Think of a world map's projection (like unpeeling an orange), or unfolding a cube to make a 2D surface.

Every XYZ point on the surface of our mesh must be mapped to a UV point on our texture. Fortunately we don't have to do it point by point - the vertices in XYZ space have corresponding vertices in UV space, and Blender / Pioneer interpolate the surface in between for us.

Even easier, Blender has methods for 'unwrapping' a mesh or part of a mesh, by projecting groups of faces onto the map algorithmically. By repeated selective unwrappings, the computer does most of the work, and we just fine tune it afterwards.

Objectives

The main things you are trying to balance when unwrapping:

  • Size
    • Maximise use of texture space: You want to make your texture files as small as possible to avoid straining the game engine. Pack polygons into the map as tightly as you can, using space efficiently. A single part of the texture can be mapped to multiple polygons, and any faces internal to the model (which should be avoided where possible to prevent z-buffer issues) can be shrunk to a point.
    • Optimise detail: Parts of the mesh probably need more detail than others. The parts that should be highly detailed need more texture space, so should be made larger when unwrapped.
  • Control distortion: You can distort polygons on the UV map for effect, or just to pack them in tighter, but assume to begin with that you want to minimise distortion. If your polygon is a square on the mesh, it should be square on the UV map.
  • Alignment / orientation: Where texture detail crosses contiguous faces, it makes it much easier to line it up correctly if the faces are contiguous on the UV map too. For textures with 'grain' you may need to rotate parts of the map for it to look right.

Set up Blender

  • Select 'UV Editing' screen layout using the widget in the top left which probably says 'Default'

The screen is divided in two, the 3D view on the right, the UV map on the left.

  • Select 'New' in the widget below the UV map. Choose your texture's size, which must be a power of 2. For 'Generated type' it can be helpful to select 'UV Grid' - this creates a 'fake' texture for you, so you can see how it maps to the mesh in the 3D window. Hit OK.
  • Switch the 3D view's 'Viewport Shading' mode to 'Texture'. Your mesh will turn white, because we haven't mapped anything to it yet...

Basic method

First we're going to unwrap everything and place it off to the side of the texture, so we can see which faces we are yet to unwrap properly.

  • Select your mesh in the 3D view. Tab to edit mode. Ctrl-tab to face select mode. Hit 'a' key until all faces are selected.
  • Hit 'u' key and choose 'Unwrap'. All faces will be mapped to the UV space - if you're on 'Texture' viewport shading mode in the 3D view you'll see your mesh covered in the grid texture.
  • Hit 'g' key in the UV view on the left. Move all the polygons to one side, so they're a decent way away from the grid. This gives us our pool of 'not done yet' faces (n.b. the mesh will still display the grid texture on it in the 3D view because the texture actually repeats itself. Don't worry about that - we're just clearing the faces out of the way in the UV view)

Now we selectively unwrap and pack sections of the model. Choose a group of faces that are logically connected. Either they are going to look identical (perhaps windows, or engine outlet surfaces), or you're going to want them joined to each other in the UV map because they share edges, and will have a texture running over these common edges.

  • Select all the faces you want to unwrap together in the 3D view (shift right click works, as do 'b' for box or 'c' for circle select) - it might help to turn 'Clipped with depth buffer' on. Hit 'u', then choose an unwrapping method - you'll have to experiment to work out which one works best for the geometry you're dealing with.
  • Move the polygons around in the UV map with 'g', 's' and 'r' until they're roughly where you want them. Switch to face or vertex mode to pack them together as tightly as possible, superimposing them if you want them to share texture. If you have multiple vertices you want at the same spot, select them, hit 'w' twice to weld them together, then shift-s and select snap to pixel.

Make sure 'Keep UV and edit mode mesh selection in sync' is on, then box select the 'not done yet' faces we moved aside earlier in the UV view, to highlight all the parts you still have to do in the 3D view. Keep picking groups of logically connected faces, unwrapping and packing them until you're done.

Using seams

I don't understand seams, someone else will have to write this bit :-)

Exporting the UV map to Gimp and importing the texture to the model

In the 'UVs' menu in the bottom left, choose 'Export UV layout'. Load the file in Gimp and draw your texture, using the UV map as a stencil. Once done, back to Blender's Default screen layout, select your mesh, then on the panel on the right select 'Texture'. Set Type to 'Image or Movie' and Image to your file.

Tips

  • If you've thoroughly stuffed it up and want to start again, switch to 'Default' screen layout, select your mesh, and switch the panel on the right to 'Object Data'. Hit the minus sign next to UVMap to delete the map entirely.
  • Sometimes if you move one vertex on the UV map it'll move the corresponding vertices on other faces. Infuriating, but if you select all vertices with 'a' then switch 'Keep UV and edit mode mesh selection in sync' off it lets you move then individually. I don't really understand why this works at all, or if there's a better method...
  • Easiest way to flip a polygon is to hit 's' for scale then 'x' or 'y' to choose your axis, then type '-1'.
  • If you want to get the finished parts out of the way in the 3D view, select them (easiest to box select on the UV map with sync on), then hit 'h' to make them invisible (alt-h brings them back).


Advanced techniques