Dynamic Mesh Performance

Per the request of Unity support, I am posting this in the forums to get more eye-balls on it.

I’ve been trying to make procedural lightning as fast as possible, and I have a great solution that moves all the animation, billboarding and glow of the lightning to the GPU, but the Mesh class is now the bottleneck as I have to use List.ToArray() to set vertices, colors, etc. Asset is here: http://u3d.as/f1c

I’ve also been implementing dynamic terrain and deformable objects, but the CPU is really a limitation because of the garbage collection and extra allocations when setting mesh vertices and other properties.

Getting every bit of performance is crucial, especially on mobile devices.

This issue / feature request was logged three years ago: http://feedback.unity3d.com/suggestions/allow-mesh-data-to-have-a-length but still does not seem to be implemented as of Unity 5.

There are hacks that can be done with unsafe code and modifying memory that assumes the location of the length integer, but this is far from ideal.

I hope you will consider adding overloads to the Mesh class for array and IList that take offset and length for all the mesh properties including vertices, indices, tangents, normals, uvs, uvs2, uvs3, uvs4 and color. It would also be nice to change vertices and normal to Vector4 so that the w value could be used in shaders for extra calculations.

Example:
Mesh.setVertices(IList vertices, int index, int length);
Mesh.setVertices(Vector4[ ] vertices, int index, int length);
Mesh.setNormals(IList normals, int index, int length);
Mesh.setNormals(Vector4[ ] normals, int index, int length);

etc…

Thank you for your consideration.

Also interested in this or something similar, being able to pass an array and a length allows to optimize memory allocation