void DrawPolyMode() { // unity // triごとに List <DelaunayTriangulation.Triangle> triangles = delaunayTriangulation.GetTriangles(); List <Vector3> t_vertices = GetVertices(); int triCount = triangles.Count; Vector3[] vertices = new Vector3[triCount * 3]; int[] tris = new int[triCount * 3]; Color[] color = new Color[triCount * 3]; Vector3[] normals = new Vector3[triCount * 3]; int t_index = 0; for (int i = 0; i < triangles.Count; i++) { DelaunayTriangulation.Triangle tri = triangles[i]; int[] triIndexs = tri.GetTriIndexs(); vertices[i * 3 + 0] = (t_vertices[triIndexs[0]]); vertices[i * 3 + 1] = (t_vertices[triIndexs[1]]); vertices[i * 3 + 2] = (t_vertices[triIndexs[2]]); tris[i * 3 + 0] = (t_index++); tris[i * 3 + 1] = (t_index++); tris[i * 3 + 2] = (t_index++); Color c = hsvColors [triIndexs [0]].GetColor() + hsvColors [triIndexs [1]].GetColor() + hsvColors [triIndexs [2]].GetColor(); c = c / 3.0f; color[i * 3 + 0] = (c); color[i * 3 + 1] = (c); color[i * 3 + 2] = (c); // normal Vector3 d1 = t_vertices[triIndexs[1]] - t_vertices[triIndexs[0]]; Vector3 d2 = t_vertices[triIndexs[2]] - t_vertices[triIndexs[0]]; Vector3 norm = Vector3.Cross(d1.normalized, d2.normalized); normals[i * 3 + 0] = (norm); normals[i * 3 + 1] = (norm); normals[i * 3 + 2] = (norm); } // Debug.Log ("t_vertices: "+vertices.Count + " / "+color.Count + " / "+tris.Count); mesh.Clear(); mesh.vertices = vertices; mesh.triangles = tris; mesh.colors = color; mesh.normals = normals; }
void DrawVertMode() { // unity // 頂点共通 List <DelaunayTriangulation.Triangle> triangles = delaunayTriangulation.GetTriangles(); List <Vector3> t_vertices = GetVertices(); List <int> tris = new List <int> (); for (var ti = 0; ti < triangles.Count; ti++) { DelaunayTriangulation.Triangle tri = triangles [ti]; int[] triIndexs = tri.GetTriIndexs(); tris.AddRange(triIndexs); } // List<Color> color = new List<Color> (); // for (int i = 0; i < t_vertices.Count; i++) { // color.Add( colors[i] ); // } // Debug.Log ("t_vertices: "+t_vertices.Count + " / "+color.Count + " / "+colors.Count + " / "+tris.Count); mesh.Clear(); mesh.vertices = t_vertices.ToArray(); mesh.triangles = tris.ToArray(); Color[] color = new Color[hsvColors.Count]; for (int i = 0; i < hsvColors.Count; i++) { color [i] = hsvColors [i].GetColor(); } mesh.colors = color; mesh.RecalculateNormals(); mf.mesh = mesh; }