CS 491 Lecture 6 – UV Mapping
TODO
- For your first half-homework, research proportional editing and texture painting in Blender. Using both these tools, model a ripe banana. Post your result on the course blog under categories
gamedev3
,spring 2016
, andgallery
before Febuary 18.
Lab
Let’s get the cannon colorful and moving today!
Finish Cannon
If you didn’t finish your cannon from last lab, especially the wheels, do so quickly.
Wood Texture
Find a wood grain texture online somewhere. Look for flat lighting (we don’t want shadows or highlights in our albedo textures; we’ll compute those). Look for an antique aesthetic. Don’t get too small a resolution. Save it in the same directory as your cannon model.
Split the Blender 3D window in two by dragging on the diagonal lines on the top-right or bottom-left of the window. In the Editor Type menu at the bottom left of one the windows, choose UV/Image Editor. Click Image / New Image and load the wood grain texture.
Blender doesn’t store textures with the model. Instead, it records their relative paths. If you ever copy a model file, you will need to include the images as well and store them in the same relatively location.
Selecting
Now it’s time to unwrap the wheel and axle. (Don’t bother texturing the barrel. We’ll just use a material in Unity for it.)
UV unwrapping presents two challenges:
- selecting geometry
- projecting 3D surfaces onto 2D
We can alleviate the selecting faces problem in a few ways. Try each of these out:
- Use B to box select a region. This often works best in an orthographic view. To get at certain geometry, you might need to hide other things. You can hide complete objects in the hierarchy—just click on the eye-con. You can hide modifier-generated geometry by clicking on the modifier’s eye-con. You can also toggle between hiding and unhiding selected faces using Mesh / Show/Hide.
- Use C to paint a selection. Hit
Escape
to cancel orEnter
to commit your selection. - Select one face in a connected region that you want to select. Hit
Control-L
to select all the other connected faces. I think of this as L being short for an island of faces. - Select a face like the others you want to select. In the menu, choose Select / Select Similar to automatically grow the selection based on some similarity criterion. On the wheel, I had good success with Perimeter.
- Once you’ve got a selection made, you can save it. In the Properties window, click on the Data panel (which is to the right of the Modifiers panel). In Vertex Groups, click on the + button to add a new group. Click Assign to add the selected vertices to the group. At any later time, click Select to restore the selection.
Before unwrapping, go ahead and save a few vertex groups: one for each wall of the outer wheel, one for each spoke, one for the outer wall of the hub, and one for the axle.
Unwrap
Now, using your saved vertex groups, let’s unwrap. Go ahead and hit U
to start unwrapping things, keeping these things in mind:
- Blender doesn’t automatically show the textures in the 3D view. Hit N to open the Numbers panel, find Shading, select GLSL as the shading type, and checked Textured Solid.
- All unwrapping does is assign a 2D texture coordinate at each unwrapped vertex. This 2D coordinate is in a very general [0, 1] coordinate space, representing a proportional index into an image. We often have to tell Blender which image to apply the proportion to get the color data to appear on our model. In the UV/Image Editor, click on the image icon to reselect the wood grain image.
- Unwrapping tries to maintain continuity as much as possible, but this usually leads to distortion. Alleviate this problem by adding seams where discontinuities might naturally occur. Select the discontinuous edge and hit
Control-E
/ Mark Seam. - Use
r
,g
, ands
in the UV/Image Editor to rotate, translate, and scale the projected faces.
Import in Unity
Once you’re satisfied with the the texturing, save and drag your Blender file into the assets of a Unity project. Explore the structure that got imported. Notice how it maintains your object organization and even brings in some unnecessary things (like Spoke Pivot).
Restoring Texture
Preview the wheel/axle object. It should be missing your texture, as we haven’t imported that yet. Drag your wood texture into the Assets. Find the imported materials, and drag the wood texture into the albedo slot.
Add a dark material to the barrel.
Manipulating the Cannon
Drag the entire cannon structure into the scene. Add a script to the wheel and in the Update method, listen for user input on the left/right cursor keys with a line like this:
float oomph = Input.GetAxis("Horizontal");
Using the game object’s transform
component, rotate the wheels. Search the Unity API for a handy method.
Do something similar for the barrel, listen for the up/down cursor keys and rotate the barrel around its heavy end.