/* * Static methods */ /// <summary> /// 輪郭線情報から三角形分割を行う。 /// </summary> /// <returns>The contour.</returns> /// <param name="contour">Contour.</param> public static Delaunay2D Contour(List <Vector2> contour) { var d = new Delaunay2D(contour); d.RemoveExternalTriangles(contour); return(d); }
void Update() { if (Input.GetMouseButtonDown(0)) { ClearPositions(); _isDragging = true; AddPosition(GetMousePosition()); } else if (Input.GetMouseButtonUp(0)) { _isDragging = false; var sw = System.Diagnostics.Stopwatch.StartNew(); _delaunay = Delaunay2D.Contour(_points); var mesh = _delaunay.ToMesh(sampleColors[Random.Range(0, sampleColors.Length)]); _meshFilter.mesh = mesh; sw.Stop(); Debug.Log(sw.ElapsedMilliseconds); var maxDistance = mesh.bounds.size.magnitude * 0.5f + 1f; Vector3 center = mesh.bounds.center; if (_coroutine != null) { StopCoroutine(_coroutine); } _coroutine = StartCoroutine(ShowCotourine(1f, maxDistance, center)); } else if (Input.GetMouseButton(0)) { Vector2 pos = GetMousePosition(); if ((pos - _points[_points.Count - 1]).magnitude > 0.5f) { AddPosition(pos); } } if (_delaunay != null) { _delaunay.ForeachTriangles((Triangle2D t) => { t.DebugDraw(); t.circumscribedCircle.DebugDraw(); }); } }