Class LODGeomap

java.lang.Object
com.jme3.terrain.GeoMap
com.jme3.terrain.geomipmap.LODGeomap
All Implemented Interfaces:
com.jme3.export.Savable

public class LODGeomap extends GeoMap
Produces the mesh for the TerrainPatch. This LOD algorithm generates a single triangle strip by first building the center of the mesh, minus one outer edge around it. Then it builds the edges in counter-clockwise order, starting at the bottom right and working up, then left across the top, then down across the left, then right across the bottom. It needs to know what its neighbour's LODs are, so it can stitch the edges. It creates degenerate polygons in order to keep the winding order of the polygons and to move the strip to a new position while still maintaining the continuity of the overall mesh. These degenerates are removed quickly by the video card.
Author:
Brent Owens
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Keeps a count of the number of indexes, good for debugging
  • Field Summary

    Fields inherited from class com.jme3.terrain.GeoMap

    hdata, height, maxval, width
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    LODGeomap(int size, float[] heightMap)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.jme3.math.Vector3f
    calculateTangent(com.jme3.math.Vector3f[] v, com.jme3.math.Vector2f[] t, com.jme3.math.Vector3f tangent, com.jme3.math.Vector3f binormal)
     
    com.jme3.scene.Mesh
    createMesh(com.jme3.math.Vector3f scale, com.jme3.math.Vector2f tcScale, com.jme3.math.Vector2f tcOffset, float offsetAmount, int totalSize, boolean center)
     
    com.jme3.scene.Mesh
    createMesh(com.jme3.math.Vector3f scale, com.jme3.math.Vector2f tcScale, com.jme3.math.Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod)
     
    protected int
    findClosestHeightIndex(int x, int z)
     
    protected com.jme3.math.Triangle[]
    getGridTrianglesAtPoint(float x, float z)
    Get the two triangles that make up the grid section at the specified point.
    protected com.jme3.math.Triangle[]
    getGridTrianglesAtPoint(float x, float z, com.jme3.math.Vector3f scale, com.jme3.math.Vector3f translation)
    Get the two triangles that make up the grid section at the specified point, translated to world coordinates.
    protected float
    getHeight(int x, int z, float xm, float zm)
    Get the two triangles that make up the grid section at the specified point.
    protected com.jme3.math.Triangle
    getTriangleAtPoint(float x, float z)
    Get the triangle that the point is on.
    protected com.jme3.math.Triangle
    getTriangleAtPoint(float x, float z, com.jme3.math.Vector3f scale, com.jme3.math.Vector3f translation)
    Get a representation of the underlying triangle at the given point, translated to world coordinates.
    com.jme3.math.Vector2f
    getUV(int x, int y, com.jme3.math.Vector2f store, com.jme3.math.Vector2f offset, float offsetAmount, int totalSize)
     
    void
    read(com.jme3.export.JmeImporter im)
     
    void
    write(com.jme3.export.JmeExporter ex)
     
    com.jme3.scene.mesh.IndexBuffer
    writeIndexArrayLodDiff(int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod, int totalSize)
    Create the LOD index array that will seam its edges with its neighbour's LOD.
    com.jme3.scene.mesh.IndexBuffer
    writeIndexArrayLodVariable(int lod, int rightLod, int topLod, int leftLod, int bottomLod, int totalSize)
     
    writeNormalArray(FloatBuffer store, com.jme3.math.Vector3f scale)
    Creates a normal array from the normal data in this Geomap
    writeTangentArray(FloatBuffer normalBuffer, FloatBuffer tangentStore, FloatBuffer binormalStore, FloatBuffer textureBuffer, com.jme3.math.Vector3f scale)
     
    writeTexCoordArray(FloatBuffer store, com.jme3.math.Vector2f offset, com.jme3.math.Vector2f scale, float offsetAmount, int totalSize)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LODGeomap

      public LODGeomap()
    • LODGeomap

      public LODGeomap(int size, float[] heightMap)
  • Method Details

    • createMesh

      public com.jme3.scene.Mesh createMesh(com.jme3.math.Vector3f scale, com.jme3.math.Vector2f tcScale, com.jme3.math.Vector2f tcOffset, float offsetAmount, int totalSize, boolean center)
    • createMesh

      public com.jme3.scene.Mesh createMesh(com.jme3.math.Vector3f scale, com.jme3.math.Vector2f tcScale, com.jme3.math.Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod)
    • writeTexCoordArray

      public FloatBuffer writeTexCoordArray(FloatBuffer store, com.jme3.math.Vector2f offset, com.jme3.math.Vector2f scale, float offsetAmount, int totalSize)
    • getUV

      public com.jme3.math.Vector2f getUV(int x, int y, com.jme3.math.Vector2f store, com.jme3.math.Vector2f offset, float offsetAmount, int totalSize)
    • writeIndexArrayLodDiff

      public com.jme3.scene.mesh.IndexBuffer writeIndexArrayLodDiff(int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod, int totalSize)
      Create the LOD index array that will seam its edges with its neighbour's LOD. This is a scary method!!! It will break your mind.
      Parameters:
      lod - level of detail of the mesh
      rightLod - LOD of the right neighbour
      topLod - LOD of the top neighbour
      leftLod - LOD of the left neighbour
      bottomLod - LOD of the bottom neighbour
      Returns:
      the LOD-ified index buffer
    • writeIndexArrayLodVariable

      public com.jme3.scene.mesh.IndexBuffer writeIndexArrayLodVariable(int lod, int rightLod, int topLod, int leftLod, int bottomLod, int totalSize)
    • writeTangentArray

      public FloatBuffer[] writeTangentArray(FloatBuffer normalBuffer, FloatBuffer tangentStore, FloatBuffer binormalStore, FloatBuffer textureBuffer, com.jme3.math.Vector3f scale)
    • calculateTangent

      public static com.jme3.math.Vector3f calculateTangent(com.jme3.math.Vector3f[] v, com.jme3.math.Vector2f[] t, com.jme3.math.Vector3f tangent, com.jme3.math.Vector3f binormal)
      Parameters:
      v - Takes 3 vertices: root, right, bottom
      t - Takes 3 tex coords: root, right, bottom
      tangent - that will store the result
      Returns:
      the tangent store
    • writeNormalArray

      public FloatBuffer writeNormalArray(FloatBuffer store, com.jme3.math.Vector3f scale)
      Description copied from class: GeoMap
      Creates a normal array from the normal data in this Geomap
      Overrides:
      writeNormalArray in class GeoMap
      Parameters:
      store - A preallocated FloatBuffer where to store the data (optional), size must be >= getWidth()*getHeight()*3
      Returns:
      store, or a new FloatBuffer if store is null
    • getHeight

      protected float getHeight(int x, int z, float xm, float zm)
      Get the two triangles that make up the grid section at the specified point. For every grid space there are two triangles oriented like this: *----* |a / | | / b| *----* The corners of the mesh have differently oriented triangles. The two corners that we have to special-case are the top left and bottom right corners. They are oriented inversely: *----* | \ b| |a \ | *----*
    • getTriangleAtPoint

      protected com.jme3.math.Triangle getTriangleAtPoint(float x, float z, com.jme3.math.Vector3f scale, com.jme3.math.Vector3f translation)
      Get a representation of the underlying triangle at the given point, translated to world coordinates.
      Parameters:
      x - local x coordinate
      z - local z coordinate
      Returns:
      a triangle in world space not local space
    • getGridTrianglesAtPoint

      protected com.jme3.math.Triangle[] getGridTrianglesAtPoint(float x, float z, com.jme3.math.Vector3f scale, com.jme3.math.Vector3f translation)
      Get the two triangles that make up the grid section at the specified point, translated to world coordinates.
      Parameters:
      x - local x coordinate
      z - local z coordinate
      scale -
      translation -
      Returns:
      two triangles in world space not local space
    • getGridTrianglesAtPoint

      protected com.jme3.math.Triangle[] getGridTrianglesAtPoint(float x, float z)
      Get the two triangles that make up the grid section at the specified point. For every grid space there are two triangles oriented like this: *----* |a / | | / b| *----* The corners of the mesh have differently oriented triangles. The two corners that we have to special-case are the top left and bottom right corners. They are oriented inversely: *----* | \ b| |a \ | *----*
      Parameters:
      x - local x coordinate
      z - local z coordinate
      Returns:
      a new array or null
    • getTriangleAtPoint

      protected com.jme3.math.Triangle getTriangleAtPoint(float x, float z)
      Get the triangle that the point is on.
      Parameters:
      x - coordinate in local space to the geomap
      z - coordinate in local space to the geomap
      Returns:
      triangle in local space to the geomap
    • findClosestHeightIndex

      protected int findClosestHeightIndex(int x, int z)
    • write

      public void write(com.jme3.export.JmeExporter ex) throws IOException
      Specified by:
      write in interface com.jme3.export.Savable
      Overrides:
      write in class GeoMap
      Throws:
      IOException
    • read

      public void read(com.jme3.export.JmeImporter im) throws IOException
      Specified by:
      read in interface com.jme3.export.Savable
      Overrides:
      read in class GeoMap
      Throws:
      IOException