Unity Virtual Reality Projects
上QQ阅读APP看书,第一时间看更新

UV Texture image

Let's paint the faces of our cube. 3D computer models in Unity are defined by meshes—a set of Vector3 points connected with edges, forming triangular-shaped facets. When building a model in Blender, you can unwrap a mesh into a flattened 2D configuration to define the mapping of texture pixels to the corresponding areas on the mesh surface (UV coordinates). The result is called a UV Texture image.

We will create a UV Texture image for our cube, as follows:

  1. Go into Edit Mode using the Interaction Mode selector in the bottom Header bar.
  2. Select all (press the A key on the keyboard twice) to make sure that all the faces are selected.
  3. In the left Tool Shelf panel, select the Shading/UVs tab.
  4. Under UV Mapping click on Unwrap, select Smart UV Project from the drop-down list, accept the default values, and click on OK (the result, shown in the following screenshot, also shows what the unwrapped cube looks like).
  5. Now, go into the Texture Paint mode using the Interaction Mode selector in the bottom Header bar again.
  6. We need to define a paint slot for our material. Click on Add Paint Slot, select Diffuse Color, name it CubeFaces, and press OK.

We can now start painting directly on the cube. Paint the front face first, as follows:

  1. Make a smaller brush. In the left Tool Shelf panel, in the Tools tab, navigate to Brush | Radius and enter 8 px.
  2. It may be easier to work in an orthographic view. From the menu bar at the bottom, navigate to View | View Persp/Ortho.
  3. Then, navigate to View | Front.
  4. You can zoom in or out using the mouse scroll wheel if needed.
  5. With your best handwriting, write the word Front using the left-click of the mouse and draw.
  6. Now, the back face.
  7. From the menu bar at the bottom, navigate to View | Back and select this face with a right-click.
  8. With your best handwriting, write Back.

Repeat the above process for the left, right, top, and bottom faces. If at some point it's not painting, make sure that there's a current face selected. Try right-clicking on the face to reselect it. The result should look something like this (shown side by side both in the 3D View editor with an orthographic perspective and in the UV/Image Editor):

Now, we need to save the texture image and set up its properties, as follows:

  1. Change the current Editor Type to UV/Image Editor using the selector on the far left of the Header at the bottom of the 3D View editor.
  2. Click on the Browse Image to be linked selector icon (just towards the left of the + icon) and choose CubeFaces from the list.
  3. The Image menu item on the menu bar at the bottom now has an asterisk (Image*) indicating that there's an unsaved image. Click on it, select Save As Image, and save it as CubeFaces.png. Use a folder outside the Unity project.
  1. On the right-hand side, in the Properties editor panel, find the long row of icons in its Header and select the Texture one (third from the last.) It may be hidden if the panel isn't wide enough; you can scroll down with your mouse to show it, as shown in the following screenshot:

  2. Within the Texture properties, change Type to Image or Movie.
  3. Then, in the Image group of properties, click on the Browse Image to be Linked selector icon (as shown in the following screenshot) and choose CubeFaces:

  4. You should see the labeled faces texture image in the Preview window.

Good! Let's save the Blender model, as follows:

  1. Select File from the top main menu bar in the Info editor and click on Save (or press Ctrl + S).
  2. Use the same folder as the one where you saved the texture image.
  3. Name it UprightCube.blend and click on Save Blender File.

We should now have two files in a folder, UprightCube.blend and CubeFaces.png. I use a folder named Models/ in the root of my Unity project.

We recommend you then export the model as FBX format. This is a standard format for Unity. (Unity can import Blend files but may require you always have Blender installed on the same system). Use File | Export | FBX to save the .fbx version.

Wow, that was a lot. Don't worry if you didn't get it all. Blender can be daunting. However, Unity needs models. You can always download someone else's models from the Unity Asset Store and other 3D model sharing sites, or you can learn to make your own. Haha! Seriously, it's a good thing to start to learn. Actually, with VR, it's gotten a lot easier as we'll show you later in this chapter.