static void Build2(int gridSize, out VertexModifier vertexModifier, out Dictionary<string, MeshRebuilder> rebuilders, out CostMetricMeasurer costMeasurer, out MeshDisposer disposer) { List<Vector3> vertices = new List<Vector3>(); for (int y = 0; y < gridSize; ++y) for (int x = 0; x < gridSize; ++x) vertices.Add(new Vector3(2 * x, 0, 2 * y)); List<int> triangles = new List<int>(); for (int y = 0; y < gridSize - 1; ++y) for (int x = 0; x < gridSize - 1; ++x) { triangles.Add(gridSize * (y) + (x)); triangles.Add(gridSize * (y) + (x + 1)); triangles.Add(gridSize * (y + 1) + (x + 1)); triangles.Add(gridSize * (y) + (x)); triangles.Add(gridSize * (y + 1) + (x + 1)); triangles.Add(gridSize * (y + 1) + (x)); } var physicsMesh = new Mesh(vertices.ToArray(), triangles.ToArray()); vertexModifier = (Random random) => { for (int vertexIndex = 0; vertexIndex < physicsMesh.Vertices.Length; ++vertexIndex) physicsMesh.Vertices[vertexIndex].Y = (float)random.NextDouble() * 2; }; rebuilders = new Dictionary<string, MeshRebuilder>(); //Note incremental first, sweep second. Starts the refine off with a better tree to begin with so it doesn't to do an unrealistic amount of optimization to begin with. rebuilders.Add("v2 Reconstruct Incremental", (i) => physicsMesh.RebuildIncremental()); rebuilders.Add("v2 Reconstruct Sweep", (i) => physicsMesh.RebuildSweep()); rebuilders.Add("v2 Refit And Refine", (i) => physicsMesh.RefitWithIncrementalRefine(i)); rebuilders.Add("v2 Refit", (i) => physicsMesh.Refit()); disposer = () => { physicsMesh.Tree.Dispose(); }; costMeasurer = () => { return physicsMesh.Tree.MeasureCostMetric(); }; }