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:
com.jme3.export.Savable
,com.jme3.util.clone.JmeCloneable
,Cloneable
,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, com.jme3.math.Transform transform) Add a child shape with the specified local transform.void
addChildShape
(CollisionShape childShape, com.jme3.math.Vector3f offset) Add a child shape with the specified local translation.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.boolean
canScale
(com.jme3.math.Vector3f scale) 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.void
cloneFields
(com.jme3.util.clone.Cloner cloner, Object original) Callback fromCloner
to convert this shallow-cloned shape into a deep-cloned one, using the specified Cloner and original to resolve copied fields.boolean[][]
connectivityMatrix
(CollisionSpace space) Generate a connectivity matrix for the children.void
correctAxes
(com.jme3.math.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.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.void
read
(com.jme3.export.JmeImporter importer) De-serialize the shape from the specified importer, for example when loading from a J3O file.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
rotate
(com.jme3.math.Matrix3f rotation) 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, com.jme3.math.Transform transform) Alter the local transform of the specified child CollisionShape.void
setScale
(com.jme3.math.Vector3f scale) Alter the scale of this shape and its children.split
(com.jme3.math.Triangle parentTriangle) Divide this shape into 2 compound shapes.Approximate this shape with a splittable shape.void
translate
(com.jme3.math.Vector3f amount) Apply the specified translation (in the parent's coordinate system) to each child.void
write
(com.jme3.export.JmeExporter exporter) Serialize this shape to the specified exporter, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.collision.shapes.CollisionShape
aabbCenter, aabbScaledVolume, boundingBox, boundingBox, copyShapeProperties, getDefaultMargin, getMargin, getScale, getScaleDp, getShapeType, getShapeType, isConcave, isContactFilterEnabled, isConvex, isInfinite, isNonMoving, isPolyhedral, jmeClone, nativeMargin, readShapeProperties, 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
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
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
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 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
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 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
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
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
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 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
-
cloneFields
Callback fromCloner
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 interfacecom.jme3.util.clone.JmeCloneable
- Overrides:
cloneFields
in classCollisionShape
- 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 classCollisionShape
- Returns:
- a distance estimate (in physics-space units, ≥0)
-
read
De-serialize the shape from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfacecom.jme3.export.Savable
- Overrides:
read
in classCollisionShape
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
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
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 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)
-
write
Serialize this shape to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfacecom.jme3.export.Savable
- Overrides:
write
in classCollisionShape
- Parameters:
exporter
- (not null)- Throws:
IOException
- from the exporter
-