reactphysics3d icon indicating copy to clipboard operation
reactphysics3d copied to clipboard

Auto destroy objects that are out of bounds

Open HugoPeters1024 opened this issue 5 years ago • 4 comments

Currently, there does not seem to be an option for a CollisionWorld to set a boundary frustum such that any bodies that exit that boundary are automatically destroyed.

I would love to try and make a PR for this but I was wondering if anyone could confirm that this actually makes sense as a feature

HugoPeters1024 avatar Apr 05 '20 16:04 HugoPeters1024

@DanielChappuis Maybe you can steer me in the the right direction on this. I could naively add a for loop over all bodies introducing another O(n) component which I can't imagine would change the upperbound of the CollisionWorld::update running time. However, I can imagine that using a default box body around the world and having a special case on any collision with it, could leverage some optimization tricks that are already present in the engine. I would love to hear your input.

HugoPeters1024 avatar Apr 06 '20 11:04 HugoPeters1024

Mmm, I'm noticing a problem with my idea. Since reactphysics3d creates and manages the pointers to any objects, users of the library might easily be catched of guard when the memory is suddenly freed. This would require some kind of callback to indicate that the object was destroyed but that does not sound like a nice situation at all...

HugoPeters1024 avatar May 11 '20 14:05 HugoPeters1024

Thanks for your feedback and the feature idea. Sorry for my late answer.

I am not sure it makes sense for ReactPhysics3D to take care of this internally right now and I think it can be implemented easily outside ReactPhysics3D by checking a given body if it exits a given frustrum and destroy that body in that case.

I would only implement this internally if most of the users need it because implementing this is not a one-liner. We need to have a flag on each body to know whether this feature is enabled or not on this body because we never want to check that for all the bodies of the world each frame in case the user only wants this feature for a single body. As you pointed out, we also need a callback when a body and all its colliders are destroyed from inside the engine. We also need to decide if the user is able to update the frustrum during the physics simulation or not and how to implement this.

Therefore, for the moment I would only try to implement this if many users ask for it as I don't see it as a priority right now but maybe in the future because I think it makes sense to take care of out-of-bounds bodies. For the moment, I think it's not that hard for the user to implement this outside the ReactPhysics3D engine.

DanielChappuis avatar May 11 '20 18:05 DanielChappuis

I fully agree with you, thanks for considering and sharing your thoughts. You don't have to keep this issue open for me, so feel free to close it.

HugoPeters1024 avatar May 11 '20 18:05 HugoPeters1024