Package com.jme3.bullet.collision.shapes
Class CompoundCollisionShape
java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.collision.shapes.CollisionShape
com.jme3.bullet.collision.shapes.CompoundCollisionShape
- All Implemented Interfaces:
Comparable<NativePhysicsObject>
A collision shape formed by combining child shapes, based on Bullet's
btCompoundShape
.-
Field Summary
Fields inherited from class com.jme3.bullet.collision.shapes.CollisionShape
enableContactFilter, logger, margin, scale
Fields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN
-
Constructor Summary
ConstructorDescriptionInstantiate an empty compound shape (with an initial capacity of 6, dynamic AABB, and no children).CompoundCollisionShape
(int initialCapacity) Instantiate an empty compound shape with the specified initial capacity (and dynamic AABB and no children). -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChildShape
(CollisionShape childShape) Add a child shape without transforming its coordinates.void
addChildShape
(CollisionShape childShape, float offsetX, float offsetY, float offsetZ) Add a child shape with the specified local translation.void
addChildShape
(CollisionShape shape, Transform transform) Add a child shape with the specified local transform.void
addChildShape
(CollisionShape childShape, Vector3f offset) Add a child shape with the specified local translation.void
addChildShape
(CollisionShape childShape, Vector3f offset, Matrix3f rotation) Add a child shape with the specified local translation and orientation.boolean
Test whether the specified scale factors can be applied to this shape.boolean
canSplit()
Test whether this shape can be split by an arbitrary plane.boolean[][]
connectivityMatrix
(CollisionSpace space) Generate a connectivity matrix for the children.void
correctAxes
(Transform paTransform) Apply the inverse of the specified Transform to each child shape.int
Count the child shapes.int
countGroups
(CollisionSpace space, int[] storeMap) Enumerate disconnected groups of connected children.int
findIndex
(CollisionShape childShape) Find the first child with the specified shape.Enumerate the child shapes.float
Estimate how far the shape extends from its origin.principalAxes
(FloatBuffer masses, Transform storeTransform, 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.protected void
Recalculate this shape's bounding box if necessary.void
removeChildShape
(CollisionShape childShape) Purge all references to the specified child shape from this shape.void
Apply the specified rotation (in the parent's coordinate system) to each child.float
Estimate the volume of this shape, including scale and margin.void
setChildTransform
(CollisionShape childShape, Transform transform) Alter the local transform of the specified child CollisionShape.void
Alter the scale of this shape and its children.Divide this shape into 2 compound shapes.Approximate this shape with a splittable shape.void
Apply the specified translation (in the parent's coordinate system) to each child.Methods inherited from class com.jme3.bullet.collision.shapes.CollisionShape
aabbCenter, boundingBox, boundingBox, getDefaultMargin, getMargin, getScale, getScaleDp, getShapeType, getShapeType, isConcave, isContactFilterEnabled, isConvex, isInfinite, isNonMoving, isPolyhedral, nativeMargin, setContactFilterEnabled, setDefaultMargin, setMargin, setNativeId, setScale, setUserIndex, setUserIndex2, toString, updateScale, userIndex, userIndex2
Methods inherited from class com.jme3.bullet.NativePhysicsObject
compareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeIdNotTracked, unassignNativeObject
-
Field Details
-
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
Add a child shape without transforming its coordinates.- Parameters:
childShape
- the child shape to add (not null, not a compound shape, alias created)
-
addChildShape
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 originoffsetY
- the local Y coordinate of the child shape's originoffsetZ
- the local Z coordinate of the child shape's origin
-
addChildShape
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
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
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
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
Apply the inverse of the specified Transform to each child shape.- Parameters:
paTransform
- the Transform to un-apply, typically one obtained usingprincipalAxes(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
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 spacestoreMap
- 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
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
Enumerate the child shapes.- Returns:
- a new array of pre-existing child shapes (not null)
-
principalAxes
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 usingcorrectAxes(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
Purge all references to the specified child shape from this shape.- Parameters:
childShape
- the collision shape to remove (not null)
-
rotate
Apply the specified rotation (in the parent's coordinate system) to each child.- Parameters:
rotation
- the rotation to apply (not null, unaffected)
-
setChildTransform
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
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
Apply the specified translation (in the parent's coordinate system) to each child.- Parameters:
amount
- the translation to apply (not null, unaffected)
-
canScale
Test whether the specified scale factors can be applied to this shape.- Overrides:
canScale
in classCollisionShape
- 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 classCollisionShape
- Returns:
- true if splittable, false otherwise
-
maxRadius
public float maxRadius()Estimate how far the shape extends from its origin.- Overrides:
maxRadius
in classCollisionShape
- Returns:
- a distance estimate (in physics-space units, ≥0)
-
recalculateAabb
protected void recalculateAabb()Recalculate this shape's bounding box if necessary.- Overrides:
recalculateAabb
in classCollisionShape
-
scaledVolume
public float scaledVolume()Estimate the volume of this shape, including scale and margin.- Overrides:
scaledVolume
in classCollisionShape
- Returns:
- the volume (in physics-space units cubed, ≥0)
-
setScale
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 classCollisionShape
- Parameters:
scale
- the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
-
toSplittableShape
Approximate this shape with a splittable shape.- Overrides:
toSplittableShape
in classCollisionShape
- Returns:
- a splittable shape (either this shape or a new one)
-