ZModeler2 Lesson#1: UV-Mapping. UV-Remapper.

UV-Mapping.

We have finally reached this mistery "UV" and "UV-Mapping" thing. First of all, let me explain, what "UV" is. This is surely not an "ultraviolet". U and V are vertex coordinates, just like X, Y and Z, but these coordinates specify where vertex is located on texture. Image on the right shows how U and V coordinates goes relative to texture. Assume, you have the following texture:

And assume you have created simple square in front view. How can texture appear on this square? Only like it's shown below - four colored squares, doesn't it?

The answer is "No, it can be mapped in almost any fashion!". Image on the right shows how square's vertices can be U-V mapped onto square texture. Take a look at mapping (the left column) and how texture appears on the mesh (right column). Notice that mapping can be scaled/stratched, rotated and even go out of texture boundary.

So, UV-mapping is the process of applying a texture image onto mesh object. This can be considered as "skining", "stratching texture over the mesh", but the most precise description is "mapping", since underlying process involves mapping of the mesh (or parts of the mesh) onto texture, but not visa versa.

The mapping as a process is "assigning image texture to a portion of a mesh". Therefore, if you have a texture for an object, you MUST map it to the mesh, and do it correctly, so that it looks good. Most of the time, textures are not just untouched photos of whatever it is that you're modeling. Instead, they are distorted, retouched, airbrushed, groups of pictures in one image. The beauty of mapping is that you can assign different parts of an image to different parts of a mesh. For example, you can have side, front, and back views of a car, all in different sections of the same image, and then you can assign, or map, the various parts of the car onto corresponding parts of that image. In fact, one of the virtues of a good texture is that it makes the most use of the space on the canvas, and fits as many parts of the car on one image as is possible, all at the highest possible resolution.

Internally, when UV-mapping you assign each 3D vertex to a certain location on texture. This location is it's U,V coordinates and they are stored within the mesh vertices. This pair of U,V is a single uv channel and in some cases mesh can use (or have to use) more than one uv channel. But one channel is the most common case.

Since UV's are stored on a vertex-basis in the mesh and don't bind to texture they were mapped, texture replacement is widly used by games and appears as variouse "skins" for the same mesh.

Finally, U,V coordinates stored in relative coordinates: zero for U is a left side of texture, one for U is the right side of texture. So, U and V do not depend on image size (whether it's 256x256, 512x128 or any other size) - you can map on higher-detailed texture and use lower-detailed texture with result file - it's all your choice.

Mapping areas on the mesh.

When mapping certain areas of the mesh onto texture there could (and will) be a case when neighbour ares on the mesh are mapped to completely different locations on texture. For example, the line where hood goes along the wings (left or right). In this case the hood is mapped to one area of texture (e.g. to an image from top) and wings are mapped to another area (to a side image). But when understanding the internal concept (that uv is assigned to the vertices) you will clearly figure out that mesh splitting is required. Been more precise, you need to slice the areas-boundary edge, so each vertex on mapping boundary is duplicated: one for hood and one for wing. To understand what acutally happens in this case I recommend to apply detach tool to the hood, move it away, uv-map it, uv-map side wings and then move the hood to it's original position. This can be done if the chapter below confuses you on this subject. When this areas-boundary issue will be clear to you, detach tool will still be used, but you will not require to detach mesh into stand-alone object and/or move it away.

UV-Mapping BMW.

We shall use BMW mesh from basics lessons. You can use Files\les1_01.z3d file. It contains only one side of the car - it doesn't matter currently. Also, I've prepared texture for BMW too. It is in Files\texture.tga file:

First of all, you need to create a material for BMW and load texture onto it. Open materials editor and create material (I gave "BMW Skin" name to it). Then load texture onto this material. You should have a textured material like on the image.

Mapping side.

You can start from Files\les1_02.z3d file. The first step before UV mapping is to assign proper material to polygons. Since whole BMW will be mapped onto one material, we can assign "BMW Skin" to the whole object. While in objects level, right-click on BMW object and pick "Properties" in context menu. Then expand Mesh\Polygons branch and change Material property to BMW Skin. Then click OK and whole BMW will turn to dark green color. That's because there is no UV-mapping yet, and all vertices use texture's upper-left pixel color, that's why I always paint a small square (8x8 pixels) in upper-left corner of texture to any bright color, so I can see non-mapped areas of the mesh.

If not whole car has turned into single color, or if texture appeared on certain areas of the mesh - don't be afraid, it's ok. The next step will elleminate this.

We shall now reset whole mapping to start uv-mapping from a "blank list". Since UV-mapping is vertex-based, switch to vertices level and select all vertices in the mesh. Switch to selected mode and right-click in viewport. Then pick Mapping\Edit UV in context menu. Dialog box will popup where the following options should be set:

By pressing OK you will remove mapping from all selected vertices. From this point on we shall create new UV-mapping.

You are still on vertices level in selected mode. Right-click in Left viewport and pick Mapping\Edit UV in context menu again and take a look at the image below:

Here you should pay attention to the areas I've highlighted with red.

  • First of all, it's mode: Create/Edit UV. In this mode, the tool will Generate UV mapping (assing UV for each vertex selected).
  • Second, From Viewport XY - is a "new mapping creation mode". This means that mesh layout in current viewport will be used to generate mapping. I've clicked in Left view when applying the tool, so I expect mapping to be generated the way the mesh lays in the left view.
  • Already mapped vertices behaviour: Generate New means that previouse UV-mapping of vertices (if available) will be lost and new mapping will be generated.

    You can click OK button to see a noticeable changes in 3D view. Deselect all vertices, switch to objects level and switch selected mode. Of cause newly generated mapping is not what we need - it requires editing.

    Edit UV has done it's job already, so the next step is to open UVMapper.

    The UVMapper view.

    The UVMapper is a specific kind of view where you can edit UVMapping for the mesh. This viewport works with the mesh which was generated by Edit UV tool. This mesh is a so-called Mapping-object and it is bind to original mesh. When you edit this mapping object, an UV-mapping of original object changes.

    Change any viewport ("Left" for example) to UVMapper. Guess what? There is nothing in UVMapper viewport. This is quite normal and you have to choose what you are going to modify in this viewport before anything will appear. First of all you need to select which material/texture mapping you are about to modify. Click on a Material button and select "BMW Skin" in a pop-up list, like on the right image. Texture should appear in UVMapper. In most of cases the mesh will appear too, but if it doesn't, click on an Objects button and place a checkmark near desired object(s). Then press Esc to hide the list. On the left image two viewports are shown: UVMapper and Left view. Notice that mesh in UVMapper looks the same way it looks in Left view (where I've applied the Edit UV tool). You can pick a Modify\Move tool and move the mesh in UVMapper. At the same time you can look into 3D view to see what changes when you move mapping-object. Don't be afraid to scale/rotate this mesh - it will no way distort your original mesh, only uv-mapping is affected.

    I've applied Modify\FFD tool with (2-X, 2-Y and 1-Z steps). With FFD you can quickly shape the mesh in UV view over texture. Assume that side photo used for texture was taken not exactly from side, but with some angle - it will take ages to place UV-object over such a texture. In my case - it almost match. Since it's just an example, i don't pay attention to details. In a real project I would apply FFD with more steps and additionally I would apply FFD to some areas of the mesh to shape them. In a worse case you can switch to vertices level and adjust vertines precisely. Also, don't be afraid of the mesh going out of texture boundary - it's quite common situation when you start mapping. Both front and rear will get new mapping later.

    Make sure to delete FFD if you have used one. Change UVMapper back to original view when you've done mapping. Note that when you hide/close the last UVMapper viewport, a mapping-object is removed. If you wish to return to UVMapping again, you can use Edit UV tool to Restore mapping.

    "Split and uv-map" approach. "Area" mapping.

    As it was stated before, you will need to map car parts to certain areas on texture. I'll show how to map front of the car to front texture. First of all, you should remember the vertex-mapping concept: some vertices (those that near the hood, headlight and some other) are already mapped and this mapping should not be distorted, but other vertices in front part need new mapping to be generated.

    Switch to polygons level and select the polygons you want to map. I selected these polygons. Image below shows that I temporary switched texture off, to show which polygons are in a question:

    You need to separate these polygons from the rest of the mesh, so they use their own vertices and don't share these vertices (and their mapping). This can be done with a single apply of Modify\Submesh\Detach tool. Locate it in commands bar and expand it's options box. Set the options like one the image. They are:

  • To New Object: OFF. We don't need to detach to a new object.
  • Keep Original: OFF. This will not leave original polygons. Otherwise, you'll get a duplicate polygons.
  • Enable Drag: OFF. We don't need to drag/move detached polygons, they need to stay where they are.

    Make sure SELECTED MODE is ON and click once in the view. Nothing (visually) will happen, but these polygons are now separated from the rest of the body. Keep selected mode ON and switch from polygons to vertices level (by pressing '1' hotkey). You should see vertices selected and these vertices show, that the area you've detached, is now separate from the rest of object:
    Once vertices are separated, you can apply Edit UV tool in Front view to selected vertices, but make sure to select Generate New option in Edit UV options box. Then, exactly like you did with the whole body, the front area is mapped. The front photo used for texture was surely out of place, so I had to modify uv-mapping object in uv view on vertex level. It's not perfect indeed, but fit our needs currently.

    Rear area is mapped exactly the same way as the front: detach and uv-map. Image on the right is a result. I used vertex-level editing of UV-mapping too. Nevertheless there are some issues on the rear bumper - the level of grey shade differs on rear and side areas of texture. This is a subject of how accurate texture is. Finally, map bottom of the car.

    The result is in Files\les1_03.z3d file.

    Color mapping.

    We came to a situation when there are no texture for certain areas of the mesh. For example, I don't have texture for mapping inner side of wheelwells. In such a case, "color mapping" can be used.

    Color mapping is a mapping of vertices onto plain color area of texture. In this case, mapping object is scaled to fit onto small (usually square) area of texture and all vertices get exactly the same color on texture. As a result, surface on the mesh appears "painted" into this color.

    Take a look at texture again. Notice several small squares in the upper-left corner of texture. These are solely for "color-mapping" technique. We shall use a "black" square now to map wheelwells. Like you have done it before, detach wheelwells (you can map them both at a time - it doesn't matter here) and generate mapping for them (front view is preferable). Then scale uv-mapping object to a small black square in the upper-left corner of texture. You can zoom closer to make sure that whole mapping-object lays inside square area. Image on the right shows how you should scale. Exactly the same way I've mapped some polygons to a bright grey square of texture. Polygons I've mapped are rounded with red on the left image. Notice that I haven't mapped roof, trunk, hood and glasses. They will not be color-mapped, since there is another mapping trick for this case.

    Hand-made texture tricks.

    We shall now map a hood. It can be color-mapped to a bright grey area, but it will not. Instead, there is a rectangle on texture that I've drawn manually. This rectangle is painted to bright grey color too, but it also contains a black bounding. It's on the right image. There is nothing special with this rectangle - all the trick is in the black bounding. These black lines will simulate groove between hood and side; between trunk and side. I've hidden mapped front, color-mapped areas and selected hood vertices:

    Then I've generated UV-mapping for these vertices in top view, moved and scaled mapping-object in UVMapper. I've placed it over the area where this object will be mapped:
    Finally (it takes a little long) I've moved all vertices individually until they laid like on the right image. At the same time very handy hood mapping was achieved. Notice that there is no black line on the right edge of the hood (since it's just a half of the hood.

    The same way trunk and roof were mapped (roof has this groove line too). Image below shows the trunk mapped. Notice that not all black boundary lines are used, since I don't need black line at all three side edges of trunk. At least I don't need dark line where surrounded with red color:

    Take a look at this area of texture (see an image on the right). Guess what is it? This will be glasses tinit (with metal/rubber frame - I don't know how exactly vehicles glasses are build in). I will show how to map front side window onto this area.

    First of all, select front side window polygons, detach them as usual and generate new mapping for them in left view:

    In UVMapper, mirror object horizontally and move it over the area it will be mapped to. Image below shows how exactly you will need to move vertices in order to map properly. Dashed line shows where boundary vertices should lay:
    As a result, you can achieve something like on the right image. Notice that mapping near rear door glass has a bit wider black line. Rear door window will have the same wide line there too, so both windows will be separated from each other with solid black line. Image below is a result of mapping rear side glass:

    Mapping front windscreen and rear glass is way more simplier - these are almost square and fit according texture area perfectly. The only thing to notice is that "solid black line" will be missing at all (no black line on "interruption edge" needed).

    Details.

    We have mapped pretty big parts of mesh as a whole. It's a rare case when objects are mapped this way. Instead, details mapping is way more common case.

    Details mapping is the way you map certain details of the mesh onto more high-detailed texture areas. Headlights and taillights are the most common example. Most of modellers prefer to allocate more texture space for headlights, taillight, emblems, door handles, etc.

    The texture I've made for BMW is not an exception - there are more detailed taillight and headlight on it. Like it was done before - detach taillight and map it onto more detailed texture. You will see that blurry taillight will becomre much more accurate:

    That is almost all i was going to tell about UV mapping in this lesson. One more thing to add is about mapping complete shape. We have mapped only half of the vehicle. If you copy it, mirror and merge into one complete shape, you will notice that certain areas have to be remapped. First of all, it's a license plate. The second, probably, a BMW emblem on the hood and on trunk gate. These can be mapped as a final touch.

    Be adviced when using Modify\Weld tool (especially in Multy-target mode). This tool welds uv-mapping too. To avoid messing of uv-mapping, make sure not to weld vertices with different mapping. Also, make sure to set UV-Limit to 0.00 when using multy-target mode.

    Result of UV-Mapping BMW is in Files/les1_04.z3d file.

    Mapping tips.

    As a conclusion, I'll quote here some mapping tips from Ryan's Ravisol tutorial.

    To a point, the mechanics of mapping a mesh can be taught. However, the art of clever, precise mapping is something that comes with time. Some practices can help you speed this learning process up.

  • Base to Pivot Using pivot helper, dragging it here and there and using it as a point of Scale\Rotate will allows you to scale any group of verts down to a specific area of the texture. So, you start by lining up the texture around the area you want to map it to, then you find a good reference point to scale it to, like one corner of the area, or perhaps the center, if you can find that. Then, using Scale, you can scale the object down into the area.
  • Map at High Zoom Another good technique to use is to zoom way in when mapping. This allows you to control down to the pixel where your verts are mapped. You must use high zoom in mapping to ensure accuracy. If you don't, you may wind up with little lines around the edges of your mapped areas where they overlap to the next area.
  • Understand Stretching/Compressing A big part of mapping is actually stretching or compressing the texture into the mesh. Because you probably distorted the shading contours of the texture when you made it, you need to counteract that effect in order to get good shading on the car. Basically put, when a small area of texture is mapped to a large area of the mesh, it's stretched, and when a large area of texture is mapped to a small area of mesh, it's compressed. Common sense tells us that compression looks better than stretching, and this is true. Stretched textures tend to look pixelated, and should be avoided. However, a combination of both techniques is essential. I think that one misconception that a lot of modelers have is that your mapping object has to look exactly like the actual object. This is not true, because changes made to the mapping object do not affect the shape of the real object. So, if you have to disproportionately scale your mapping object to fit your texture, don't be afraid to do so.
  • Tile Textures When working with track textures, tiling should be your friend. Instead of using 2048x2048 textures to represent grass in a track or scene, you can use one 256x256 texture and tile it. If a texture can be repeated as a pattern with little or no obvious lines or repetition, then it can be tiled. Tiling is easy in Z-Modeler. You just have to scale it larger and larger until you have tiled it as much as you like it. However, a word of caution. This only works when the texture is the only one in the image! You cannot use this technique with an image that contains more than one texture.
  • Mirror/Rotate You can use the Mirror and Rotate commands in Z-Modeler's mapping window to move the verts as well, so make good use of them. If you see that some text is mirrored, don't flip the texture, mirror the mapping object. However, a word of caution, make sure you line it back up well, and mind the modification axes you have active when you mirror. You don't want it to end up upside down as well. Rotation is another good way to move verts around. Often the orientation of the texture is different from the mesh. Therefore you have to rotate it to make it fit.
  • Avoid Messy Mapping Finally, avoid messy mapping. Try and keep the mapping objects lined up with each other whenever they are adjacent. Try to also avoid mapping a whole mass of polys to a certain area with no regard for their shape, because this can cause shading difficulties. It will also make it easier when you go to tweak the mapping later.

    UV Remapper.

    While talking about UV-Mapping, it's a very convenient to mention one mapping problem - a so called multy-texture remapping.

    Multy-texture remapping is a process of converting multiple-materials mesh to single-material mesh. In more general case, it involves converting UV mapping of the mesh, that uses several textures to a certain areas of another material/texture.

    As an example, assume you have a complete mesh which was mapped to several materials. Each of materials uses it's own texture (e.g. side, front, top, and other textures). But for some reason you need to convert this mesh into some game format which limits you with a single texture. Most of racing games are the case since they use only one texture (skin) at a time for the whole mesh (and usually offers several replaceable "skins" for the same mesh). Your choice would be to create one big texture out of side, front, top etc. and lay them on a single "skin" texture. But here the problem arise: uv-mapping will be lost in such a case.

    UV-Remapper is the tool which allows to solve this problem. It's located in main menu under Edit\Surface branch and can be applied to selected objects or to selected polygons (both in selected mode). As an example, assume you have a mesh that uses the set of textures (see an image on the right). Assume you have placed all these images onto singe 256x256 texture. You have a file with several materials (one for each texture) and a mesh that uses all these materials. To remap this mesh, first create new material (e.g. "New Skin Material" and load your single texture onto it. Then select meshes You would like to remap, switch to selected mode and open UV Remapper. The first what you should do is to set "Remap To" material choice to "New Skin Material". Main texture of this material will be displayed in the left view. List of materials on the right allows you to place checkmarks which means that according material will be remapped. An according remapping-area (or "source material") rectangle will be drawn in the view. When you right-click on such a rectangle (or select an according row in the list) this rectangle becomes editable. You can move it and drag it's corner points to resize area. Thus you can place it over according area on texture.

    You can zoom in and out with mouse wheel, like in other viewports. Ctrl and Shift key held down will toggle slow and fast zooming respectively.

    Image on the left shows almost all rectangles positioned over respective areas on new texture. Here I came to a "under.bmp" texture. It was rotated 90 degreese on the canvas and I can't just lay new rectangle over it - I need it to be rotated. Before explaining what to do in such a case, take a look again at these area-rectangles. First of all, one of the lines is green and others are blue. Green line shows "top-edge" of old texture. Second, when switched to editable mode, one corner point is purple (others are red) - the purple point is a "top-left" corner of old image. Ok, now I shall rotate my "under.bmp" area. To make it possible, I switch area-rectangle to "user-defined" mode: I hold key down, click and drag one of it's corner points. From this moment on, corner points can be dragged only one by one and I can place them however I would like. The right image shows how I need to place "under.bmp" area. Once placed properly, hit OK button and selected meshes (or polygons) will be remapped to new material and according vertices mapping will be updated.

    This was just an example. When you face to exactly this situation, you can practice it. For now, it's upto your choice whether you will check how this works or not.