- Home /
How to implement mesh collider decomposition for sandbox constructor like in Empyrion, Space Engineers, StarMade (detailed clarification inside)
Hello. Here is a complex question about algorithm. I do not ask for code solution. Only for some information about theory and a link where solution is described.
I will try to explain the question as better as possible.
First of all, check these games:
Empyrion - Galactic Survival
Space Engineers
StarMade
Interstellar Rift
Planet Nomads
Corneroids
Scrap mechanics
All of these games have shared feature: You can build a big, even huge moving vehicles using a blocks (like in Minecraft).
I am working on the same feature. I am already aware about "Combine Mesh" technique and know how to use it. However, I am not sure what to do with colliders for huge moving spaceships.
Many of us know "how to create Minecraft in Unity". This theme was very popular some time ago and we can found a lot of tutorials, even on YouTube about develop a Minecraft.
But Minecraft is simple, because its world is static, so you can use non-convex mesh collider to define collider of the terrain.
But if we are going to create a spaceship, situation is much harder, because ship is rigidbody, and as we know, non-convex mesh colliders is not allowed to use on non-kinematic rigidbody,
Therefore, spaceship should consists from many convex colliders which should be parented into the main object.
But look at the ships which built in the Space Engineers or Star Made, they are huge. It may consist up to millions blocks. Obviously, we can't just parent million of box colliders to rigidbody. it will drop FPS to 0.1 as soon as this space ship will begin to move.
It means that many blocks should be combined in the single mesh collider, but algorithm should combine only those block, which will result convex mesh collider.
So this is a main question. How to do this? I am tried to invent my own algorithm, and I designed several variants, however, I feels like I am tried to reinvent a wheel or bicycle.
Example of different results. So which algorithm is the most reliable and always will result 100% optimized result?
Because algorithm should be very very optimized, and as I listed above, there is already exist at least 7 other games which already have this feature. It means what all of those games most likely found a solution somewhere and just implemented it by instruction.
So this is my question. Maybe someone know about this solution and where I can find it?
I am tried to search for it, it was not too successful, however seems like it called "mesh decomposition". I found a few documents about it, but it is not related to Unity and very hard to understand, besides that, this algorithm more designed to work on any mesh, so it is not very fast. There is some solution in the Asset Store, for example this one, and I am already tested it for "block based" mesh, and it turned out too slow and result is incorrect. So approach should be different.
Also I had a thought - maybe those games somehow optimized own engine specially for this task? But fortunately, Empyrion is made on Unity, so it should be possible on Unity. Just look at those ships, they are huge. And this is made on Unity.
However, if we will look at StarMade, ships size will be even bigger. For example look at this. Imagine amount of box colliders for such construction. How this even possible?
Your answer
![](https://koobas.hobune.stream/wayback/20220612122435im_/https://answers.unity.com/themes/thub/images/avi.jpg)