private void InitAudioVisualizer() { totalTriangles = (int)sampleMesh.GetIndexCount(0) / 3; audioProfile.bandSize = totalTriangles; audioProcessor = new AudioProcessor(ref audioSource, ref audioProfile); MeshUtil.DeepCopyMesh(ref sampleMesh, out modifiedSampleMesh); audioVFX.SetMesh(VFXPropertyId.mesh_sampleMesh, modifiedSampleMesh); audioVFX.SetInt(VFXPropertyId.int_triangleCount, totalTriangles); modifiedSampleMesh.MarkDynamic(); meshFilter.mesh = modifiedSampleMesh; // transferring mesh data to native arrays to be processed parallely Mesh.MeshDataArray sampleMeshData = Mesh.AcquireReadOnlyMeshData(sampleMesh); normals = MeshUtil.NativeGetNormals(sampleMeshData[0], Allocator.Persistent); normals.AsReadOnly(); triangles = MeshUtil.NativeGetIndices(sampleMeshData[0], Allocator.Persistent); triangles.AsReadOnly(); vertices = MeshUtil.NativeGetVertices(sampleMeshData[0], Allocator.Persistent); // audio processing attributes samples = new NativeArray <float>(audioProfile.sampleSize, Allocator.Persistent); bandDistribution = new NativeArray <int>(audioProfile.bandSize + 1, Allocator.Persistent); bandDistribution.CopyFrom(audioProcessor.bandDistribution); bandDistribution.AsReadOnly(); prevBands = new NativeArray <float>(totalTriangles, Allocator.Persistent); prevBands.CopyFrom(prevBands); bandVelocities = new NativeArray <float>(totalTriangles, Allocator.Persistent); bandVelocities.CopyFrom(bandVelocities); sampleMeshData.Dispose(); if (seed != 0) { // if randomized is turned on int[] seqArray = MathUtil.GenerateSeqArray(totalTriangles); MathUtil.ShuffleArray <int>(ref seqArray, seed); // triangle indices NativeArray <int> trianglesCopy = new NativeArray <int>(triangles, Allocator.Temp); for (int s = 0; s < seqArray.Length; s++) { triangles[s * 3] = trianglesCopy[seqArray[s] * 3]; triangles[s * 3 + 1] = trianglesCopy[seqArray[s] * 3 + 1]; triangles[s * 3 + 2] = trianglesCopy[seqArray[s] * 3 + 2]; } trianglesCopy.Dispose(); } }