Package com.jme3.bullet.collision.shapes
Class MeshCollisionShape
java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.collision.shapes.CollisionShape
com.jme3.bullet.collision.shapes.MeshCollisionShape
- All Implemented Interfaces:
com.jme3.export.Savable
,com.jme3.util.clone.JmeCloneable
,Cloneable
,Comparable<NativePhysicsObject>
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 Summary
Modifier and TypeFieldDescriptionstatic final Logger
message logger for this classstatic final int
maximum number of submeshes when compression is usedstatic final int
maximum number of triangles in any submesh when compression is usedFields inherited from class com.jme3.bullet.collision.shapes.CollisionShape
enableContactFilter, logger, margin, scale
Fields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN
-
Constructor Summary
ModifierConstructorDescriptionprotected
No-argument constructor needed by SavableClassUtil.MeshCollisionShape
(boolean useCompression, CompoundMesh mesh) Instantiate a shape based on the specified CompoundMesh.MeshCollisionShape
(boolean useCompression, IndexedMesh... submeshes) Instantiate a shape from the specified native mesh(es).MeshCollisionShape
(boolean useCompression, Collection<IndexedMesh> meshes) Instantiate a shape from the specified collection of native meshes.MeshCollisionShape
(byte[] bvhBytes, IndexedMesh... submeshes) Instantiate a shape from the specified native mesh(es) and serialized BVH.MeshCollisionShape
(com.jme3.scene.Mesh... jmeMeshes) Instantiate a shape based on the specified JME mesh(es), using quantized AABB compression.MeshCollisionShape
(com.jme3.scene.Mesh mesh, boolean useCompression) Instantiate a shape based on the specified JME mesh. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.int
Count how many triangles are in the mesh.int
Count how many vertices are in the mesh.int
Count how many submeshes are in the mesh.getBvh()
Access the bounding-value hierarchy.getSubmesh
(int index) Access the specified submesh.static boolean
Test whether bounding-value hierarchies will be serialized when serializing mesh collision shapes.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.byte[]
Serialize the BVH to a byte array.void
setScale
(com.jme3.math.Vector3f scale) Alter the scale of this shape.static void
setSerializingBvh
(boolean setting) Alter whether bounding-value hierarchies will be included when serializing mesh collision shapes.split
(com.jme3.math.Triangle splittingTriangle) Attempt to divide this shape into 2 shapes.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, canScale, copyShapeProperties, getDefaultMargin, getMargin, getScale, getScaleDp, getShapeType, getShapeType, isConcave, isContactFilterEnabled, isConvex, isInfinite, isNonMoving, isPolyhedral, jmeClone, maxRadius, nativeMargin, readShapeProperties, scaledVolume, setContactFilterEnabled, setDefaultMargin, setMargin, setNativeId, setScale, setUserIndex, setUserIndex2, toSplittableShape, 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
-
maxSubmeshes
public static final int maxSubmeshesmaximum number of submeshes when compression is used- See Also:
-
maxTrianglesInAnySubmesh
public static final int maxTrianglesInAnySubmeshmaximum number of triangles in any submesh when compression is used- See Also:
-
logger2
message logger for this class
-
-
Constructor Details
-
MeshCollisionShape
protected MeshCollisionShape()No-argument constructor needed by SavableClassUtil. -
MeshCollisionShape
Instantiate a shape from the specified collection of native meshes.- Parameters:
useCompression
- true to use quantized AABB compressionmeshes
- the collection on which to base the shape (must contain at least one triangle)
-
MeshCollisionShape
Instantiate a shape based on the specified CompoundMesh.- Parameters:
useCompression
- true to use quantized AABB compressionmesh
- the mesh on which to base the shape (not null, must contain at least one triangle, unaffected)
-
MeshCollisionShape
Instantiate a shape from the specified native mesh(es).- Parameters:
useCompression
- true to use quantized AABB compressionsubmeshes
- the mesh(es) on which to base the shape (must contain at least one triangle)
-
MeshCollisionShape
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)
-
MeshCollisionShape
public MeshCollisionShape(com.jme3.scene.Mesh... jmeMeshes) Instantiate a shape based on the specified JME mesh(es), using quantized AABB compression.- Parameters:
jmeMeshes
- the mesh(es) on which to base the shape (must contain at least one triangle, unaffected)
-
MeshCollisionShape
public MeshCollisionShape(com.jme3.scene.Mesh mesh, boolean useCompression) Instantiate a shape based on the specified JME mesh.- Parameters:
mesh
- the mesh on which to base the shape (must contain at least one triangle, unaffected)useCompression
- true to use quantized AABB compression
-
-
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
Access the bounding-value hierarchy.- Returns:
- the pre-existing instance (not null)
-
getSubmesh
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)
-
isSerializingBvh
public static boolean isSerializingBvh()Test whether bounding-value hierarchies will be serialized when serializing mesh collision shapes.- Returns:
- true if serializing hierarchies, otherwise false
-
serializeBvh
public byte[] serializeBvh()Serialize the BVH to a byte array.- Returns:
- a new array containing a serialized version of the BVH
-
setSerializingBvh
public static void setSerializingBvh(boolean setting) Alter whether bounding-value hierarchies will be included when serializing mesh collision shapes.- Parameters:
setting
- true to serialize hierarchies, false to slip serializing them (default=true)
-
split
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 classCollisionShape
- Returns:
- true
-
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)
-
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
-
setScale
public void setScale(com.jme3.math.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 classCollisionShape
- Parameters:
scale
- the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
-
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
-