Imagine that you want to put a realistic texture on a model of a human body. "Realistic" means that you need to create subtle variations of colour: the skin will be rosier here, darker there and so on. Since this looks very difficult to do by procedural means (i.e. using patterns like bozo or gradient), it is likely that you'll want to use an image map. But then, how are you going to map this picture on the model ? There are different mapping types available, but only for simple primitives : plane, sphere, cylinder... Even if you assume that a body is somehow cylindrical, it will very difficult to position a particular colour on a particular spot. This could turn into a nightmare of trial-and-error, if it's possible at all. Fortunately, UV-mapping is the right tool for this.
A UV map looks like the following: The first picture is a UV template for a mesh of a head (Poser 4 Nude Woman), while the second one is the final painted version (actually a part of the one used for Eve's morning). Unlike a regular image map, which is projected on the model according to one of the mathematical map types, this map will fit the model exactly. The lines on the templates are the mesh polygons (triangles). The model will be painted according to its colour on the map : for this each vertex of the mesh has a map co-ordinate - the <u,v> vector - associated to it. |
Note : this tutorial will only cover UV-mapping for meshes. For other uses of UV-mapping, please refer to the Megapov and POV 3.5 documentation.
In Megapov and POV 3.5 and higher, there are two mesh formats that support UV-mapping. These UV meshes contain information about the geometry and normals, but also about the way they are textured (the UV vectors).
Note that there is an important behavioural difference between a UV-mapped mesh2 and a traditional one. With a classic mesh, each copy of it can be independently textured, so that you can parse the mesh once and still have copies with different textures. With mesh2, the texture is given at parsing time, so that all its copies have the same texture. If you need another copy with a different texture, youll need to parse the mesh again.
First, you'll need a version of POV that supports it, like Megapov or POV 3.5 and higher. Because mesh UV-mapping was only recently supported by POV, there are few utilities that deal with it. Important note : this tutorial is Windows only. Of the utilities below some may have Linux or Mac versions.
These other utilities will be handy:
You will also need a paint programme such as Photoshop or Paintshop Pro that can read and save in the major graphic file formats (JPG, TIFF, TGA, PNG and BMP).
Any mesh can be theoretically UV-mapped and converted to be used in POV. Presently (June 2000), there is no 100% reliable way to convert an OBJ or 3DS file with UV-mapping to POV. All the converters listed above are prone to crash on particular files or to produce files that don't render properly. It seems that some converters only support subsets of the file specifications : for instance, they may convert correctly an Poser OBJ file, but will produce an erroneous mesh with a Lightwave OBJ. When this happens, try another converter. Still, my favourite is 3DS2POV, which I have used quite extensively in 1999-2000. However, it requires a prior conversion to 3DS which may be itself tricky.
Using Poser - a commercial package dedicated to the creation of human and animal characters - is one of the main reasons why many POV users (including me) are interested in UV-mapping, so Ill use Poser as an example. Poser exports to several formats, including OBJ and 3DS, which are already UV-mapped, and the image and bump maps are available with the models.
From a Poser model to mesh2
There are two ways to do this.
Once you have exported the model to mesh2, you should obtain several files, depending on the converter. Basically they produce a file that contains the model, a file for the textures and a *.pov file that can be run directly.
In the case of a conversion through 3DS2POV, and assuming that the 3DS file was called TOTO.3DS, then:
- TOTO_O.INC is the object file itself.
- TOTO.POV is a ready-to-use POV file.
- TOTO_M.INC contains the material (texture) information.
- TOTO_A.INC is related to animation.
Editing the textures
When you open the TOTO_M.INC file, youll see that it contains one or several texture definitions. In fact, a UV-mapped mesh can use many different textures, each texture being attached to one particular part of the mesh. Typically, Poser models produce mesh2 meshes that require a dozen or so textures.
However, it usually doesnt make sense to use the textures as they are in the TOTO_M.INC file, because theyre only templates with dummy colours. Youll need to edit the TOTO_M.INC, and replace the texture info by the correct pigment (image map) and finish information, or even add a normal statement. Usually, there is a texture called "default_texture" that you can use as a starting point. Once edited, the material file should look like this:
#declare default_texture = texture {
pigment{image_map{png "p4woman.png"}} // the UV map
finish{metallic brilliance 2 ambient 0.01 diffuse 0.6 specular 0.03 roughness 0.05}
}
#declare Mskin=texture{default_texture} // the main texture
#declare Meyeball =texture{Mskin finish{reflection 0.3}}
#declare MeyeBrow = texture{Mskin}
#declare Mnipple = texture{Mskin}
#declare Mlips = texture{Mskin finish{ambient 0.1 diffuse 0.3 specular 1 roughness 0.01}}
#declare MinnerMouth = texture{Mskin}
#declare Mtongue = texture{Mskin}
#declare Mteeth = texture{Mskin}
#declare Mlashes = texture{Mskin}
#declare Mpupil = texture{Meyeball}
#declare Miris =texture{ Meyeball}
The textures names are usually self-explanatory, at least for Poser models. This is not always the case with all models and sometimes it is necessary to do some tests to figure out the precise use of the textures.
In the above example, all the textures are based on the image_map provided with the Poser model. You may need to convert the original map (often a TIFF file) into a format that POV-Ray can read. Note that the Poser bump maps (*.BUM) files are actually BMP files, at least in the Windows version : all you need is change the extension (and increase the contrast of the bump map).
The image map is defined once and then used for all the body parts, with some variation in the finish statement. This is because the Poser maps usually cover the whole body: its the same map for the eyes and for the skin. In the example above, some reflection was added to the standard map for the eye parts (eyeballs, pupil, iris).
In this case, only one map is needed. Other models may require several maps. For instance, Zygotes Millenium Woman "Victoria", which is much more detailed than the standard Poser 4 nude woman, requires one map for her body and another for her face. Hair, clothes and accessories will need their own maps.
The use of an image map is not at all mandatory: you can put anything in the texture statement. In fact, you may provide no map at all and use UV-mapping info only to give different colours to the different body parts, or mix image maps and regular texture statements. In the above example,
#declare Miris = texture{pigment{SkyBlue}}
would change the colour of the iris from whatever colour is present at this location in the image map to a SkyBlue colour.
If you're using another converter, the process should be more or less the same.
One last thing about textures: because UV maps match exactly the model geometry, youd better not change the position of the elements of the map. Its possible to do so, though, see the UVMapper page for further detail. Of course, you can alter the colours to suit your needs, or the size of the map (the UV co-ordinates are relative to the map, not absolute).
Putting the model in your POV scene
Once the textures are all prepared, you need to put the model in your POV scene. The TOTO.POV file is a ready-to-use scene that you can use as a template. It reads the other files (TOTO_O.inc, TOTO_A.INC and TOTO_M.INC). Though it works perfectly, Ive always found that the default camera settings and lighting werent very practical for test purpose, so I usually edit this scene, add my own camera and lights to get a frontal scene and remove the call to TOTO_A.INC. The TOTO.POV scene also contains information about the min/max spatial co-ordinates of the mesh which is very handy when you need to position the mesh. Poser models are often very small, a POV unit or so high. Other models can have every possible size.
Sometimes, 3DS2POV outputs not one mesh but several (all in the same TOTO_O.INC file though). All these meshes are listed in TOTO.POV. It may be useful to put them together in one union{} statement.
If you use UV-mapping with Megapov or another unofficial version, youll need to add the version info at the beginning of the mesh file:
#version unofficial Megapov xxx.yyy; // where xxx.yyy is the version number of Megapov.
Summary
To use a UV-mapped model, youll need:
The process is pretty much the same as above, with one difference: youll need to generate the map yourself. Fortunately, this is almost automatic.
The first step is to convert your file to the OBJ format. This can be done with 3DWIN, or with any software that can read your original file and export to OBJ with the UV info untouched. DONT USE CROSSROADS, because it ignores the UV info.
The second step is to use a UV-mapping utility. The most popular is Steve Coxs UVMapper. If the mesh contains UV info, just load the OBJ file: UVMapper will build and show the map template automatically. Once you have saved the template, you can paint it using your favourite image editor. Note that the template is in 8-bit black and white: before painting you may need to increase the colour depth to 24-bit RGB.
After that, you can proceed as explained in the previous section.
In the two previous cases, the UV info was already there. In all probability, the UV info was created using tools that let you paint interactively on 3D models. AFAIK, there are no such tools available for free, or as low-cost shareware. If you dont have a tool like this, youll need to rely on UVMapper to do the job.
Here is a step-by-step example based on sPatch, Crossroads, UVMapper and POSE2POV. It also requires a version of POV that supports UV-mapping. The files (but not the programmes) necessary to the demo are bundled here. This works pretty much the same with OBJUVPOV.
1. Create the model in sPatch
2. Convert it to OBJ by Crossroads
|
3. Create the UV info
|
|
4. Convert to mesh2
|
5. Edit the files and run POV
|
|
Notes:
There are LOTS of things that can go wrong... Normals or UV vectors disappear or are totally messed up, wrong number of items in the indices lists cause errors etc. If mesh2 drives you mad, try to convert to the other UV-aware mesh format using OBJUVPOV. Try several converters if one doesn't give the right answer.
Here are some solutions to problems Ive come across.
My Poser model is all distorted when converted to mesh2, or refuses to be exported, or crashes 3DS2POV
The map is all wrong and doesnt seem to UV-map anything
There may be two reasons for this (at least reasons I know of).
The map appears correctly but I can see "seams" or erratically mapped triangles