Ray collision with terrain -> CastError (jME3 Bug)

Hi folks,

I’m continuing on my Total War terrain quest :stuck_out_tongue: and encountered an error while picking the terrain.

I’ve got this picking code in my onAction() method:


if (name.equals(“mouse_left”) && !pressed) {

CollisionResults results = new CollisionResults();

Ray ray = new Ray(cam.getLocation(), cam.getDirection());

map.terrain.collideWith(ray, results); // <- Exception is here

for (int i = 0; i < results.size(); i++) {

Vector3f pt = results.getCollision(i).getContactPoint();

map.selectTile((int) pt.x, (int) pt.z);




All the data is set up and I see the terrain. When I click on the terrain, I got the following error:


SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.ClassCastException: com.jme3.scene.Geometry cannot be cast to com.jme3.terrain.geomipmap.TerrainQuad

at com.jme3.terrain.geomipmap.TerrainQuad.findPick(TerrainQuad.java:1418)

at com.jme3.terrain.geomipmap.picking.BresenhamTerrainPicker.getTerrainIntersection(BresenhamTerrainPicker.java:78)

at com.jme3.terrain.geomipmap.TerrainQuad.collideWithRay(TerrainQuad.java:269)

at com.jme3.terrain.geomipmap.TerrainQuad.collideWith(TerrainQuad.java:1382)

at openwar.Main$1$1.onAction(Main.java:55)


Did you maybe attach other Geometry to the terrain? I think you should not do that as the Terrain expects only terrain quads as children.

Argh… that’s it. I had the skybox in my terrain node, duh. Thanks, normen! :slight_smile:

But maybe this use case could be changed in the core code so that it doesn’t happen to others aswell?

Yeah, guess there should be at least some warning or something.