Generalized Triangle Mesh Optimizer

Abstract:

This document is about creating optimized (simplified) triangular meshes for use in bump-mapping capable games. It describes the procedure to automatically create the optimized mesh from a mesh with many polygons, by using the triangle mesh optimizer from the Sylphis 3D game engine .

Introduction

The Sylphis 3D game engine is capable of doing per pixel lighting on all geometry it draws. This gives us the opportunity to assign normals on every mapped texel and simulate surface bumps, when there is no actual geometry. This normal assignment is done by mapping on the surface the normal-map. This normal-map is like a standard color texture, but every texel's (R,G,B) gives us the normal's (X,Y,Z) at that point on the surface. This makes other points on the surface ``look at'' the light more and be brighter, while others ``look at'' the light less and be darker. This gives the impression of a bumpy surface to the eye.

There are two ways of creating the normal-map. The easy way is generating it from a ``hand-drawn'' gray-scale image that represents the bumps of the surface. This technic has moderate results. The more advanced generation method, involves extracting the normal information from a high detail mesh. This technic produces the best results, but requires that there are two models of the same thing. One with many triangles and one with low triangle count so that it can be used for realtime rendering. The obvious solution, to have artists create both models, can be very time consuming. It would be nice if it was possible to create the low resolution mesh from the high resolution mesh automatically. Most 3D modelling software include optimization functions, but most of the time don't create good approximations for the high resolution model. At least no good approximations for bump-mapping.

This text is about the triangle mesh optimizer created as part of the Sylphis 3D game engine and discuss the usage and the features of it.

Installing

The Sylphis Generalized Triangle Mesh Optimizer (G.T.O) is part of the Sylphis 3D game engine, but it was designed to be used even without Sylphis. The external G.T.O can be downloaded from the download section of sourceforge Sylphis' homepage :

https://sourceforge.net/project/showfiles.php?group_id=136327&package_id=161788&release_id=351672

Simply execute the downloaded file and the installer will guide you through the rest of the installation process.

Note that it might be a good thing to add the program's installation folder to the system path.

The Optimizer

The Sylphis Generalized Triangle Mesh Optimizer (G.T.O) is a command line utility. This means that it is invoked from the command line prompt with the appropriate parameters1. The executable name is sgto.exe. It takes three parameters. The input high resolution mesh file, the output low resolution mesh file and the requested number of polygons for the output mesh.



The input file mush be in the Simple Mesh File (.SFM) format and so the produced output will be. The importers for 3DSMAX version 5.0 are included in the Sylphis 3DSMAX exporters download, available at the Sylphis homepage.

Usage Example

In the folder example/ under the installation directory we can find a high resolution model of a cow. The file is named cow.smf2. This model has 34834 triangles.

Start the command line and change folder to the installation folder. Then type :



This will start the process to create a triangle mesh approximation for example cow.smf with 1000 triangles. Note that it is possible to get a 999 triangle mesh for output. This will not happen with this mesh, but it is normal to happen. Your console should look something like figure 1.

Figure 1: Running the optimizer

When the optimization process completes there should be the file cow_out.smf in the current folder. The output mesh should have 1000 triangles, as requested. This is a 97% reduction!

Lets import the files in 3DSMAX for visual review. In figure 2 we can see the high and low resolution models in wire-frame mode. In figure 3 we can see the high and low resolution models after smoothing their normals.

Figure 2: The 34834 triangle model (left) and the 1000 triangle model (right). In wire-frame rendering mode.

Figure 3: The 34834 triangle model (left) and the 1000 triangle model (right).

Take notice that even at a reduction of 97%, the low detail model still maintains the major features of the high resolution model, while loosing the details that can be later be added by bump-mapping. Take for example the eyes and the nose holes that are removed in the low resolution model.

Comparing with the 3DSMAX Optimizer

Now we will try to create the low resolution model by using the optimize modifier that comes with 3DSMAX. We start by importing the high resolution model and then we apply on it the optimize modifier. We then progressively increment the Face Thresh value, until we have nearly 1000 triangles. With a Face Thresh value of 18.6 we get 1036 triangles (Figure 4).

Figure 4: The optimize modifier parameters of 3DSMAX.

So lets compare the results of Sylphis G.T.O and 3DSMAX. In figures 5, 6 we can see the wire-frame an filled versions of the two low resolution models. The left was generated by the Sylphis G.T.O and has 1000 triangles. The right by 3DSMAX and has 1036 triangles. Even if it is hard to believe the right model has 36 triangles more than the left! It is obvious that the Sylphis G.T.O managed its triangle budget more wisely, resulting in more homogeneous triangle distribution and does not generates ``long'' and degenerate triangles. This is a very important parameter when normal mapping is the target.

Figure 5: The 1000 triangle model generated by Sylphis G.T.O (left) and the 1036 triangle model generated by 3DSMAX(right). In wire-frame rendering mode.

Figure 6: The 1000 triangle model generated by Sylphis G.T.O (left) and the 1036 triangle model generated by 3DSMAX(right).

In Figure 8 and Figure 7 we can see an other example of optimization. The original high resolution model consisted of 180000 triangles. To the left we can see the Sylphis G.T.O produced version. To the right we can see what 3DSMAX optimize produced.

Figure 7: The 2500 triangle model generated by Sylphis G.T.O (left) and the 2518 triangle model generated by 3DSMAX(right). In wire-frame rendering mode. This two models was generated from a high resolution model of 180000 triangles.

Figure 8: The 2500 triangle model generated by Sylphis G.T.O (left) and the 2518 triangle model generated by 3DSMAX(right). This two models was generated from a high resolution model of 180000 triangles.

It is again obvious that the Sylphis G.T.O produced better and more uniform triangles, while being more loyal to the triangle budget. The 3DSMAX version on the other hand even failed to maintain the figure of the body. The model became heavily distorted.

Applying Normal-Mapping

Now that we have both a high and low resolution models we can generate the normal-map for the low resolution model. For this procedure we will use the NormalMapper utility from ATI. Available from www.ati.com.

The first thing that we should do is to assign texture coordinates to the low resolution model cow_out.smf. For this use the Unwrap UVW modifier from 3DSMAX. Then create a flatten texture mapping. This will not create the best results but it is ok for the example. Now that the model has texturing coordinates export to .NMF files both the high and low resolution models. These file types is supported by the ATI's normal mapper. Invoke the normal mapper like this :



After finishing the above command will generate the normal map in Figure 9.

Figure 9: The normal-map

This can be applied on the low resolution model to make it look like the high resolution model. In Figure 10 we can see how the normal map can make the low resolution model look like the high resolution model. In Figure 10, A is the original high resolution model of 34834 triangles. B is the optimized by Sylphis G.T.O low resolution model of 1000 triangles without the normal map. Now C is the same model as B, but with the normal map applied. Note that C has only 3% of the triangles A has, but looks almost identical to it.

Figure 10:

Closing words

It is obvious that bump-mapping can put back into the low resolution model a great amount of detail, that was impossible to add with triangles because of performance reasons. The quality of the normal maps generated from high resolution meshes is unreachable. So having a tool that will automatically create the low resolution mesh from the high resolution, gives the artists the freedom to create everything very detailed and very high resolution and not worry about the low resolution model. The Sylphis G.T.O is still in early stages of development but can give pretty good results. It is also important to say that the Sylphis G.T.O can be used separately from the Sylphis 3D game engine.



Footnotes

... parameters1
The source code of the utility can be obtained from the site, so it is possible to create a GUI version
...cow.smf2
If you know the origin of this model please contact me, so that proper credit can be given. It is widely used by academics but none seems to now its origin.