I’ve been playing around with Level of Detail lately.
As you may know (or not), JME 3 meshes supports lods as long as they are generated. There is also a LodControl that allows you switch the lod according to the distance to the camera.
In JME lods are implemented as several index buffers that provides different ways of connecting vertices in a mesh.
The only way until now to generate lods on an arbitrary model was to import it in the engine through the Ogre pipeline and use the advanced conversion to j3o to generate the lods.
This process uses Ogre’s command line tool in the background.
I wanted to allow users to generate lods from the SDK whatever pipeline they chose. So I went and look at ogre’s code.
I stumbled on this interesting thread http://www.ogre3d.org/forums/viewtopic.php?f=11&t=74798#p476220 where Peter Szücs a GSOC 2012 student describe how he enhanced Ogre LOD generation toward quality and performance…and provides an MIT licenced C++ code :D.
So I went and “translated” this to Java. I’m pretty happy with the result.
Here is Jaime with around 60% decimation. the left one is generated with JME and the “new” algorithm the right one is generated with ogre command line tool
Ok…they both have a tooth problem, but the left one doesn’t have bat wings and the texture is not distorted along the seams.
Note that the original model has 5108 triangles.
I don’t even know if this algorithm has been merged to Orge 1.9 version.
So enjoy, you now have a LodGenerator class to generate lods for any model. For now it’s only a utility class in the engine, a SDK tool will come later.
LodGenerator lodGenerator = new LodGenerator(geometry); lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue1,reductionvalue2);
TriangleReductionMethod is the way to consider triangle decimation. Proportional is a percentage, Constant is an arbitrary number of triangle, Collapse_Cost is base on the aesthetic cost of collapsing a triangle. I encourage you to read the references pointed in the javadoc to understand all of this.
the above example will generate 3 lod levels : the first is the original index buffer, and the 2 others will have respectiively a reduction of reductionvalue2 and reduction value 2.
for example :
LodGenerator lodGenerator = new LodGenerator(geometry);
the first one will be a version of the mesh with 10% less polygons, the second a version with 50% less polygons.