Class DebugShapeFactory

java.lang.Object
com.jme3.bullet.util.DebugShapeFactory

public final class DebugShapeFactory extends Object
A utility class to generate debug meshes for Bullet collision shapes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    specify high-res debug meshes for convex shapes (up to 256 vertices)
    static final Logger
    message logger for this class
    static final int
    specify low-res debug meshes for convex shapes (up to 42 vertices)
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Forget all previously generated debug meshes.
    static int
    Count how many debug meshes are cached.
    debugVertices(CollisionShape shape, int meshResolution)
    Determine vertex locations for the specified collision shape.
    static com.jme3.math.Vector3f[]
    footprint(CollisionShape shape, com.jme3.math.Transform shapeToWorld, int meshResolution)
    Estimate the footprint of the specified (non-compound, non-plane) shape.
    static com.jme3.scene.Mesh
    For compatibility with the jme3-jbullet library.
    static com.jme3.scene.Spatial
    Create a Spatial for visualizing the specified collision object.
    static com.jme3.scene.Spatial
    For compatibility with the jme3-jbullet library.
    getDebugTriangles(CollisionShape shape, int meshResolution)
    Generate vertex locations for triangles to visualize the specified collision shape.
    static void
    Install the specified MeshCustomizer, replacing any customizer previously installed.
    static float
    maxDistance(CollisionShape shape, com.jme3.math.Transform shapeToWorld, int meshResolution)
    Estimate how far the specified (non-compound, non-plane) shape extends from some origin, based on its debug mesh.
    static void
    removeShapeFromCache(long shapeId)
    Forget all previously generated debug meshes for the identified shape.
    static void
    setIndexBuffers(boolean setting)
    Alter whether to index new debug meshes.
    static void
    setIndexBuffers(int maxVertices)
    Alter whether to index new debug meshes.
    static float
    volumeConvex(ConvexShape shape, int meshResolution)
    Calculate the volume of a debug mesh for the specified convex shape.

    Methods inherited from class java.lang.Object

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

    • highResolution

      public static final int highResolution
      specify high-res debug meshes for convex shapes (up to 256 vertices)
      See Also:
    • lowResolution

      public static final int lowResolution
      specify low-res debug meshes for convex shapes (up to 42 vertices)
      See Also:
    • logger

      public static final Logger logger
      message logger for this class
  • Method Details

    • clearCache

      public static void clearCache()
      Forget all previously generated debug meshes.
    • countCachedMeshes

      public static int countCachedMeshes()
      Count how many debug meshes are cached.
      Returns:
      the count (≥0)
    • debugVertices

      public static FloatBuffer debugVertices(CollisionShape shape, int meshResolution)
      Determine vertex locations for the specified collision shape. Note: recursive!
      Parameters:
      shape - the input shape (not null, unaffected)
      meshResolution - (0=low, 1=high)
      Returns:
      a new, unflipped, direct buffer full of scaled shape coordinates (capacity a multiple of 3)
    • footprint

      public static com.jme3.math.Vector3f[] footprint(CollisionShape shape, com.jme3.math.Transform shapeToWorld, int meshResolution)
      Estimate the footprint of the specified (non-compound, non-plane) shape. The shape's scale and margin are taken into account, but not its debug-mesh resolution.
      Parameters:
      shape - (not null, not compound, not plane, unaffected)
      shapeToWorld - the world transform of the collision object (not null, unaffected)
      meshResolution - (0=low, 1=high)
      Returns:
      a new array of corner locations (in world coordinates)
    • getDebugMesh

      public static com.jme3.scene.Mesh getDebugMesh(CollisionShape shape)
      For compatibility with the jme3-jbullet library.
      Parameters:
      shape - the shape to visualize (not null, not compound, not plane, unaffected)
      Returns:
      a new Triangles-mode Mesh (no indices, no normals)
    • getDebugShape

      public static com.jme3.scene.Spatial getDebugShape(CollisionShape shape)
      For compatibility with the jme3-jbullet library.
      Parameters:
      shape - the shape to visualize (may be null, unaffected)
      Returns:
      a new Spatial or null
    • getDebugShape

      public static com.jme3.scene.Spatial getDebugShape(PhysicsCollisionObject pco)
      Create a Spatial for visualizing the specified collision object.

      This is mostly used internally. To enable debug visualization, use BulletAppState.setDebugEnabled(boolean).

      Parameters:
      pco - the object to visualize (not null, unaffected)
      Returns:
      a new tree of nodes and geometries, or null
    • getDebugTriangles

      public static FloatBuffer getDebugTriangles(CollisionShape shape, int meshResolution)
      Generate vertex locations for triangles to visualize the specified collision shape. Note: recursive!
      Parameters:
      shape - the shape to visualize (not null, unaffected)
      meshResolution - (0=low, 1=high)
      Returns:
      a new, unflipped, direct buffer full of scaled shape coordinates (capacity a multiple of 9)
    • installMeshCustomizer

      public static void installMeshCustomizer(MeshCustomizer customizer)
      Install the specified MeshCustomizer, replacing any customizer previously installed.
      Parameters:
      customizer - the desired customizer, or null for none
    • maxDistance

      public static float maxDistance(CollisionShape shape, com.jme3.math.Transform shapeToWorld, int meshResolution)
      Estimate how far the specified (non-compound, non-plane) shape extends from some origin, based on its debug mesh. The shape's scale and margin are taken into account, but not its debug-mesh resolution.
      Parameters:
      shape - (not null, not compound, not plane, unaffected)
      shapeToWorld - the transform to apply to debug-mesh coordinates (not null, unaffected)
      meshResolution - (0=low, 1=high)
      Returns:
      the maximum length of the transformed vertex locations (≥0)
    • removeShapeFromCache

      public static void removeShapeFromCache(long shapeId)
      Forget all previously generated debug meshes for the identified shape.
      Parameters:
      shapeId - the ID of the shape to remove
    • setIndexBuffers

      public static void setIndexBuffers(boolean setting)
      Alter whether to index new debug meshes. (Doesn't affect cached meshes or plane shapes.) Indexing might boost performance when there are many small meshes; it isn't recommended for very large meshes.
      Parameters:
      setting - true→always index, false→never index
    • setIndexBuffers

      public static void setIndexBuffers(int maxVertices)
      Alter whether to index new debug meshes. (Doesn't affect cached meshes or plane shapes.) Indexing might boost performance when there are many small meshes; it isn't recommended for very large meshes.
      Parameters:
      maxVertices - the largest mesh to be indexed (vertex count, ≥-1, default=6000)
    • volumeConvex

      public static float volumeConvex(ConvexShape shape, int meshResolution)
      Calculate the volume of a debug mesh for the specified convex shape. The shape's scale and margin are taken into account, but not its debug-mesh resolution.
      Parameters:
      shape - the convex shape to analyze (not null, unaffected)
      meshResolution - (0=low, 1=high)
      Returns:
      the scaled volume (in physics-space units cubed, ≥0)