public override void VertexMove(MoveArgs data) { if (VertexTable.Contains(new VertexLookup() { Id = data.id })) { VertexLookup vdata = VertexTable.Find(item => item.Id == data.id); foreach (VertexLookup vLookup in VertexTable) { if (vLookup.Line && vLookup.Line.vStart == vdata.Vertex) { vLookup.Line.MoveStart(data.pos); } if (vLookup.Line && vLookup.Line.vEnd == vdata.Vertex) { vLookup.Line.MoveEnd(data.pos); } } curve.Vector3(GetVertexPositions(), Lr); if (label) { label.position = _labelPosition(); } } curve.Vector3(GetVertexPositions(), Lr); }
public bool Equals(VertexLookup other) { if (other == null) { return(false); } return(this.Id.Equals(other.Id)); }
public int CompareTo(VertexLookup other) { if (other == null) { return(1); } else { return(Vertex.CompareTo(other.Vertex)); } }
public override bool Equals(object obj) { if (obj == null) { return(false); } VertexLookup com = obj as VertexLookup; if (com == null) { return(false); } else { return(Equals(com)); } }
/// <summary> /// Make the Line into a Linear Ring by setting the Lr flag and creating a LineSegment form the last vertex to the first. /// If the last vertex is in the same (exact) position as the first vertex, the last vertex is deleted. /// </summary> public void MakeLinearRing() { // Make the Line inot a Linear ring if (!Lr) { VertexLookup First = VertexTable.Find(item => item.Vertex == 0); VertexLookup Last = VertexTable.Find(item => item.Vertex == VertexTable.Count - 1); if (First.Com.transform.position == Last.Com.transform.position) { Destroy(Last.Com.gameObject); VertexTable.Remove(Last); Last = VertexTable.Find(item => item.Vertex == Last.Vertex - 1); Last.Line.MoveEnd(First.Com.transform.position); Last.Line.vEnd = 0; } else { VertexTable.Last().Line = _createSegment(VertexTable.Last().Com.transform.position, VertexTable.First().Com.transform.position, VertexTable.Count - 1, true); } Lr = true; } }
public override void RemoveVertex(VirgisFeature vertex) { if (BlockMove) { Destroy(gameObject); } else { VertexLookup vLookup = VertexTable.Find(item => item.Com == vertex); if (vLookup.isVertex) { int thisVertex = vLookup.Vertex; if (vLookup.Line != null) { Destroy(vLookup.Line.gameObject); } else { Destroy(VertexTable.Find(item => item.Vertex == vLookup.Vertex - 1).Line.gameObject); } Destroy(vLookup.Com.gameObject); VertexTable.Remove(vLookup); VertexTable.ForEach(item => { if (item.Vertex >= thisVertex) { item.Vertex--; if (item.Line != null) { item.Line.vStart--; if (item.Line.vEnd != 0) { item.Line.vEnd--; } } } ; if (Lr && item.isVertex && item.Line.vEnd >= VertexTable.Count) { item.Line.vEnd = 0; } ; }); int end = thisVertex; int start = thisVertex - 1; if (Lr && thisVertex >= VertexTable.Count) { end = 0; } if (Lr && thisVertex == 0) { start = VertexTable.Count - 1; } Debug.Log($"start : {start}, End : {end}"); if (VertexTable.Count > 1) { VertexTable.Find(item => item.Vertex == start).Line.MoveEnd(VertexTable.Find(item => item.Vertex == end).Com.transform.position); } else { Destroy(gameObject); } } } transform.parent.SendMessage("RemoveVertex", this, SendMessageOptions.DontRequireReceiver); }
/// <summary> /// Makes the actual mesh /// </summary> protected void _redraw() { if (lines.Count > 0) { Polygon = new List <DCurve3>(); foreach (Dataline ring in lines) { foreach (VertexLookup v in ring.VertexTable) { VertexTable.Add(v); } DCurve3 curve = new DCurve3(); curve.Vector3(ring.GetVertexPositions(), true); Polygon.Add(curve); } } MeshFilter mf = Shape.GetComponent <MeshFilter>(); MeshCollider[] mc = Shape.GetComponents <MeshCollider>(); mf.mesh = null; Mesh mesh = new Mesh(); Mesh imesh = new Mesh(); mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; imesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; Frame3f frame = new Frame3f(); Vector3[] vertices; GeneralPolygon2d polygon2d; Delaunator delaunator; List <int> triangles = new List <int>(); try { // // Map 3d Polygon to the bext fit 2d polygon and also return the frame used for the mapping // polygon2d = Polygon.ToPolygon(ref frame); // // calculate the dalaunay triangulation of the 2d polygon // delaunator = new Delaunator(polygon2d.AllVerticesItr().ToPoints()); IEnumerable <Vector2d> vlist = delaunator.Points.ToVectors2d(); vertices = new Vector3[vlist.Count()]; // // for each vertex in the dalaunay triangulatin - map back to a 3d point and also populate the vertex table // for (int i = 0; i < vlist.Count(); i++) { Vector2d v = vlist.ElementAt(i); try { Vector3d v1 = Polygon.AllVertexItr().Find(item => v.Distance(frame.ToPlaneUV((Vector3f)item, 2)) < 0.001); vertices[i] = Shape.transform.InverseTransformPoint((Vector3)v1); VertexLookup vl = VertexTable.Find(item => v1.Distance(item.Com.transform.position) < 0.001); if (vl != null) { vl.pVertex = i; } } catch { Debug.Log("Mesh Error"); } } // // eaxtract the triangles from the delaunay triangulation // IEnumerable <ITriangle> tris = delaunator.GetTriangles(); for (int i = 0; i < tris.Count(); i++) { ITriangle tri = tris.ElementAt(i); if (polygon2d.Contains(tri.CetIncenter())) { int index = 3 * i; triangles.Add(delaunator.Triangles[index]); triangles.Add(delaunator.Triangles[index + 1]); triangles.Add(delaunator.Triangles[index + 2]); } } } catch (Exception e) { throw new Exception("feature is not a valid Polygon : " + e.ToString()); } // // build the mesh entity // mesh.vertices = vertices; mesh.triangles = triangles.ToArray(); mesh.uv = BuildUVs(vertices); mesh.RecalculateBounds(); mesh.RecalculateNormals(); imesh.vertices = mesh.vertices; imesh.triangles = triangles.Reverse <int>().ToArray(); imesh.uv = mesh.uv; imesh.RecalculateBounds(); imesh.RecalculateNormals(); mf.mesh = mesh; try { mc[0].sharedMesh = mesh; mc[1].sharedMesh = imesh; } catch (Exception e) { Debug.Log(e.ToString()); } }
/// <summary> /// Generates the actual mesh for the polyhedron /// </summary> private void MakeMesh() { MeshFilter mf; mf = Shape.GetComponent <MeshFilter>(); if (mf == null) { mf = Shape.AddComponent <MeshFilter>(); } mf.mesh = null; Mesh mesh = new Mesh(); TriangulatedPolygonGenerator tpg = new TriangulatedPolygonGenerator(); Frame3f frame = new Frame3f(); tpg.Polygon = Polygon.ToPolygon(ref frame); tpg.Generate(); int nv = tpg.vertices.Count; VertexTable.Clear(); foreach (Dataline ring in Polygon) { foreach (VertexLookup v in ring.VertexTable) { VertexTable.Add(v); } } IEnumerable <Vector3d> vlist = tpg.vertices.AsVector3d(); Vector3[] vertices = new Vector3[vlist.Count()]; for (int i = 0; i < vlist.Count(); i++) { Vector3d v = vlist.ElementAt(i); try { VertexLookup vl = VertexTable.Find(item => v.xy.Distance(frame.ToPlaneUV(item.Com.transform.position, 3)) < 0.001); vertices[i] = Shape.transform.InverseTransformPoint(vl.Com.transform.position); vl.pVertex = i; } catch { VertexTable.Add(new VertexLookup() { pVertex = i, Com = VertexTable[0].Com }); vertices[i] = Shape.transform.InverseTransformPoint((Vector3)frame.FromFrameV(v)); } } List <Vector2> uvs = new List <Vector2>(); IEnumerable <Vector2d> uv2d = tpg.uv.AsVector2f(); foreach (Vector2d uv in uv2d) { uvs.Add((Vector2)uv); } mesh.vertices = vertices.ToArray(); mesh.triangles = tpg.triangles.ToArray <int>(); mesh.uv = uvs.ToArray <Vector2>(); mesh.RecalculateBounds(); mesh.RecalculateNormals(); mf.mesh = mesh; }