static void CreateTriangles(int cc, DefaultTriangulationCell <Vertex> e, Color color) { //var go = new GameObject(e.ToString()); var go = new GameObject(cc.ToString() + "-" + UnityEngine.Random.Range(0, 1000).ToString()); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); Mesh mesh = new Mesh(); go.GetComponent <MeshFilter> ().mesh = mesh; mesh.vertices = new Vector3[] { new Vector3((float)e.Vertices[0].Position[0], (float)e.Vertices[0].Position [1], 0f), new Vector3((float)e.Vertices [1].Position[0], (float)e.Vertices [1].Position [1], 0f), new Vector3((float)e.Vertices [2].Position[0], (float)e.Vertices [2].Position [1], 0f) }; mesh.uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1) }; if (SurfaceNormalForTriangle(mesh.vertices [0], mesh.vertices [1], mesh.vertices [2]).z < 0f) { mesh.triangles = new int[] { 0, 1, 2 }; } else { mesh.triangles = new int[] { 2, 1, 0 }; } mesh.RecalculateNormals(); mesh.RecalculateBounds(); go.GetComponent <Renderer> ().material.color = color; }
void CreateTriangles(DefaultTriangulationCell <Vertex> e) { var go = new GameObject(e.ToString()); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); Mesh mesh = new Mesh(); go.GetComponent <MeshFilter> ().mesh = mesh; mesh.vertices = new Vector3[] { new Vector3((float)e.Vertices[0].Position[0], (float)e.Vertices[0].Position [1], 0f), new Vector3((float)e.Vertices [1].Position[0], (float)e.Vertices [1].Position [1], 0f), new Vector3((float)e.Vertices [2].Position[0], (float)e.Vertices [2].Position [1], 0f) }; // foreach (Vertex sv in e.Source.Vertices) { // // mesh.vertices = new Vector3[] {new Vector3(sv.Position[0], 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0)}; // // } mesh.uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1) }; mesh.triangles = new int[] { 0, 1, 2 }; mesh.RecalculateNormals(); mesh.RecalculateBounds(); go.GetComponent <Renderer> ().material.color = Color.blue; // new Color (UnityEngine.Random.Range (0.0f, 1.0f), // UnityEngine.Random.Range (0.0f, 1.0f), // UnityEngine.Random.Range (0.0f, 1.0f)); // }
static void CreateTetrahedron(int cc, DefaultTriangulationCell <Vertex> e, Color color) { var p0 = new Vector3((float)e.Vertices [0].Position [0], (float)e.Vertices [0].Position [1], (float)e.Vertices [0].Position [2]); var p1 = new Vector3((float)e.Vertices [1].Position[0], (float)e.Vertices [1].Position [1], (float)e.Vertices [1].Position [2]); var p2 = new Vector3((float)e.Vertices [2].Position[0], (float)e.Vertices [2].Position [1], (float)e.Vertices [2].Position [2]); var p3 = new Vector3((float)e.Vertices [3].Position[0], (float)e.Vertices [3].Position [1], (float)e.Vertices [3].Position [2]); //Debug.Log ("here"); var parent = GameObject.Find(cc.ToString()); var go = new GameObject(cc.ToString() + "-" + UnityEngine.Random.Range(0, 100000).ToString()); go.transform.parent = parent.transform; go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); Mesh mesh = new Mesh(); go.GetComponent <MeshFilter> ().mesh = mesh; mesh.vertices = new Vector3[] { p0, p1, p2, p0, p2, p3, p2, p1, p3, p0, p3, p1 }; mesh.triangles = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(mesh.vertices[i].y, mesh.vertices[i].x); } mesh.uv = uvs; mesh.RecalculateNormals(); mesh.RecalculateBounds(); go.GetComponent <Renderer> ().material = (Material)Resources.Load("ToonLit", typeof(Material)); //Color.red; // new Color (UnityEngine.Random.Range (0.0f, 1.0f), // UnityEngine.Random.Range (0.0f, 1.0f), // UnityEngine.Random.Range (0.0f, 1.0f), // 0f); //color; }
void CreateTetrahedron(int cc, DefaultTriangulationCell <Vertex> e, Color color) { //Debug.Log (e.Vertices.Count()); var p0 = new Vector3((float)e.Vertices [0].Position [0], (float)e.Vertices [0].Position [1], (float)e.Vertices [0].Position [2]); var p1 = new Vector3((float)e.Vertices [1].Position[0], (float)e.Vertices [1].Position [1], (float)e.Vertices [1].Position [2]); var p2 = new Vector3((float)e.Vertices [2].Position[0], (float)e.Vertices [2].Position [1], (float)e.Vertices [2].Position [2]); var p3 = new Vector3((float)e.Vertices [3].Position[0], (float)e.Vertices [3].Position [1], (float)e.Vertices [3].Position [2]); var go = new GameObject(cc.ToString() + "-" + UnityEngine.Random.Range(0, 1000).ToString()); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); Mesh mesh = new Mesh(); go.GetComponent <MeshFilter> ().mesh = mesh; mesh.vertices = new Vector3[] { p0, p1, p2, p0, p2, p3, p2, p1, p3, p0, p3, p1 }; mesh.triangles = new int[] { 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9 }; Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(mesh.vertices[i].y, mesh.vertices[i].x); } mesh.uv = uvs; mesh.RecalculateNormals(); mesh.RecalculateBounds(); ; go.GetComponent <Renderer> ().material.color = //Color.red; // new Color (UnityEngine.Random.Range (0.0f, 1.0f), // UnityEngine.Random.Range (0.0f, 1.0f), // UnityEngine.Random.Range (0.0f, 1.0f), // 0f); color; }