Technically, the objects exist as sheer numbers.
What do I mean?
Well, all you need is the list of Mesh Name + Tranform.
If your model compiles that list out and passes it onto the other thread, then the non blocking thread can re-build the merged mesh one object at a time.
You will run into the same age all optimization dilemma…
So you talk to the game other thread once every component? Every 3? Wait for the whole thing?
(Every component defeata the purpuse so just a silly example really).
The other issue is the data from the transform and how that is stored.
Its a single object, but it contains location, rotation, and scale as V3s.
Say you use regular floats.
Thats 9 floats per component.
9 floats times a billion - and it takes longer to pass data to the other thread than writing the math out…
This situation is not a known object of the same general coordinates and shape, so simplifying the transform is probably not all that possible.
Maybe you can get Scale to be a single float if it is constrained, but loc and rot are still going to have to bead float3s…
I would suggest figuring out a batch number that works based on power of 2 values.
And making the system smart enough to time itself in order to x2 the batch size if the computing power of the system in use allows for it.
Faster CPU, better build times…
What you could do, is to maintain the build as a text file stored locally (at a minimum base64 encoded to prevent people editing).
Then you can just memory stream the document into the non-blocking thread instead of having to deal with batching and sorting ducks in a row…
Really, not sure that helps though, as like you said the meshes are in the game thread and have to be written out from there…
My 6th sense tells me it would probably end up being about the same as merging actors off the main thread direclty.
To be clear, the problem isnt really the merge or the write, its the loop of a billion possible instances that will cause a hang.
So then, back to batching, but off the main thread and ditectly into the mesh merge…
Unless you find an easy way to maintain both…
Like say, instead of writing to file all at once, you write to file with each piece the player places.
In the case the non game thread will then eventually just have all the data it needs and work… I think that may be the best approach here…
Ps, to be clear, write data to the file direclty. Its faster instead of converting to readable text, then encoding.
So instead of text, go with a .bin or similar format…