private void AddPointsAndSprings(List <TriangleVertexIndices> indices, List <TSVector> vertices) { for (int i = 0; i < vertices.Count; i++) { SoftBody.MassPoint massPoint = new SoftBody.MassPoint(this.sphere, this, this.material); massPoint.Position = vertices[i]; massPoint.Mass = FP.EN1; this.points.Add(massPoint); } for (int j = 0; j < indices.Count; j++) { TriangleVertexIndices indices2 = indices[j]; SoftBody.Triangle triangle = new SoftBody.Triangle(this); triangle.indices = indices2; this.triangles.Add(triangle); triangle.boundingBox = TSBBox.SmallBox; triangle.boundingBox.AddPoint(this.points[triangle.indices.I0].position); triangle.boundingBox.AddPoint(this.points[triangle.indices.I1].position); triangle.boundingBox.AddPoint(this.points[triangle.indices.I2].position); triangle.dynamicTreeID = this.dynamicTree.AddProxy(ref triangle.boundingBox, triangle); } HashSet <SoftBody.Edge> edges = this.GetEdges(indices); int num = 0; foreach (SoftBody.Edge current in edges) { SoftBody.Spring spring = new SoftBody.Spring(this.points[current.Index1], this.points[current.Index2]); spring.Softness = FP.EN2; spring.BiasFactor = FP.EN1; spring.SpringType = SoftBody.SpringType.EdgeSpring; this.springs.Add(spring); num++; } }
public SoftBody(int sizeX, int sizeY, FP scale) { List <TriangleVertexIndices> list = new List <TriangleVertexIndices>(); List <TSVector> list2 = new List <TSVector>(); for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { list2.Add(new TSVector(i, 0, j) * scale); } } for (int k = 0; k < sizeX - 1; k++) { for (int l = 0; l < sizeY - 1; l++) { TriangleVertexIndices item = default(TriangleVertexIndices); item.I0 = l * sizeX + k; item.I1 = l * sizeX + k + 1; item.I2 = (l + 1) * sizeX + k + 1; list.Add(item); item.I0 = l * sizeX + k; item.I1 = (l + 1) * sizeX + k + 1; item.I2 = (l + 1) * sizeX + k; list.Add(item); } } this.EdgeSprings = this.springs.AsReadOnly(); this.VertexBodies = this.points.AsReadOnly(); this.Triangles = this.triangles.AsReadOnly(); this.AddPointsAndSprings(list, list2); for (int m = 0; m < sizeX - 1; m++) { for (int n = 0; n < sizeY - 1; n++) { SoftBody.Spring spring = new SoftBody.Spring(this.points[n * sizeX + m + 1], this.points[(n + 1) * sizeX + m]); spring.Softness = FP.EN2; spring.BiasFactor = FP.EN1; this.springs.Add(spring); } } foreach (SoftBody.Spring current in this.springs) { TSVector tSVector = current.body1.position - current.body2.position; bool flag = tSVector.z != FP.Zero && tSVector.x != FP.Zero; if (flag) { current.SpringType = SoftBody.SpringType.ShearSpring; } else { current.SpringType = SoftBody.SpringType.EdgeSpring; } } for (int num = 0; num < sizeX - 2; num++) { for (int num2 = 0; num2 < sizeY - 2; num2++) { SoftBody.Spring spring2 = new SoftBody.Spring(this.points[num2 * sizeX + num], this.points[num2 * sizeX + num + 2]); spring2.Softness = FP.EN2; spring2.BiasFactor = FP.EN1; SoftBody.Spring spring3 = new SoftBody.Spring(this.points[num2 * sizeX + num], this.points[(num2 + 2) * sizeX + num]); spring3.Softness = FP.EN2; spring3.BiasFactor = FP.EN1; spring2.SpringType = SoftBody.SpringType.BendSpring; spring3.SpringType = SoftBody.SpringType.BendSpring; this.springs.Add(spring2); this.springs.Add(spring3); } } }