Best I’ve found is mostly covered here:
The building blocks of that is to compare two objects to see which should be in front. Them you’d sort all the objects with something called a topological sort. You only need to sort the objects visually overlapping each other.
As seen on that page there are some cases where the the sort will fail, so in those cases it would be good to be able to split the objects.
That said, depending on your levels, you can design around that to avoid the failing cases.
If everything is on the ground plane I think it should be possible to do something similar.