Rendering/Converting polygonal objects
I noticed that the vast majority of the scene created with POV-Ray are made up exclusively using CSG and POV-Ray primitives like spheres, boxes, cylinders...
CSG is a powerful tool for creation of several type of objects and it has some advantages over polygonal mesh objects. They needs very little disk space to store and render perfectly at whatever resolution without showing facets.
However there are many things that are very difficult to model this way like organic shapes. And after all there are a great number of polygonal modelers for the Macintosh, shareware and commercial, and there are thousands of models out there in Internet, CD-ROMs...
Rendering polygonal mesh object in POV-Ray is possible but it's not a very easy task. I have some experience in this field and I would like to share it with you to see even more stunning images rendered with our favourite raytracer.
First of, let's spent two words explaining some POV-Ray keywords that we will use: mesh{}, triangle{}, smooth_triangle{}.
mesh{}
This is a new keyword introduced in revision 3.0. In previous revisions of POV-Ray we used union{}instead.
You should use mesh{}since it's optimized and should render faster using less memory.
The triangle is the simpler type of polygon. It has the peculiarity of being always planar. This keeps things simpler during rendering. If two or all three vertices overlap, the triangle is call "degenerate" and it's not rendered by POV-Ray.
The use of this primitive is useful only if we want a faceted looking object (like a F-118 Stealth Fighter or a crystal puppet). Otherwise, to obtain a smooth rounded surface using triangles is possible only using a huge amount of them. This is not the right way since POV-Ray kindly provide us surface normal interpolation.
This useful and often ignored POV-Ray primitive is the main subject of this page. It is a triangle with three additional vectors attached to the three vertices. POV-Ray is capable of rendering the triangle's face to make it looks like it's curved, depending of the direction of the surface normals. If we have a mesh of adjacent triangles, and the surface normals are properly oriented, POV-Ray renders the mesh smooth and it will appear rounded instead of faceted. Orienting those vectors by hand is a nightmare but luckily it's a process that can be automated. There is an algorithm that calculates the vectors orientations by elaborating the vertices of the triangle mesh.
On Macintosh, there is only one freeware program to perform such task:POV-Utilities. It's a collection of various utils for POV-Ray and contains Raw Triangle Smoother that's the program I'm writing of. It will read a text file in RAW triangle format and will output an .INC file with a union{} of triangles. It's possible to choose for the output both triangle{} and smooth_triangle{} primitives. Raw triangle format is the simpler way to store a triangle mesh. In the POV-Utilities package there is a text file called "RAW2POV.DOC" that will explain in detail the RAW format.
There are very few 3D modelers for MacOS that saves in this format so a conversion is usually needed.
Near all 3D apps saves in DXF format so the typical conversion steps are:
Modeler -> DXF -> Converter -> RAW -> Raw Triangle Smoother -> .INC and .POV files output.
At this point someone may point that exists some modelers (Amapi, Vision-3D, ...) that saves directly to a .POV file. Well, it's true, but Vision-3D supports only the triangle{} primitive, witch is inacceptable for most purposes, and Amapi is
commercial software. I cannot reccomend to spend severl hundred bucks just to
smooth up RAW files!
What we will use as a converter from DXF to RAW? In POV-Utilities there is a DXF to RAW converter but it's useless since it miss some facets due to a bug. I have written and app that can do the job: D-form. It imports in several formats and can export to a RAW file. Since it's not simply a converter it can perform some useful things to the model like reseizing, centring in the origin, rotating and a large number of deformations.
After saving the model to a RAW file open POV-Utilities and choose "Raw Triangle Smoother..." from the "Utilities - Scene File Conversion" submenu. Press the button "Select Input File..." to choose the RAW file to convert. The checkbox "Create Smooth Triangle" must be checked to get smooth_triangle{} output. Check also "Add Camera and Light Statements" and deselect all the others.
The include file so created needs some hand editing. Here's an example of a possible output:
This is the .POV file:
#include "colors.inc"
#include "shapes.inc"
#include "textures.inc"
/* Texture declarations for object 'thing' */
#declare thing_1 = texture {
finish {Shiny }
pigment {color red 1.000 green 1.000 blue 1.000 }
}
#include "thing.inc"
camera {
location <1.3000, 0.4000, 0.3000>
look_at <0.0000, 0.0000, 0.0000>
}
light_source {
<5.2000, 1.6000, 1.2000> color White
}
This is the .INC file:
/* Object 'thing' */
union {
triangle {<0.0000, -0.5000, 0.3090>, <0.3090, 0.0000, 0.5000>, <-0.3090, 0.0000,
0.5000> }
triangle {<0.0000, 0.5000, 0.3090>, <-0.3090, 0.0000, 0.5000>, <0.3090, 0.0000, 0.5000>
}
triangle {<0.0000, 0.5000, 0.3090>, <0.0000, 0.5000, -0.3090>, <-0.5000, 0.3090,
0.0000> }
texture {thing_1 }
}
I suggest to edit the .POV file this way:
#include "colors.inc"
#include "shapes.inc"
#include "textures.inc"
#include "thing.inc"
/* Texture declarations for object 'thing' */
#declare thing_1 = texture {
finish {Shiny }
pigment {color red 1.000 green 1.000 blue 1.000 }
}
camera {
location <1.3000, 0.4000, 0.3000>
look_at <0.0000, 0.0000, 0.0000>
}
light_source {
<5.2000, 1.6000, 1.2000> color White
}
object{
thing
}
And the .INC file this way:
#declare thing =
mesh {
triangle {<0.0000, -0.5000, 0.3090>, <0.3090, 0.0000, 0.5000>, <-0.3090, 0.0000,
0.5000> }
triangle {<0.0000, 0.5000, 0.3090>, <-0.3090, 0.0000, 0.5000>, <0.3090, 0.0000, 0.5000>
}
triangle {<0.0000, 0.5000, 0.3090>, <0.0000, 0.5000, -0.3090>, <-0.5000, 0.3090,
0.0000> }
texture {thing_1 }
}
If you are still using a POV-Ray 2.2 or earlier leave "union" instead of "mesh".
Here's an example of two models converted to a triangle{} based mesh:
Here's an example of two models converted to a smooth_triangle{} (60 degrees) based mesh:
Here's an example of two models converted to a smooth_triangle{} (180 degrees) based mesh:
If you have any problems, please mail me.
Home > 3D Graphics > Persistence of Vision Raytracer > POV-Ray for MacOS Hints and Tips > Rendering/Converting polyonal objects
This page hosted by
Get your own Free HomePage