teaching machines

CS 491 Lecture 6 – UV Mapping

February 11, 2016 by . Filed under gamedev3, lectures, spring 2016.

TODO

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:

  1. selecting geometry
  2. projecting 3D surfaces onto 2D

We can alleviate the selecting faces problem in a few ways. Try each of these out:

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:

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.