fabmax / physx-jni

Java JNI bindings for Nvidia PhysX
MIT License
85 stars 8 forks source link

Support for variable (or larger) sized PxOverlapBuffers #50

Closed aecsocket closed 1 year ago

aecsocket commented 1 year ago

Currently the only (useful) object that can be passed into PxScene.overlap's PxOverlapCallback is a PxOverlapBuffer10, but as the name implies it can only store a buffer of 10 overlapping objects. From looking at the source this looks to be a limitation of "webidl" and template classes, however my use case requires storing more than 10 objects.

One possible solution is to create separate classes for handling more than 10 objects, but I don't know any reasonable number for this. However even better would be something that can support all of the objects passed back from PhysX (I don't understand the internals well so I don't know how hard this would be to implement). Similar solutions could be put in place for Raycast- and SweepBuffers.

For context, my use case is getting a collection of all objects which are near a specific point, which I do by performing an overlap of a sphere at that position. I don't need the distance to be exact, just any objects which are at least x units away from the point. If there is a better way to do this without an overlap scene query then I'd be happy to see it as well.

fabmax commented 1 year ago

Yes I agree, the hardcoded limit 10 objects is a bit of a limitation here. I think it should be relatively easy to add a few custom classes which implement the PxHitCallback interfaces and use a std::vector for storing an arbitrary number of results.

As a rather messy workaround you might be able to use the loop where you update all your object poses after each simulation step and compute the distance between each object position and your current query center point (collecting all obvjects, which are close enough).

aecsocket commented 1 year ago

I think that will be a good solution to the problem. Thanks for the alternative suggestion, that will work for mt use case for now.

fabmax commented 1 year ago

2.0.5-SNAPSHOT now contains three new query result classes PxOverlapResult, PxRaycastResult and PxSweepResult, which are backed by a std::vector. PxOverlapResult should do the trick for you.

aecsocket commented 1 year ago

This solution works really well, thanks!