BatchNode - RayTrace Selection Problem

Hey Guys,

thanks for all your help with the BatchNode, still works pretty fast an awesome:

But now i have the problem that i can´t Select Geometrys out of the BatchNode via Raytrace like it worked before anymore.
Can´t find by search that someone has this problem before, thats why i started a new Thread, sorry for that. But i alos think is a interesting Problem other can benefit frome too.

Is there an alternative to the “standard” Raytrace-Selection-Procedure? My Code (only for the Raytrace, I have other Methods to iterate over the results to get the correct one) worked before when it was just a simply node:

private CollisionResults fireRaytrace() {
this.selectedSpatial = null;
// Reset results list.
CollisionResults results = new CollisionResults();
// Convert screen click
// to 3d position
Vector2f click2d = inputManager.getCursorPosition();
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalize();

	// Aim the ray from the clicked spot  forwards.
	Ray ray = new Ray(click3d, dir);

	// rootNode.collideWith(ray, results);
	staticbatchgeo.collideWith(ray, results);

	return results;


I mean its clear obvios that it cant work anymore, I mean the meshes are now one big Mesh. But is there any possibility to find out the “originally” Geometry/Spatial from the BatchNode over Raytrace? Or if not, some other ideas? Maybe with pure mathematics, my gamelogic is 2d so maybe just made an invisible plane or something and then calculate the entry point from the raytrace and recalculate the point to find out which object is at that position…or something like that…? :slight_smile:

Ok…I have a first “simplier” Idea, in my other Method i fire the Selection like that:

CollisionResults results = fireRaytrace();

	int selection = -1;
	Spatial selectedspatial = null;
	if (results.size() > 0) {
		Geometry target = results.getClosestCollision().getGeometry();
		System.out.println("target: " + target.getName());
		// Here comes the
		// action:
		Spatial selectedsp = target;

		try {

		// we look for the SpaceObject-Parent
		if (selectedsp != null) {
			while (!Character.isDigit(selectedsp.getName().charAt(0))) {
				selectedsp = selectedsp.getParent();

			selection = Integer.parseInt(selectedsp.getName());
			selectedspatial = selectedsp;
		catch (NullPointerException e) {
			System.out.println("AMonkeyFunctions: Selection NULL");


So instead of
Geometry target = results.getClosestCollision().getGeometry();
I could just use
And then calculate which Object from my World model (in my Case the correct “SpaceObject”) .

Just have to recalulate the Contact Point to the World Coordinates and should be able to find the correct one.

But have some limitations, only the first contact Point is Considered.

Have to try it out.

Some other better/simpler Idea? Or other Solutions?


Actually it should work as before.
The underlying geometries are not removed from the scenegraph, and still have their mesh data.
Are you sure you don’t have them in the collision result?
Actually that’s THE reason why I didn’t removed the underlying geometries.

@nehon said: Actually it should work as before. The underlying geometries are not removed from the scenegraph, and still have their mesh data. Are you sure you don't have them in the collision result? Actually that's THE reason why I didn't removed the underlying geometries.

for(Iterator itp = results.iterator(); itp.hasNext():wink:
CollisionResult result =;
Geometry geo = result.getGeometry();
System.out.println("geo: " + geo.getName());

With this Code there is always only one Geometry, its the Mesh from my BatchNode. No other result are in the CollisionResult.
How can I make an raytrace to the underlying Geometry?

Do you do the collision check directly on the batched geometry? Idk if you have to do it on a parent node so that the BatchNode can delegate?

If i make ths .colideWith on the RootNode he just find sometime the Big-Mesh serveral Times (according to the Angel). But still not that what i want.

But my other aproach with the getContactPoint will work atm too.

Did you by any chance removed the underlying geometries without rebatching?

I"ll make some test this week end and see if i can have the issue

No, I dont remove anything before batching.

Thanks for your Work, if your Tests are correct then it should be something in my code.

My Solution is working now but is a little bit inaccurate.

Is it possible to make invisible boxes for every position and make the raytraces against them?

@PhilipWilluweit said: Is it possible to make invisible boxes for every position and make the raytraces against them?
yes but...that's kind of what underlying geometries of the batch node are...

I don’t have this issue, i made a simple picking on testBatchNode and each time i got 2 collision results on the batch itself (in and out) and 2 collisions on the underlying geometry.
Could you wrap up a test case maybe?

1 Like

Hello nehon,

I am so Sorry for not 120% Belive you when you said it should still work.

Of course it does! A moment ago I found the issue. Simply just got the wrong Parent before… :slight_smile:

It works pretty well now like before. Now I am even more impressed by the BatchNode and your fantastic Work. Thanks a lot!

  • Philip
1 Like

Well picking could be better to be honest. Right now we keep all the sub geoms only for that.
I guess we could get rid of them and make some smart picking on the batch mesh.

1 Like