I have a lot of meshes that need their bone weight offset in realtime (basically I wrote a skinned mesh combiner that adds geometry to their meshes, and appends bone weights accordingly).
The function runs extremely fast (under a millisecond) except for the part that accesses the mesh's bone weights. All it does is retrieve the original bone weight, offsets the value, and re-applies it. However, running that subroutine through each vertex takes over 30 milliseconds! (compared to under a millisecond to set all the verts, triangles, normals and uvs for the new mesh).
The pseudocode is as follow:
for (i = 0; i < mesh.vertices.length; i++)
{
mesh.boneWeights*.boneIndex0 += offset;*
*}*
*```*
*<p>Any way to speed this up?</p>*
I believe mesh.boneWeights *has to make a copy each time, so if you have 1000 vertices it will make 1000 copies. Try something like this and see if it works faster: