private void SetUpManifolds(List <Vector3> vertices, List <List <int> > meshts, List <List <Vector3> > meshvs, List <List <Vector3> > meshns, List <Vector3> normals, Dictionary <int, List <MPolygon> > polygons, List <Vector3> cutPoints, int numComponents) { manifolds = new List <Manifold> (); int largerManifold = 1; if (meshvs[0].Count > meshvs[1].Count) { largerManifold = 0; } manifold.gameObject.GetComponent <MeshRenderer> ().enabled = false; for (int i = 0; i < numComponents; i++) { var mesh1v = meshvs[i]; var mesh1t = meshts[i]; var mesh1n = meshns[i]; Color randomColor = Color.grey; if (i != largerManifold) { randomColor = UnityEngine.Random.ColorHSV(); } Manifold meshObj = CreateMesh(mesh1v, mesh1t, vertices, normals, polygons[i], mesh1n, randomColor); var boundary = new List <int> (); foreach (var cp in cutPoints) { var index = mesh1v.IndexOf(cp); if (index != -1) { boundary.Add(index); } else { Debug.LogError("Does not contain cutpoint at " + cp); } } newBoundaries[meshObj] = boundary; meshObj.AddBoundary(boundary); manifolds.Add(meshObj); } }
internal void Add(Manifold m2, ref List <List <int> > boundaryCurves) { var mesh = this.manifold.gameObject.GetComponent <MeshFilter> ().mesh; var v1 = mesh.vertices; var t1 = mesh.triangles; var n1 = mesh.normals; var mesh2 = m2.gameObject.GetComponent <MeshFilter> ().mesh; var v2 = mesh2.vertices; var t2 = mesh2.triangles; var n2 = mesh2.normals; var newVerts = new Vector3[v1.Length + v2.Length]; var newTris = new int[t1.Length + t2.Length]; var newNorms = new Vector3[n1.Length + n2.Length]; var localToWorld1 = manifold.gameObject.transform.localToWorldMatrix; var localToWorld2 = m2.gameObject.transform.localToWorldMatrix; for (int i = 0; i < v1.Length; i++) { // newVerts[i] = localToWorld1.MultiplyPoint3x4 (v1[i]); newVerts[i] = v1[i]; } for (int i = 0; i < v2.Length; i++) { // newVerts[i + v1.Length] = localToWorld2.MultiplyPoint3x4 (v2[i]); Vector3 vector3 = m2.gameObject.transform.TransformPoint(v2[i]); newVerts[i + v1.Length] = manifold.gameObject.transform.InverseTransformPoint(vector3); // newVerts[i + v1.Length] = v2[i]; } for (int i = 0; i < t1.Length; i++) { newTris[i] = t1[i]; } for (int i = 0; i < t2.Length; i++) { newTris[i + t1.Length] = t2[i] + v1.Length; } for (int i = 0; i < n1.Length; i++) { newNorms[i] = n1[i]; } for (int i = 0; i < n2.Length; i++) { newNorms[i + n1.Length] = n2[i]; } foreach (var bound in boundaryCurves) { for (int i = 0; i < bound.Count; i++) { bound[i] = bound[i] + v1.Length; } manifold.AddBoundary(bound); } mesh.vertices = newVerts; mesh.triangles = newTris; mesh.normals = newNorms; mesh.RecalculateBounds(); StartCoroutine(buildGraph()); }