Short intro:
I’ve written a prototype of minecraft-alike terrain generator. Terrain is plain-voxel-based - no marching cubes/etc stuff. It’s divided in 32x32 chunks (every chunk contains 32x32 matrix of RLE-compressed 1-dim voxel arrays) and generated on-the-fly. Every single chunk is polygonized into one or more meshes (to keep verts number less than 64k). A chunk gets polygonized and added to the scene as soon as distance between camera and that chunk is less than ‘view distance’. I’ve tested it with distances up to 16 chunks.
Most of calculations are performed in separate threads and all heap object are kept in object pools, so there were no lags.
The problem:
The problem is in physics. Physics is based on MeshColliders attached to each game object (i.e. mesh). As those meshes are terrain - colliders have to be static. So here is the problem - adding that many static mesh colliders takes 12 ms every frame in average. Once they’re added - everything is ok and is running smoothly at 80+ fps until new pack of terrain meshes are to be added to scene. Profiler shows that this ~12 ms is spent on ‘physics baking’.
The question:
Is there a way to ‘bake physics’ outside the main thread?
Maybe some other way to minimise impact of physics baking?
The only solution that I can think of now is to write my own ‘physics’ in separate thread, but I don’t really want to.