Class MeshCollisionShape

All Implemented Interfaces:
Comparable<NativePhysicsObject>

public class MeshCollisionShape extends CollisionShape
A mesh collision shape that uses a Bounding Value Hierarchy (BVH), based on Bullet's btBvhTriangleMeshShape. Not for use in dynamic bodies. Collisions between HeightfieldCollisionShape, MeshCollisionShape, and PlaneCollisionShape objects are never detected.

TODO add a shape based on btScaledBvhTriangleMeshShape

  • Field Details

    • maxSubmeshes

      public static final int maxSubmeshes
      maximum number of submeshes when compression is used
      See Also:
    • maxTrianglesInAnySubmesh

      public static final int maxTrianglesInAnySubmesh
      maximum number of triangles in any submesh when compression is used
      See Also:
    • logger2

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

    • MeshCollisionShape

      public MeshCollisionShape(boolean useCompression, Collection<IndexedMesh> meshes)
      Instantiate a shape from the specified collection of native meshes.
      Parameters:
      useCompression - true to use quantized AABB compression
      meshes - the collection on which to base the shape (must contain at least one triangle)
    • MeshCollisionShape

      public MeshCollisionShape(boolean useCompression, CompoundMesh mesh)
      Instantiate a shape based on the specified CompoundMesh.
      Parameters:
      useCompression - true to use quantized AABB compression
      mesh - the mesh on which to base the shape (not null, must contain at least one triangle, unaffected)
    • MeshCollisionShape

      public MeshCollisionShape(boolean useCompression, IndexedMesh... submeshes)
      Instantiate a shape from the specified native mesh(es).
      Parameters:
      useCompression - true to use quantized AABB compression
      submeshes - the mesh(es) on which to base the shape (must contain at least one triangle)
    • MeshCollisionShape

      public MeshCollisionShape(byte[] bvhBytes, IndexedMesh... submeshes)
      Instantiate a shape from the specified native mesh(es) and serialized BVH. The submeshes must be equivalent to those used to generate the BVH.
      Parameters:
      bvhBytes - the serialized BVH (not null, unaffected)
      submeshes - the mesh(es) on which to base the shape (must contain at least one triangle)
  • Method Details

    • countMeshTriangles

      public int countMeshTriangles()
      Count how many triangles are in the mesh.
      Returns:
      the count (≥0)
    • countMeshVertices

      public int countMeshVertices()
      Count how many vertices are in the mesh.
      Returns:
      the count (≥0)
    • countSubmeshes

      public int countSubmeshes()
      Count how many submeshes are in the mesh.
      Returns:
      the count (≥0)
    • getBvh

      public BoundingValueHierarchy getBvh()
      Access the bounding-value hierarchy.
      Returns:
      the pre-existing instance (not null)
    • getSubmesh

      public IndexedMesh getSubmesh(int index)
      Access the specified submesh.
      Parameters:
      index - the index of the desired submesh (in the order the submeshes were added, ≥0)
      Returns:
      the pre-existing instance (not null)
    • serializeBvh

      public byte[] serializeBvh()
      Serialize the BVH to a byte array.
      Returns:
      a new array containing a serialized version of the BVH
    • split

      public MeshCollisionShape[] split(Triangle splittingTriangle)
      Attempt to divide this shape into 2 shapes.
      Parameters:
      splittingTriangle - to define the splitting plane (in shape coordinates, not null, unaffected)
      Returns:
      a pair of mesh shapes, the first shape generated by the plane's minus side and the 2nd shape generated by its plus side; either shape may be null, indicating an empty shape
    • canSplit

      public boolean canSplit()
      Test whether this shape can be split by an arbitrary plane.
      Overrides:
      canSplit in class CollisionShape
      Returns:
      true
    • recalculateAabb

      protected void recalculateAabb()
      Recalculate this shape's bounding box if necessary.
      Overrides:
      recalculateAabb in class CollisionShape
    • setScale

      public void setScale(Vector3f scale)
      Alter the scale of this shape.

      Note that if shapes are shared (between collision objects and/or compound shapes) changes can have unintended consequences.

      Overrides:
      setScale in class CollisionShape
      Parameters:
      scale - the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))