Class CompoundCollisionShape

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

public class CompoundCollisionShape extends CollisionShape
A collision shape formed by combining child shapes, based on Bullet's btCompoundShape.
  • Field Details

    • logger2

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

    • CompoundCollisionShape

      public CompoundCollisionShape()
      Instantiate an empty compound shape (with an initial capacity of 6, dynamic AABB, and no children).
    • CompoundCollisionShape

      public CompoundCollisionShape(int initialCapacity)
      Instantiate an empty compound shape with the specified initial capacity (and dynamic AABB and no children).
      Parameters:
      initialCapacity - the number of children to allocate (>0, default=6)
  • Method Details

    • addChildShape

      public void addChildShape(CollisionShape childShape)
      Add a child shape without transforming its coordinates.
      Parameters:
      childShape - the child shape to add (not null, not a compound shape, alias created)
    • addChildShape

      public void addChildShape(CollisionShape childShape, float offsetX, float offsetY, float offsetZ)
      Add a child shape with the specified local translation.
      Parameters:
      childShape - the child shape to add (not null, not a compound shape, alias created)
      offsetX - the local X coordinate of the child shape's origin
      offsetY - the local Y coordinate of the child shape's origin
      offsetZ - the local Z coordinate of the child shape's origin
    • addChildShape

      public void addChildShape(CollisionShape childShape, com.jme3.math.Vector3f offset)
      Add a child shape with the specified local translation.
      Parameters:
      childShape - the child shape to add (not null, not a compound shape, alias created)
      offset - the local coordinates of the child shape's origin (not null, unaffected)
    • addChildShape

      public void addChildShape(CollisionShape childShape, com.jme3.math.Vector3f offset, com.jme3.math.Matrix3f rotation)
      Add a child shape with the specified local translation and orientation.
      Parameters:
      childShape - the child shape to add (not null, not a compound shape, alias created)
      offset - the local coordinates of the child shape's origin (not null, unaffected)
      rotation - the local orientation of the child shape (not null, unaffected)
    • addChildShape

      public void addChildShape(CollisionShape shape, com.jme3.math.Transform transform)
      Add a child shape with the specified local transform. The transform's scale is ignored.
      Parameters:
      shape - the child shape to add (not null, not a compound shape, alias created)
      transform - the local transform of the child shape (not null, unaffected)
    • connectivityMatrix

      public boolean[][] connectivityMatrix(CollisionSpace space)
      Generate a connectivity matrix for the children.
      Parameters:
      space - the space to use for tests, or null to create a new space
      Returns:
      an N-by-N matrix where e(i,j) is true if and only if the ith child intersects with the jth child
    • correctAxes

      public void correctAxes(com.jme3.math.Transform paTransform)
      Apply the inverse of the specified Transform to each child shape.
      Parameters:
      paTransform - the Transform to un-apply, typically one obtained using principalAxes(java.nio.FloatBuffer, com.jme3.math.Transform, com.jme3.math.Vector3f) (not null, unaffected, scale=1)
    • countChildren

      public int countChildren()
      Count the child shapes.
      Returns:
      the count (≥0)
    • countGroups

      public int countGroups(CollisionSpace space, int[] storeMap)
      Enumerate disconnected groups of connected children.

      A graph-coloring algorithm is applied to the connectivity matrix. Each node in the graph represents a child, and each color represents a group of connected children.

      Parameters:
      space - the space to use for tests, or null to create a new space
      storeMap - storage for the mapping from children to groups (not null, length = number of children, modified)
      Returns:
      the number of groups found (≥0, ≤number of children)
    • findIndex

      public int findIndex(CollisionShape childShape)
      Find the first child with the specified shape.
      Parameters:
      childShape - the shape to search for (unaffected)
      Returns:
      the index of the child if found, otherwise -1
    • listChildren

      public ChildCollisionShape[] listChildren()
      Enumerate the child shapes.
      Returns:
      a new array of pre-existing child shapes (not null)
    • principalAxes

      public com.jme3.math.Transform principalAxes(FloatBuffer masses, com.jme3.math.Transform storeTransform, com.jme3.math.Vector3f storeInertia)
      Calculates the coordinate transform to be applied to a rigid body in order for this shape to be centered on its center of mass and its principal axes to coincide with its local axes. Apply the inverse of this transform to each child shape using correctAxes(com.jme3.math.Transform). The resulting moment of inertia is also calculated.
      Parameters:
      masses - the relative mass for each child shape (not null, direct, all elements >0)
      storeTransform - storage for the transform (modified if not null)
      storeInertia - storage for the moment of inertia (not null, modified)
      Returns:
      a coordinate transform to apply to the collision object (either storeTransform or a new instance, not null, scale=1)
    • removeChildShape

      public void removeChildShape(CollisionShape childShape)
      Purge all references to the specified child shape from this shape.
      Parameters:
      childShape - the collision shape to remove (not null)
    • rotate

      public void rotate(com.jme3.math.Matrix3f rotation)
      Apply the specified rotation (in the parent's coordinate system) to each child.
      Parameters:
      rotation - the rotation to apply (not null, unaffected)
    • setChildTransform

      public void setChildTransform(CollisionShape childShape, com.jme3.math.Transform transform)
      Alter the local transform of the specified child CollisionShape. The transform's scale is ignored. Assumes that no 2 children refer to the same shape!
      Parameters:
      childShape - the child's CollisionShape (not null, unaffected)
      transform - the desired Transform (not null, unaffected)
    • split

      public CompoundCollisionShape[] split(com.jme3.math.Triangle parentTriangle)
      Divide this shape into 2 compound shapes. Each of this shape's children must be based on a splittable shape.
      Parameters:
      parentTriangle - a triangle that defines the splitting plane (in the parent's shape coordinates, not null, unaffected)
      Returns:
      a pair of shapes, not centered, the first element on the plane's minus side and the 2nd element on its plus side; either element may be null, indicating an empty shape
    • translate

      public void translate(com.jme3.math.Vector3f amount)
      Apply the specified translation (in the parent's coordinate system) to each child.
      Parameters:
      amount - the translation to apply (not null, unaffected)
    • canScale

      public boolean canScale(com.jme3.math.Vector3f scale)
      Test whether the specified scale factors can be applied to this shape.
      Overrides:
      canScale in class CollisionShape
      Parameters:
      scale - the desired scale factor for each local axis (may be null, unaffected)
      Returns:
      true if applicable, otherwise false
    • canSplit

      public boolean canSplit()
      Test whether this shape can be split by an arbitrary plane.
      Overrides:
      canSplit in class CollisionShape
      Returns:
      true if splittable, false otherwise
    • 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)
    • maxRadius

      public float maxRadius()
      Estimate how far the shape extends from its origin.
      Overrides:
      maxRadius in class CollisionShape
      Returns:
      a distance estimate (in physics-space units, ≥0)
    • 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
    • recalculateAabb

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

      public float scaledVolume()
      Estimate the volume of this shape, including scale and margin.
      Overrides:
      scaledVolume in class CollisionShape
      Returns:
      the volume (in physics-space units cubed, ≥0)
    • setScale

      public void setScale(com.jme3.math.Vector3f scale)
      Alter the scale of this shape and its children. CAUTION: Not all shapes can be scaled arbitrarily.

      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))
    • toSplittableShape

      public CollisionShape toSplittableShape()
      Approximate this shape with a splittable shape.
      Overrides:
      toSplittableShape in class CollisionShape
      Returns:
      a splittable shape (either this shape or a new one)
    • 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