public override void OnInspectorGUI() { CSACollider csaCollider = (CSACollider)target; if (DrawDefaultInspector()) { csaCollider.EditorStart(); } }
private void HandleCSAVsHeightMapCollision( CSACollider csaCollider, HeightMapCollider hMapCollider, List <Contact> contacts, List <Segment> coarseContacts ) { foreach (Triangle tri in hMapCollider.TriGrid) { Vector3Int ind = hMapCollider.TriGrid.CurrentIndices; // position of bounding sphere in world coordinates Vector3 spherePos = csaCollider.BoundingSphere.CenterW; float radius = csaCollider.BoundingSphere.Radius; colors[ind.x] = colors[ind.y] = colors[ind.z] = Color.blue; if (IntersectionTest.SphereVsTriangle(spherePos, radius, tri)) { colors[ind.x] = colors[ind.y] = colors[ind.z] = Color.red; Diagnostics.Tic(); foreach (Slice slice in csaCollider.Slices) { if (IntersectionTest.PlaneVsTriangle(slice, tri, out Vector3 vec1, out Vector3 vec2)) { // endpoints of the plane-triangle intersection in plane local coordinates Vector2 vecA = slice.TransformToLocalBase(vec1); Vector2 vecB = slice.TransformToLocalBase(vec2); // calculating the data for transforming the curve float theta = Mathf.Atan2(vecB.y - vecA.y, vecB.x - vecA.x); Complex segRotation = new Complex(theta); Transform2D segTrf = new Transform2D(-vecA, segRotation); float segLength = Vector2.Distance(vecA, vecB); Vector2 upInLocal = slice.TransformToLocalBase(vec1 + tri.Normal); foreach (FourierCurve curve in slice.curves) { if (IntersectionTest.SegmentVsRectangle(curve.AABB, segTrf, segLength)) { // add the segments to render on the scene debugSegments.Add(new Segment(vec1, vec2)); coarseContacts.Add(new Segment(vec1, vec2)); if (csaCollider.rootFinder == CSACollider.RootFinder.SimulatedAnnealing) { if (IntersectionTest.SegmentVsCurveSA( curve, vecA, vecB, segLength, segRotation, upInLocal, out Vector2 contactInPlaneLocal, out float penetration, annealingTemperature, penetrationLimit)) { // rotate back the contact point into world coordinates Vector3 contactInWorld = contactInPlaneLocal.x * slice.LocalX + contactInPlaneLocal.y * slice.LocalY + slice.RefPoint; debugPoints.Add(contactInWorld); segmentColor.Add(Color.green); // the contact point relative to the object's transform Vector3 contactInLocal = contactInPlaneLocal.x * slice.LocalXL + contactInPlaneLocal.y * slice.LocalYL; RigidBody body = csaCollider.GetComponent <RigidBody>(); if (!csaCollider.isTrigger && body != null && body.enabled) { contacts.Add(new Contact(tri, contactInWorld, body)); } } else { segmentColor.Add(Color.magenta); } } else if (csaCollider.rootFinder == CSACollider.RootFinder.AberthEhrlich) { List <Vector2> intersections = new List <Vector2>(); if (IntersectionTest.SegmentVsCurveAE( curve, vecA, vecB, segLength, segRotation, upInLocal, intersections)) { foreach (Vector2 intPlane in intersections) { Vector3 intInWorld = intPlane.x * slice.LocalX + intPlane.y * slice.LocalY + slice.RefPoint; debugPoints.Add(intInWorld); segmentColor.Add(Color.green); RigidBody body = csaCollider.GetComponent <RigidBody>(); if (!csaCollider.isTrigger && body != null && body.enabled) { contacts.Add(new Contact(tri, intInWorld, body)); } } } else { segmentColor.Add(Color.magenta); } } } } } } Diagnostics.Toc2Log("slice time"); } }