I'm looking for a 3D Java physics library which would be effective for objects which are complicated yet locally ordered: by which I mean the object is made up of local axis aligned boxes (see screenshot). This is for a game in which players can create blocky spaceships of arbitrary shapes and the game works out realistic collision shapes (allowing you to walk around inside it etc).

The physics engine I am looking for would have the following

  • Efficiently supports objects made of up to 100 subshapes (I already have code that finds the minimum number of boxes with which to represent the object and it usually ends up around 100 cuboids of varying sizes)
  • Allows those complex shapes to collide with each other (not just complex vs simple collisions)
  • Is a 3D library
  • Is in Java
  • Anything that uses a gift wrapping approach or similar that does not allow internal voids isn't suitable.
  • A Previous physics engine I've tried have used compound shapes where they simply tested each subshape vs each other subshape if a potential collision passed broadphase; 100 subshapes vs 100 subshapes quickly killed that approach (I'm looking at you JBullet).

enter image description here

I know this is possible; in part because I have already written it, however my version is very bare bones and I would like to change for a somewhat more professional physics engine if it were to be available.

I have previously used JBullet (within JMonkey), which is a Java port of Bullet Physics, and while it supported this it was not optimised for it and hated it; grinding to a halt when two such objects were near each other.

  • Not sure how you were using JBullet, but this might help.
    – House
    Feb 28 '14 at 21:05
  • @Byte56 That is interesting and looks like it might give considerably better performance than the compound collision shape approach Mar 13 '14 at 20:50
  • @Byte56 I'm remembering a lot of the problems I had last time with jbullet "java.lang.IllegalStateException: Dynamic rigidbody can not have mesh collision shape!". This is a problem I had because I'm not making a minecraft world (although it has obvious similarities) but dynamic blocky vs dynamic blocky. Something based on your non accepted answer might work, but the temporary cube approach isn't going to work for me (not efficiently at least) since theres not a single place where the cube could be known to move to ahead of time Mar 13 '14 at 21:55
  • Yep, the approach is only really suitable for non-moving objects. The mesh can be modified on the fly, but moving doesn't work so well. If you have objects like those in your image moving around and colliding, it's probably not going to work. The physics of dynamic, complex, concave objects are going to be pretty tough. Good luck with it. Your best bet is probably going to be finding some way to fake it.
    – House
    Mar 13 '14 at 22:07
  • @Byte56 It at least inspires me to keep making my own implementation a little less buggy; knowing there isn't an "off the shelf" solution that I'm just ignoring Mar 13 '14 at 22:29

Disclosure: I didn't try it, but I think this meets your criteria: https://github.com/tzaeschke/ode4j

It's a Java port of ODE, which claims to support collisions between most mesh combinations: https://www.ode-wiki.org/wiki/index.php?title=Manual:_All&printable=yes

My knowledge in this field and about your use case is too limited to say for sure, but this link contains a feature overview and a collision matrix that may help you decide if this does what you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.