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:
[java]
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;
}
[/java]
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…?
Ok…I have a first “simplier” Idea, in my other Method i fire the Selection like that:
[java]
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;
System.out.println("selected!");
}
}
catch (NullPointerException e) {
System.out.println("AMonkeyFunctions: Selection NULL");
}
}
[/java]
So instead of
[java]
Geometry target = results.getClosestCollision().getGeometry();
[/java]
I could just use
[java]
results.getClosestCollision().getContactPoint());
[/java]
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.
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?
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?
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.