public static CollisionShape createMeshShape(Spatial spatial) {
        if (spatial instanceof TerrainQuad) {
            TerrainQuad terrain = (TerrainQuad) spatial;
            return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale());
        } else if (spatial instanceof TerrainPatch) {
            TerrainPatch terrain = (TerrainPatch) spatial;
            return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale());
        } else if (spatial instanceof Geometry) {
            return createSingleMeshShape((Geometry) spatial, spatial);
        } else if (spatial instanceof Node) {
            return createMeshCompoundShape((Node) spatial);
        } else {
            throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!");
        }
    }
Create a mesh shape for the given Spatial.
<p>
This type of collision shape is mesh-accurate and meant for immovable
"world objects". Examples include terrain, houses or whole shooter
levels.
<p>
Objects with "mesh" type collision shape will not collide with each
other.
<p>
Creates a HeightfieldCollisionShape if the supplied spatial is a
TerrainQuad.

@param spatial the spatial on which to base the shape (not null)
@return A MeshCollisionShape or a CompoundCollisionShape with
MeshCollisionShapes as children if the supplied spatial is a Node. A
HeightfieldCollisionShape if a TerrainQuad was supplied.
jme3-jbullet/src/main/java/com/jme3/bullet/util/CollisionShapeFactory.java