Picking using BoundingVolume

What is the most appropriate way to pick on just the bounding volumes of entities that exist in my pickable node? Using:

myPickableNode.collideWith(myRay, collisionResults);

will pick all the meshes that exist on my entites, this gives LOTS of results that must impact performance and I don’t really care about which part of the entity was hit only that it was hit in the first place (this is for mouse picking so that I can select an object in the graph).

I’m sure that this is simple and I am missing something.

Edit: I can achieve this in various ways, but everything I have tried seems overkill (which makes me think that I’m missing something simple).

Let me show what I have been trying:

I intend to have a game entity made up of lots of Geometry objects, lets say, it is a person with body, hair, shoes, etc… each being a geometry, what is the most appropriate way to create this object. Should I make my PersonEntity extend Node, Spatial, Geometry, or something else. Then I would manually set the bounds and override collideWith but then what do I set as the Geometry in CollisionResult.setGeometry(...). I feel almost as if I want to use CollisionResult.setSpatial(...) or CollisionResult.setCollidable(...) (for posterity: these don’t exist).

What I don’t want to have to do is get the collisions nearest result, determine that it is some entities hair then have to go find the entity that this hair belongs to.

I also don’t want to have to separate different parts of my entity on to different nodes.

What I want is a bounding box that covers the entity that I can pick against that I can then reference the entity from.

But this is an incredibly trivial bit of code, really… and fast.

If you don’t want to do mesh picking then you will have to do it yourself and implement your own collision objects and stuff. Since 99% of the collision results data is about picking a triangle it would be wasteful for you to reuse it for anything.

As an aside, characters made up of a dozen objects are not going to be very efficient in the long run.

My concern was in the performance of the actual picking, ie why do collisions for multiple complex objects when I only need to check collisions for one simple (bounding) object (for each entity), I’m not quite sure how collisions work for a mesh, does it iterate over every triangle? If so how fast is this if you have a decent amount of objects in the graph?

My entities are composite of a variety of meshes, so that I can dynamically switch out clothing/hair etc… is there a better way to create characters of this kind?

I was considering this I just didn’t want to waste my time on it if there was a simple option out-of-the-box.

Have you measured the performance and found that it is not enough for your use case? If so, have you identified the actual hot spot in the code that you would like to optimize? If not then spend your time setting up a test case relevant yo your game where you can measure this in a profiler. This is IMO the best way you can spend your time if you are worried about performance.

1 Like

No. It uses a BVH.

It already excludes checking things that don’t pass the bounds check.

Yes, but not with stock JME shaders… unless you want to write a texture atlas per combination.

As @jmaasing suggests, early optimization is the root of many evils.