//private void OnCollisionExit(Collision collision) //{ // DeformableAgent da = collision.gameObject.GetComponent<DeformableAgent>(); // if (da) { // Vector3 centralContact = Vector3.zero; // for (int i = 0; i < collision.contacts.Length; i++) // centralContact += collision.contacts[i].point; // centralContact /= collision.contacts.Length; // Deform(collision.transform, centralContact); // } //} private void OnTriggerEnter(Collider other) { DeformableAgent da = other.GetComponent <DeformableAgent>(); //float dispersion = (da) ? da.dispersion : 1.0f; if (!currentImpactCollider && da) { currentImpactCollider = other; DeformVectors vectors = new DeformVectors(transform, other.transform.up, other.transform.position); Network_DeformableMesh ndm = GetComponent <Network_DeformableMesh>(); if (ndm) { ndm.CmdOnDeform(vectors.impact, vectors.simplified); } else { Deform(vectors.impact, vectors.simplified); } currentHitPoint = other.transform.position; } //if (!currentImpactCollider && da) { // currentImpactCollider = other; // RaycastHit hitInfo; // float rayLength = other.bounds.extents.magnitude; // if (Physics.Raycast(other.transform.position, other.transform.forward, out hitInfo, rayLength) // || Physics.Raycast(other.transform.position, -other.transform.forward, out hitInfo, rayLength)) // { // if (hitInfo.transform.gameObject == gameObject) // { // Vector3[] pts = new Vector3[9]; // Vector3 otherRight = other.transform.right * other.bounds.extents.x * dispersion; // Vector3 otherUp = other.transform.up * other.bounds.extents.y * dispersion; // int p = 0; // for (int i = -1; i <= 1; i += 1) // { // for (int j = -1; j <= 1; j += 1) // pts[p++] = hitInfo.point + (otherRight * i) + (otherUp * j); // } // Deform(other.transform, pts); // currentHitPoint = hitInfo.point; // return; // } // } // Deform(other.transform, other.transform.position); // currentHitPoint = other.transform.position; //} }
private void Deform_local(Transform otherObject, Vector3[] hitPoints, Mesh targetMesh) { UpdateComponents(); thread_vertices = targetMesh.vertices; float finalForce = (forceFactor / hitPoints.Length) * FindClosestHeatFactor(heatScript, otherObject.position); for (int i = 0; i < hitPoints.Length; i++) { for (int j = 0; j < thread_vertices.Length; j += maxWorkGroupSize) { DeformVectors vectors = new DeformVectors(transform, otherObject.transform.up, hitPoints[i]); int workgroupSize = (j + maxWorkGroupSize < thread_vertices.Length) ? maxWorkGroupSize : thread_vertices.Length - j; threads.Add(StartThread(j, j + workgroupSize, vectors.impact, vectors.simplified, finalForce)); } } }