Using Unity C#, I needed to procedurally create a mesh that may have several submeshes. Normally, after creating my vertex array, I'd make an array of lists where X is the submesh index (submesh index) and Y are triangles. Then, when constructing the mesh I'd simply walk through it horizontally and do mesh.SetTriangles(subMeshTris[subMeshIndex], subMeshIndex);
However, since job system forbids using nested arrays, I needed an alternative solution to represent which triangles belong to which submesh in a flat way.
I have two ideas so far:
To keep a parallel array of size
allTriangles.length / 6
that's gonna be a lookup for what submesh should those 6 triangles belong to, but I couldn't think of how to efficiently transform it into separate arrays so farTo keep some sort of layout info struct and insert triangles in specific indices instead of appending at the end. So if my info reads
Material 1 from 0 to 24, Material 2 from 24 to 36
and I need to insert another 6 triangles into material 1, I'd push them after element 23, then update the info struct so that it readsMaterial 1 from 0 to 30, Material 2 from 30 to 42
after which I should be able to copy the ranges
I'm currently working on idea #2 but decided to consult online in case I'm unaware of a more efficient approach.