Class LodGenerator

java.lang.Object
jme3tools.optimize.LodGenerator

public class LodGenerator extends Object
This is a utility class that adds the ability to generate LOD levels for an arbitrary mesh. It computes a collapse cost for each vertex and each edge. The higher the cost the more likely collapsing the edge or the vertex will produce artifacts on the mesh.

This class is the java implementation of the enhanced version of Ogre engine LOD generator, by Péter Szücs, originally based on Stan Melax "easy mesh simplification". The MIT licenced C++ source code can be found here https://github.com/worldforge/ember/tree/master/src/components/ogre/lod more information can be found here http://www.melax.com/polychop http://sajty.elementfx.com/progressivemesh/GSoC2012.pdf

The algorithm sorts vertices according to their collapse cost in ascending order. It collapses from the "cheapest" vertex to the more expensive.
Usage:

      LodGenerator lODGenerator = new LodGenerator(geometry);
      lODGenerator.bakeLods(reductionMethod,reductionValue);
 
reductionMethod type is VertexReductionMethod described here LodGenerator.TriangleReductionMethod reduction value depends on the reductionMethod

  • Constructor Details

    • LodGenerator

      public LodGenerator(Mesh mesh)
      Constructs an LodGenerator for the given Mesh.
      Parameters:
      mesh - the mesh for which to generate LODs.
    • LodGenerator

      public LodGenerator(Geometry geom)
      Constructs an LodGenerator for the given Geometry.
      Parameters:
      geom - the geometry for which to generate LODs.
  • Method Details

    • computeLods

      public VertexBuffer[] computeLods(LodGenerator.TriangleReductionMethod reductionMethod, float... reductionValues)
      Computes the LODs and returns an array of VertexBuffers that can be passed to Mesh.setLodLevels().
      This method must be fed with the reduction method LodGenerator.TriangleReductionMethod and a list of reduction values.
      for each value a LOD will be generated.
      The resulting array will always contain at index 0 the original index buffer of the mesh.

      Important note : some meshes cannot be decimated, so the result of this method can vary depending of the given mesh. Also the reduction values are indicative and the produces mesh will not always meet the required reduction.

      Parameters:
      reductionMethod - the reduction method to use
      reductionValues - the reduction value to use for each LOD level.
      Returns:
      an array of VertexBuffers containing the different index buffers representing the LOD levels.
    • bakeLods

      public void bakeLods(LodGenerator.TriangleReductionMethod reductionMethod, float... reductionValues)
      Computes the LODs and bakes them into the mesh.
      This method must be fed with the reduction method LodGenerator.TriangleReductionMethod and a list of reduction values.
      for each value a LOD will be generated.

      Important note: some meshes cannot be decimated, so the result of this method can vary depending on the given mesh. Also, the reduction values are approximate, and the algorithm won't always achieve the specified reduction.

      Parameters:
      reductionMethod - the reduction method to use
      reductionValues - the reduction value to use for each LOD level.