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); }
protected VirgisFeature _drawFeature(IEnumerable <LineString> LinearRings, string gisId = null, Dictionary <string, object> properties = null) { LineString perimeter = (LinearRings as ReadOnlyCollection <LineString>)[0]; Vector3[] poly = perimeter.Vector3(); DCurve3 curve = new DCurve3(); curve.Vector3(poly, true); Vector3 center = (Vector3)curve.Center(); //Create the GameObjects GameObject dataPoly = Instantiate(PolygonPrefab, center, Quaternion.identity, transform); // add the gis data from geoJSON Datapolygon p = dataPoly.GetComponent <Datapolygon>(); p.gisId = gisId; p.gisProperties = properties ?? new Dictionary <string, object>(); if (symbology["body"].ContainsKey("Label") && symbology["body"].Label != null && (properties?.ContainsKey(symbology["body"].Label) ?? false)) { //Set the label GameObject labelObject = Instantiate(LabelPrefab, dataPoly.transform, false); labelObject.transform.Translate(dataPoly.transform.TransformVector(Vector3.up) * symbology["point"].Transform.Scale.magnitude, Space.Self); Text labelText = labelObject.GetComponentInChildren <Text>(); labelText.text = (string)properties[symbology["body"].Label]; } List <Dataline> polygon = new List <Dataline>(); // Darw the LinearRing foreach (LineString LinearRing in LinearRings) { Vector3[] lr = LinearRing.Vector3(); GameObject dataLine = Instantiate(LinePrefab, dataPoly.transform, false); Dataline com = dataLine.GetComponent <Dataline>(); com.Draw(lr, true, symbology, LinePrefab, HandlePrefab, null, mainMat, selectedMat, lineMain, lineSelected); polygon.Add(com); } //Draw the Polygon p.Draw(polygon, bodyMain); return(p); }
/// <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()); } }