Package com.jme3.bullet.collision.shapes
Class HeightfieldCollisionShape
java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.collision.shapes.CollisionShape
com.jme3.bullet.collision.shapes.HeightfieldCollisionShape
- All Implemented Interfaces:
com.jme3.export.Savable,com.jme3.util.clone.JmeCloneable,Cloneable,Comparable<NativePhysicsObject>
A collision shape for terrain defined by a matrix of height values, based on
Bullet's
btHeightfieldTerrainShape. Should be more efficient than an
equivalent MeshCollisionShape. Not for use in dynamic bodies.
Collisions between HeightfieldCollisionShape,
MeshCollisionShape, and PlaneCollisionShape objects are never
detected.-
Field Summary
FieldsFields inherited from class com.jme3.bullet.collision.shapes.CollisionShape
enableContactFilter, logger, margin, scaleFields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNo-argument constructor needed by SavableClassUtil.HeightfieldCollisionShape(float[] heightArray) Instantiate a square shape for the specified array of heights.HeightfieldCollisionShape(float[] heightArray, com.jme3.math.Vector3f scale) Instantiate a square shape for the specified height array and scale vector.HeightfieldCollisionShape(int stickLength, int stickWidth, float[] heightmap, com.jme3.math.Vector3f scale, int upAxis, boolean flipQuadEdges, boolean flipTriangleWinding, boolean useDiamond, boolean useZigzag) Instantiate a rectangular shape for the specified parameters.HeightfieldCollisionShape(com.jme3.terrain.heightmap.HeightMap heightMap) Instantiate a square shape for the specified HeightMap.HeightfieldCollisionShape(com.jme3.terrain.Terrain terrain, com.jme3.math.Vector3f scale) Instantiate a square shape for the specified terrain and scale vector. -
Method Summary
Modifier and TypeMethodDescriptionvoidcloneFields(com.jme3.util.clone.Cloner cloner, Object original) Callback fromClonerto convert this shallow-cloned shape into a deep-cloned one, using the specified Cloner and original to resolve copied fields.intCount how many columns are in the heightfield.intCount how many heights are in the heightfield.intCount how many rows are in the heightfield.voidread(com.jme3.export.JmeImporter importer) De-serialize the shape from the specified importer, for example when loading from a J3O file.Approximate this shape with a splittable shape.intupAxis()Return the index of the height axis.voidwrite(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, canSplit, copyShapeProperties, getDefaultMargin, getMargin, getScale, getScaleDp, getShapeType, getShapeType, isConcave, isContactFilterEnabled, isConvex, isInfinite, isNonMoving, isPolyhedral, jmeClone, maxRadius, nativeMargin, readShapeProperties, recalculateAabb, scaledVolume, setContactFilterEnabled, setDefaultMargin, setMargin, setNativeId, setScale, setScale, setUserIndex, setUserIndex2, toString, updateScale, userIndex, userIndex2Methods 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
-
HeightfieldCollisionShape
protected HeightfieldCollisionShape()No-argument constructor needed by SavableClassUtil. -
HeightfieldCollisionShape
public HeightfieldCollisionShape(float[] heightArray) Instantiate a square shape for the specified array of heights.- Parameters:
heightArray- (not null, length≥4, length a perfect square, unaffected)
-
HeightfieldCollisionShape
public HeightfieldCollisionShape(com.jme3.terrain.heightmap.HeightMap heightMap) Instantiate a square shape for the specified HeightMap. If the HeightMap isn't populated, invoke its load() method.- Parameters:
heightMap- (not null, size ≥ 2)
-
HeightfieldCollisionShape
public HeightfieldCollisionShape(float[] heightArray, com.jme3.math.Vector3f scale) Instantiate a square shape for the specified height array and scale vector.- Parameters:
heightArray- (not null, length≥4, length a perfect square, unaffected)scale- the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
-
HeightfieldCollisionShape
public HeightfieldCollisionShape(com.jme3.terrain.Terrain terrain, com.jme3.math.Vector3f scale) Instantiate a square shape for the specified terrain and scale vector.- Parameters:
terrain- (not null, size ≥2, unaffected)scale- the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
-
HeightfieldCollisionShape
public HeightfieldCollisionShape(int stickLength, int stickWidth, float[] heightmap, com.jme3.math.Vector3f scale, int upAxis, boolean flipQuadEdges, boolean flipTriangleWinding, boolean useDiamond, boolean useZigzag) Instantiate a rectangular shape for the specified parameters.- Parameters:
stickLength- the number of rows in the heightfield (>1)stickWidth- number of columns in the heightfield (>1)heightmap- (not null, length≥stickLength*stickWidth, unaffected)scale- the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))upAxis- the height-axis index (0→X, 1→Y, 2→Z, default=1)flipQuadEdges- true→reverse the direction of the first diagonal (default=true)flipTriangleWinding- true→left-hand winding of triangles (default=false)useDiamond- true→diagonals alternate on both horizontal axes (default=false)useZigzag- true→diagonals alternate on one horizontal axis (default=false)
-
-
Method Details
-
countColumns
public int countColumns()Count how many columns are in the heightfield.- Returns:
- the count (≥2)
-
countMeshVertices
public int countMeshVertices()Count how many heights are in the heightfield.- Returns:
- the count (≥4)
-
countRows
public int countRows()Count how many rows are in the heightfield.- Returns:
- the count (≥2)
-
upAxis
public int upAxis()Return the index of the height axis.- Returns:
- the axis index: 0→X, 1→Y, 2→Z
-
cloneFields
Callback fromClonerto convert this shallow-cloned shape into a deep-cloned one, using the specified Cloner and original to resolve copied fields.- Specified by:
cloneFieldsin interfacecom.jme3.util.clone.JmeCloneable- Overrides:
cloneFieldsin 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:
readin interfacecom.jme3.export.Savable- Overrides:
readin classCollisionShape- Parameters:
importer- (not null)- Throws:
IOException- from the importer
-
toSplittableShape
Approximate this shape with a splittable shape.- Overrides:
toSplittableShapein classCollisionShape- Returns:
- a new splittable shape
-
write
Serialize this shape to the specified exporter, for example when saving to a J3O file.- Specified by:
writein interfacecom.jme3.export.Savable- Overrides:
writein classCollisionShape- Parameters:
exporter- (not null)- Throws:
IOException- from the exporter
-