void Test() { //for (int i = 0; i < 10; i++) { foreach (GameObject obj in objs) { Debug.Log(obj); DateTime start = DateTime.Now; CutParams p = new CutParams(false, false, false, false, Vector3.zero, 0.2f, 0, Vector2.zero); CuttingPlane pl = CuttingPlane.InWorldSpace(obj.transform.up, obj.transform.position); if (GapAlgorithm.Run(obj, pl, p) == null) { throw new Exception("test failed"); } Debug.Log((DateTime.Now - start).TotalMilliseconds + " elapsed"); } //} }
public void OnCollisionEnter(Collision col) { if (ignoreColliders.Contains(col.collider)) { ignoreColliders.Remove(col.collider); return; } Cuttable cuttable; if (!col.gameObject.TryGetComponent <Cuttable>(out cuttable)) { return; } Vector3 cutDir = directionsAreNormals ? TransformNormal(cutDirection, transform) : transform.TransformDirection(cutDirection); float relVel = (col.relativeVelocity - Vector3.Project(col.relativeVelocity, cutDir)).magnitude; // Debug.Log("vel: "+relVel); // Debug.DrawRay(col.GetContact(0).point,col.relativeVelocity-Vector3.Project(col.relativeVelocity,cutDir)/relVel,Color.blue,1); if (minimumVelocity > relVel) { return; } Vector3 dir = omnidirectionalMode ? -col.relativeVelocity : cutDir; Vector3 edge = directionsAreNormals ? TransformNormal(edgeDirection, transform) : transform.TransformDirection(edgeDirection); Vector3 angleProjection = Vector3.ProjectOnPlane(gameObject.GetComponentInParent <Rigidbody>().velocity, edge); // Debug.Log("angle: "+Vector3.Angle(angleProjection,cutDir)); // if (Vector3.Angle(angleProjection,cutDir) > 70) Debug.Break(); // Debug.DrawRay(col.GetContact(0).point,angleProjection,Color.red,1); // Debug.DrawRay(col.GetContact(0).point,cutDir,Color.green,1); // Debug.DrawRay(col.GetContact(0).point,-col.relativeVelocity,Color.blue,1); if (Vector3.Angle(angleProjection, cutDir) > maxAngle) { return; } Vector3 normal = Vector3.Cross(dir, edge).normalized; Vector3 pointInPlane = useContactPoint ? col.GetContact(0).point : transform.position; CuttingPlane plane = CuttingPlane.InWorldSpace(normal, pointInPlane); CutParams param = new CutParams( cuttable.checkForHoles, true, cuttable.closeOpenSurfaces, cuttable.allowOpenSurfaces, Vector3.zero, float.PositiveInfinity, 0, cuttable.innerTextureCoordinate ); CutResult result = PerformCut(col.gameObject, plane, param); if (result != null) { if (cuttable.polySeparate) { result.PolySeparate(); } result.DestroyObject(); foreach (CutObj res in result.Results) { GameObject resObj = res .UseDefaults() .WithDriftVelocity(driftVelocity) .WithSeperationDistance(seperationDistance) .WithRingWidth(cuttable.highlightWidth) .WithRingColor(cuttable.highLightColor) .FallbackToColor(new Color(1, 0.1f, 0.1f)) .Instantiate(); cuttable.CopyTo(resObj); ignoreColliders.Add(resObj.GetComponent <Collider>()); } } }