private void Update() { if (Input.GetKeyDown(KeyCode.D) && !IsGenerating) { foreach (Edge e in edges) { e.gameObject.SetActive(true); Destroy(e.gameObject); } edges.Clear(); generator.Clear(); container.Clear(); added.Clear(); } if (Input.GetKeyDown(KeyCode.R) && !IsGenerating) { pointCloud.GenerateCloud(); } if (Input.GetKeyDown(KeyCode.G) && !IsGenerating) { edges.Clear(); container.Clear(); added.Clear(); StartCoroutine(Triangulate()); } Render(); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.D) && !IsGenerating) { foreach (Edge e in edges) { e.gameObject.SetActive(true); Destroy(e.gameObject); } edges.Clear(); hull.Clear(); generator.Clear(); } if (Input.GetKeyDown(KeyCode.R) && !IsGenerating) { pointCloud.GenerateCloud(); } if (Input.GetKeyDown(KeyCode.G) && !IsGenerating) { Debug.Log("Generating convex hull with Jarvis March"); foreach (Edge e in edges) { e.gameObject.SetActive(true); Destroy(e.gameObject); } edges.Clear(); hull.Clear(); StartCoroutine(DoJarvisMarch(new List <Vertex>(generator.Vertices))); } }
private void Update() { if (Input.GetKeyDown(KeyCode.D) && !IsGenerating) { foreach (Edge e in edges) { e.gameObject.SetActive(true); Destroy(e.gameObject); } edges.Clear(); VertexGenerator generator = GameObject.Find("VertexGenerator").GetComponent <VertexGenerator>(); generator.Clear(); upper.Clear(); lower.Clear(); hull.Clear(); } if (Input.GetKeyDown(KeyCode.R) && !IsGenerating) { pointCloud.GenerateCloud(); } if (Input.GetKeyDown(KeyCode.G) && !IsGenerating) { Debug.Log("Generating convex hull with Graham Scan"); foreach (Edge e in edges) { e.gameObject.SetActive(true); Destroy(e.gameObject); } edges.Clear(); upper.Clear(); lower.Clear(); hull.Clear(); VertexGenerator generator = GameObject.Find("VertexGenerator").GetComponent <VertexGenerator>(); StartCoroutine(DoGrahamScan(new List <Vertex>(generator.Vertices).ToArray())); } if (IsGenerating) { ConstructHull(); for (int i = 1; i < hull.Count; i++) { if (i >= edges.Count) { Edge edge = Instantiate(edgePrefab).GetComponent <Edge>(); edges.Add(edge); } edges[i - 1].Point1 = hull[i - 1]; edges[i - 1].Point2 = hull[i]; edges[i - 1].SetPosition(hull[i - 1].transform.position, hull[i].transform.position); edges[i - 1].transform.SetParent(transform); edges[i - 1].gameObject.SetActive(true); edges[i - 1].isHighlighted = i >= hull.Count - 1 && edges[0].Point1 != edges[i - 1].Point2; } for (int i = hull.Count; i < edges.Count; i++) { edges[i].gameObject.SetActive(false); } } }