Class HeightfieldCollisionShape

All Implemented Interfaces:
com.jme3.export.Savable, com.jme3.util.clone.JmeCloneable, Cloneable, Comparable<NativePhysicsObject>

public class HeightfieldCollisionShape extends CollisionShape
A collision shape for terrain defined by a matrix of height values, based on Bullet's btHeightfieldTerrainShape. Should be more efficient than an equivalent MeshCollisionShape. Not for use in dynamic bodies. Collisions between HeightfieldCollisionShape, MeshCollisionShape, and PlaneCollisionShape objects are never detected.
  • Field Details

    • logger2

      public static final Logger logger2
      message logger for this class
  • Constructor Details

    • HeightfieldCollisionShape

      protected HeightfieldCollisionShape()
      No-argument constructor needed by SavableClassUtil.
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(float[] heightArray)
      Instantiate a square shape for the specified array of heights.
      Parameters:
      heightArray - (not null, length≥4, length a perfect square, unaffected)
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(com.jme3.terrain.heightmap.HeightMap heightMap)
      Instantiate a square shape for the specified HeightMap. If the HeightMap isn't populated, invoke its load() method.
      Parameters:
      heightMap - (not null, size ≥ 2)
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(float[] heightArray, com.jme3.math.Vector3f scale)
      Instantiate a square shape for the specified height map and scale vector.
      Parameters:
      heightArray - (not null, length≥4, length a perfect square, unaffected)
      scale - the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(com.jme3.terrain.Terrain terrain, com.jme3.math.Vector3f scale)
      Instantiate a square shape for the specified terrain and scale vector.
      Parameters:
      terrain - (not null, size ≥2, unaffected)
      scale - the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(int stickLength, int stickWidth, float[] heightmap, com.jme3.math.Vector3f scale, int upAxis, boolean flipQuadEdges, boolean flipTriangleWinding, boolean useDiamond, boolean useZigzag)
      Instantiate a rectangular shape for the specified parameters.
      Parameters:
      stickLength - the number of rows in the heightfield (>1)
      stickWidth - number of columns in the heightfield (>1)
      heightmap - (not null, length≥stickLength*stickWidth, unaffected)
      scale - the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
      upAxis - the height-axis index (0→X, 1→Y, 2→Z, default=1)
      flipQuadEdges - true→reverse the direction of the first diagonal (default=true)
      flipTriangleWinding - true→left-hand winding of triangles (default=false)
      useDiamond - true→diagonals alternate on both horizontal axes (default=false)
      useZigzag - true→diagonals alternate on one horizontal axis (default=false)
  • Method Details

    • countColumns

      public int countColumns()
      Count how many columns are in the heightfield.
      Returns:
      the count (≥2)
    • countMeshVertices

      public int countMeshVertices()
      Count how many heights are in the heightfield.
      Returns:
      the count (≥4)
    • countRows

      public int countRows()
      Count how many rows are in the heightfield.
      Returns:
      the count (≥2)
    • upAxis

      public int upAxis()
      Return the index of the height axis.
      Returns:
      the axis index: 0→X, 1→Y, 2→Z
    • cloneFields

      public void cloneFields(com.jme3.util.clone.Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned shape into a deep-cloned one, using the specified Cloner and original to resolve copied fields.
      Specified by:
      cloneFields in interface com.jme3.util.clone.JmeCloneable
      Overrides:
      cloneFields in class CollisionShape
      Parameters:
      cloner - the Cloner that's cloning this shape (not null)
      original - the instance from which this shape was shallow-cloned (not null, unaffected)
    • read

      public void read(com.jme3.export.JmeImporter importer) throws IOException
      De-serialize the shape from the specified importer, for example when loading from a J3O file.
      Specified by:
      read in interface com.jme3.export.Savable
      Overrides:
      read in class CollisionShape
      Parameters:
      importer - (not null)
      Throws:
      IOException - from the importer
    • toSplittableShape

      public CollisionShape toSplittableShape()
      Approximate this shape with a splittable shape.
      Overrides:
      toSplittableShape in class CollisionShape
      Returns:
      a new splittable shape
    • write

      public void write(com.jme3.export.JmeExporter exporter) throws IOException
      Serialize this shape to the specified exporter, for example when saving to a J3O file.
      Specified by:
      write in interface com.jme3.export.Savable
      Overrides:
      write in class CollisionShape
      Parameters:
      exporter - (not null)
      Throws:
      IOException - from the exporter