public void UpdateMeshLight(NativeList <Color32> colors) { var c32L = Pools.c32.Get(); UnsafeCopy.CopyColors(colors, c32L); filter.mesh.SetColors(c32L); Pools.c32.Return(c32L); }
// updates and returns nativeLists back to pools public static void UpdateMeshFilter(MeshFilter filter, NativeList <Vector3> vertices, NativeList <Vector3> normals, NativeList <Vector3> uvs, NativeList <Vector3> uv2s, NativeList <Color32> colors, NativeList <int> triangles) { filter.mesh.Clear(); if (triangles.Length < ushort.MaxValue) { filter.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt16; } else { filter.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } // old bad allocaty way //filter.mesh.vertices = vertices.ToArray(); //filter.mesh.SetUVs(0, new List<Vector3>(uvs.ToArray())); //filter.mesh.SetUVs(1, new List<Vector3>(uv2s.ToArray())); //filter.mesh.colors32 = colors.ToArray(); //filter.mesh.triangles = triangles.ToArray(); var vertL = Pools.v3.Get(); var normL = Pools.v3.Get(); var uvL = Pools.v3.Get(); var uv2L = Pools.v3.Get(); var colorL = Pools.c32.Get(); var intL = Pools.i.Get(); UnsafeCopy.CopyVectors(vertices, vertL); UnsafeCopy.CopyVectors(normals, normL); UnsafeCopy.CopyVectors(uvs, uvL); UnsafeCopy.CopyVectors(uv2s, uv2L); UnsafeCopy.CopyColors(colors, colorL); UnsafeCopy.CopyIntegers(triangles, intL); filter.mesh.SetVertices(vertL); filter.mesh.SetNormals(normL); filter.mesh.SetUVs(0, uvL); filter.mesh.SetUVs(1, uv2L); filter.mesh.SetColors(colorL); filter.mesh.SetTriangles(intL, 0); Pools.v3.Return(vertL); Pools.v3.Return(normL); Pools.v3.Return(uvL); Pools.v3.Return(uv2L); Pools.c32.Return(colorL); Pools.i.Return(intL); // and then return the native lists too Pools.v3N.Return(vertices); Pools.v3N.Return(normals); Pools.v3N.Return(uvs); Pools.v3N.Return(uv2s); Pools.c32N.Return(colors); Pools.intN.Return(triangles); }