private static void SetNormals(Triange t) { SetNormal(t.a, t.c, t.b); SetNormal(t.b, t.a, t.c); SetNormal(t.c, t.b, t.a); //t.a.i = 1f; t.a.j = 0f; t.a.k = 0f; //t.b.i = 0f; t.b.j = -1f; t.b.k = 0f; //t.c.i = 0f; t.c.j = -1f; t.c.k = 0f; }
private void Start() { List <Vector3> posList = new List <Vector3>(); for (int i = 0; i < tList.Count; i++) { posList.Add(tList[i].position); } Triange = new Triange(posList); Triange.SetCompareAxle(CompareAxle.Y); int[] a = Triange.GetTriangles(); if (a != null) { for (int i = 0; i < a.Length; i++) { resultList.Add(a[i]); } } GameObject go = new GameObject(); MeshFilter mf = go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); Mesh m = new Mesh(); Vector3[] vertexs = new Vector3[a.Length]; for (int i = 0; i < vertexs.Length; i++) { Vector3 v = tList[a[i]].position; vertexs[i] = v; } m.vertices = vertexs; int[] tri = new int[a.Length]; for (int i = 0; i < tri.Length; i += 3) { tri[i] = i; tri[i + 1] = i + 2; tri[i + 2] = i + 1; } m.triangles = tri; mf.mesh = m; }
private static List <Triange> GetMesh(List <SurfacePoint> points, BoundingBox boundingBox) { var mesh = new List <Triange>(); // builds the list of vertices based on the points grid var rows = GetRows(points, boundingBox); // builds the list of triangle for each row of vertices for (var row = 0; row < rows.Count - 1; row += 1) { var rowA = rows[row]; var widthRowA = rowA.Count; var rowB = rows[row + 1]; var widthRowB = rowB.Count; var i = 0; var j = 0; while (i < widthRowA - 1 && j < widthRowB - 1) { var t0 = new Triange { a = Clone(rowA[i]), b = Clone(rowA[i + 1]), c = Clone(rowB[j]) }; SetNormals(t0); mesh.Add(t0); var t1 = new Triange { a = Clone(rowA[i + 1]), b = Clone(rowB[j + 1]), c = Clone(rowB[j]) }; SetNormals(t1); mesh.Add(t1); i += 1; j += 1; //if (i == 5 || j == 5) { break; } } //if (row == 5) { break; } } return(mesh); }