public void CreateTriangle(int id1, int id2, int id3) { Matrix4x4 world2Object = gameObject.transform.worldToLocalMatrix; GameObject[] points = { particles[id1], particles[id2], particles[id3] }; FracTriangle newTriangle = new FracTriangle(world2Object, points, mu, lambda, phi, psi); triangles.Add(newTriangle); }
public void CutElement(int fracturePointId, Vector3 p1, FracTriangle triangle, GameObject particleOnPlane) { // Duplicate Fracture point GameObject originalP = particles[fracturePointId]; FracParticle fpOriginal = originalP.GetComponent <FracParticle>(); // Duplicate Particle and assign side of plane. // The new particle is defined as always on the positive side of the plane GameObject duplicateP = DuplicateParticle(fracturePointId); FracParticle fpDupplicate = duplicateP.GetComponent <FracParticle>(); fpOriginal.Side = false; fpDupplicate.Side = true; // If the other point is an already existing particle, then no other points to create GameObject secondPoint; if (particleOnPlane != null) { secondPoint = particleOnPlane; // HACK: This is a poor way of doing this search. Just trying to make it work here first. // Check if a spring between the originalPoint and the second point already exists bool alreadyExists = false; for (int i = 0; i < fpOriginal.Springs.Count; ++i) { Spring s = fpOriginal.Springs[i]; if ((s.P2.gameObject == secondPoint && s.P1.gameObject == originalP) || (s.P1.gameObject == secondPoint && s.P2.gameObject == originalP)) { alreadyExists = true; } } if (!alreadyExists) { Spring s = originalP.AddComponent <Spring>(); s.Initialize(originalP.GetComponent <Rigidbody>(), secondPoint.GetComponent <Rigidbody>()); } Spring ds = duplicateP.AddComponent <Spring>(); ds.Initialize(duplicateP.GetComponent <Rigidbody>(), secondPoint.GetComponent <Rigidbody>()); } else { secondPoint = CreateParticle(p1); } // Reassign springs for (int i = 0; i < fpOriginal.Springs.Count; ++i) { Spring s = fpOriginal.Springs[i]; GameObject otherPoint = s.GetOtherPoint(originalP); FracParticle sfp = otherPoint.GetComponent <FracParticle>(); if (sfp.gameObject == secondPoint) { continue; } else { Assert.IsTrue(sfp.SideIsSet, "FracMesh : CutElement : Side is not set. Can't reassign springs"); } // if spring particle doesn't have the same side as the initial particle, then the spring must be // re-assigned to the duplicate. Otherwise, nothing to change if (sfp.Side != fpOriginal.Side) { s.Initialize(otherPoint.GetComponent <Rigidbody>(), duplicateP.GetComponent <Rigidbody>()); } } }