void Start() { plane = new PlaneMath(new Coords(A.position), new Coords(B.position), new Coords(C.position)); line = new Line(new Coords(D.position), new Coords(E.position), Line.LINETYPE.RAY); line.Draw(1, Color.green); for (float s = 0; s <= 1; s += 0.1f) { for (float t = 0; t <= 1; t += 0.1f) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = plane.Lerp(s, t).ToVector(); } } float interceptAt = line.IntersectsAt(plane); if (interceptAt == interceptAt) { GameObject it = GameObject.CreatePrimitive(PrimitiveType.Cube); it.transform.position = line.Lerp(interceptAt).ToVector(); } }
public void Split(Transform splitTransform) { if (!_isSplitting) { //If a cut is made then get the cut plane _isSplitting = _splitMesh = true; _splitPlane = new PlaneMath(splitTransform); MeshFilter[] meshFilters = GetComponentsInChildren <MeshFilter>(); SkinnedMeshRenderer[] skinnedRenderes = GetComponentsInChildren <SkinnedMeshRenderer>(); _meshContainerStatic = new MeshContainer[meshFilters.Length]; _meshSplitterStatic = new IMeshSplitter[meshFilters.Length]; //Loop through each mesh filter and intitialze a capped mesh and save it in container for (int i = 0; i < meshFilters.Length; i++) { _meshContainerStatic[i] = new MeshContainer(meshFilters[i]); _meshSplitterStatic[i] = (IMeshSplitter) new MeshSplitterConcave(_meshContainerStatic[i], _splitPlane, splitTransform.rotation); } _meshSplitterSkinned = new IMeshSplitter[skinnedRenderes.Length]; _meshContainerSkinned = new MeshContainer[skinnedRenderes.Length]; //Although this function is rendundant here but it is important - it gets the bones and joints of the object incase the object is bendable for (int i = 0; i < skinnedRenderes.Length; i++) { _meshContainerSkinned[i] = new MeshContainer(skinnedRenderes[i]); _meshSplitterSkinned[i] = (IMeshSplitter) new MeshSplitterConcave(_meshContainerSkinned[i], _splitPlane, splitTransform.rotation); } } }
public MeshSplitterConvex(MeshContainer meshContainer, PlaneMath splitPlane, Quaternion splitRotation) { _mesh = meshContainer; _splitPlane = splitPlane; _splitRotation = splitRotation; _ownRotation = meshContainer.transform.rotation; capInds = new List <int>(meshContainer.vertexCount / 10); }
public MeshSplitterConcave(MeshContainer meshContainer, PlaneMath splitPlane, Quaternion splitRotation) { _mesh = meshContainer; _splitPlane = splitPlane; _splitRotation = splitRotation; _ownRotation = meshContainer.transform.rotation; _edges = new List <Edge>(meshContainer.vertexCount / 10); }
private void ProjectOnToPlane(Vector3 faceNormal) { Vector3 planePoint = _affectors[20].position; foreach (var pos in _randomBalls) { Vector3 projectedPoint = PlaneMath.ProjectPointOnPlane(faceNormal, planePoint, pos); Debug.DrawLine(pos, projectedPoint, Color.red, 500); } }
public float IntersectsAt(PlaneMath plane) { Coords N = TMath.Cross(plane.u, plane.v); Coords AB = plane.A - A; if (TMath.Dot(N, v) == 0) { return(float.NaN); } float t = TMath.Dot(N, AB) / TMath.Dot(N, v); return(t); }
public void Split(Transform splitTransform) { if (!_isSplitting) { _isSplitting = _splitMesh = true; _splitPlane = new PlaneMath(splitTransform); MeshFilter[] meshFilters = GetComponentsInChildren <MeshFilter> (); SkinnedMeshRenderer[] skinnedRenderes = GetComponentsInChildren <SkinnedMeshRenderer> (); _meshContainerStatic = new MeshContainer[meshFilters.Length]; _meshSplitterStatic = new IMeshSplitter[meshFilters.Length]; for (int i = 0; i < meshFilters.Length; i++) { _meshContainerStatic [i] = new MeshContainer(meshFilters [i]); _meshSplitterStatic [i] = Convex ? (IMeshSplitter) new MeshSplitterConvex(_meshContainerStatic [i], _splitPlane, splitTransform.rotation) : (IMeshSplitter) new MeshSplitterConcave(_meshContainerStatic [i], _splitPlane, splitTransform.rotation); if (UseCapUV) { _meshSplitterStatic [i].SetCapUV(UseCapUV, CustomUV, CapUVMin, CapUVMax); } #if UNITY_EDITOR _meshSplitterStatic [i].DebugDraw(ShowDebug); #endif } _meshSplitterSkinned = new IMeshSplitter[skinnedRenderes.Length]; _meshContainerSkinned = new MeshContainer[skinnedRenderes.Length]; for (int i = 0; i < skinnedRenderes.Length; i++) { _meshContainerSkinned [i] = new MeshContainer(skinnedRenderes [i]); _meshSplitterSkinned [i] = Convex ? (IMeshSplitter) new MeshSplitterConvex(_meshContainerSkinned [i], _splitPlane, splitTransform.rotation) : (IMeshSplitter) new MeshSplitterConcave(_meshContainerSkinned [i], _splitPlane, splitTransform.rotation); if (UseCapUV) { _meshSplitterSkinned [i].SetCapUV(UseCapUV, CustomUV, CapUVMin, CapUVMax); } #if UNITY_EDITOR _meshSplitterSkinned [i].DebugDraw(ShowDebug); #endif } } }
/// <summary> /// Test if the angle between next edge and current edge is less or equal to 180 degrees. /// </summary> /// <param name="currentEdge">Current Edge</param> /// <param name="nextEdge">Next Edge</param> /// <param name="cw">Direction is clockwise?</param> /// <returns></returns> private int TestInnerSide(Edge currentEdge, Edge nextEdge, bool cw) { PlaneMath plane = new PlaneMath(currentEdge.Left, currentEdge.Normal); float pointSide = plane.PointSide(cw ? nextEdge.Right : nextEdge.Left); if (pointSide < -.000001f) // less than zero with a threshold, inner side { return(1); } if (pointSide < .000001f) // < 180 degree angle, needs to be melted { return(0); } return(-1); }