Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

Automatic Mesh Optimizations via Triangle Welding

Not many news on the Delta Engine side, we have been very busy with an internal project that pays the bills. This is what this post is about. v0.9.12 is however a pretty good improvement over v0.9.11 (previously release version 1.1) and while not new platform or rendering features are coming (since no one is working on those at the moment) we have completely revamped entities (see last post) and the content system as well. Not only it is much easier to use and develop for, the editor is also in a much better state because of reduced functionality and much cleaner design.

From the new "Automatic Mesh Optimizations via Triangle Welding" article in our public wiki:

Goal: Optimize imported complex 3D data from 180k vertices (140k triangles) to ~20k vertices (~30k triangles)

For an internal project we were given huge meshes with tons of vertices (180k unique vertices per mesh) to be rendered on mobile devices (especially slower Android devices, if possible multiple big meshes visible like 3-10). The process of importing needs to be automatic as we do not know which geometry is going to be imported and rendered, for just one geometry a human 3D modeler can obviously redo the geometry and bring it down to a reasonable polygon count. We found no good tool to do this either manually or programmatically, so we had to write our own library for it (not enough open source in the world as I am sure people have done this before). Rendering performance was really bad since each mesh had to be subdivided into 14 materials as well and some needed too many vertices to keep in index buffers with shorts.

Long story short we did 2 things: First we welded the vertices, everything closer than 0.25cm was collapsed into one vertex point, which reduced the mesh 40%. Next we also started welding triangles, which is much more difficult and constantly destroyed our geometry (while it is nice to have 90% merged, that is not really useful if it does not look like the original anymore). This is why we put a lot of extra checks in place to not merge any corner triangle points away and keep the outlines intact and sharp corners as well, but otherwise everything below 10cm (up to 50cm for straight lines) and below 22.5 degrees is collapsed into bigger triangles.

We are still testing, but in some tests we can get rid of 80% of the triangles, we will update this once we have tested it with huge geometries as well (quite slow, needs optimization and we are still refactoring, tests look good so far). All the code sits in the content service of the Delta Engine, so you won't find it in the rendering code of the Delta Engine.

Read the wiki entry for the rest of the article.