public static SoftBody CreateFromVtkFile(SoftBodyWorldInfo worldInfo, string fileName) { List <Vector3> points = new List <Vector3>(0); List <int[]> cells = new List <int[]>(0); using (var reader = new StreamReader(fileName)) { bool readingPoints = false; bool readingCells = false; string line; while ((line = reader.ReadLine()) != null) { if (line.Length == 0) { continue; } string[] lineParts = line.Split(' '); if (lineParts[0] == "POINTS") { readingPoints = true; readingCells = false; points.Capacity = int.Parse(lineParts[1]); } else if (lineParts[0] == "CELLS") { readingPoints = false; readingCells = true; cells.Capacity = int.Parse(lineParts[1]); } else if (lineParts[0] == "CELL_TYPES") { readingPoints = false; readingCells = false; } else if (readingPoints) { Vector3 point = new Vector3( (float)ParseDouble(lineParts[0]), (float)ParseDouble(lineParts[1]), (float)ParseDouble(lineParts[2])); points.Add(point); } else if (readingCells) { int numPoints = int.Parse(lineParts[0]); int[] cell = new int[numPoints]; for (int i = 0; i < numPoints; i++) { cell[i] = int.Parse(lineParts[i + 1]); } cells.Add(cell); } } } SoftBody body = new SoftBody(worldInfo, points.Count, points.ToArray(), null); foreach (int[] cell in cells) { body.AppendTetra(cell[0], cell[1], cell[2], cell[3]); body.AppendLink(cell[0], cell[1], null, true); body.AppendLink(cell[1], cell[2], null, true); body.AppendLink(cell[2], cell[0], null, true); body.AppendLink(cell[0], cell[3], null, true); body.AppendLink(cell[1], cell[3], null, true); body.AppendLink(cell[2], cell[3], null, true); } GenerateBoundaryFaces(body); body.InitializeDmInverse(); body.TetraScratches.Resize(body.Tetras.Count); body.TetraScratchesTn.Resize(body.Tetras.Count); //Console.WriteLine($"Nodes: {body.Nodes.Count}"); //Console.WriteLine($"Links: {body.Links.Count}"); //Console.WriteLine($"Faces: {body.Faces.Count}"); //Console.WriteLine($"Tetras: {body.Tetras.Count}"); return(body); }