private void adaptate() { if (!this.aad.isRectangular() && this.aad.getInfluenceArea() != null) { Mesh mesh = new Mesh(); List <Vector3> vertices = new List <Vector3> (); foreach (Vector2 v in this.aad.getPoints()) { vertices.Add(new Vector3(v.x / 100f, v.y / 100f, this.transform.position.z)); } mesh.SetVertices(vertices); List <int> triangles = new List <int> (); for (int i = 2; i < aad.getPoints().Count; i++) { triangles.AddRange(new int[] { 0, i - 1, i }); } mesh.SetTriangles(triangles, 0); this.GetComponent <MeshFilter> ().mesh = mesh; } }
public static Rectangle MoveAreaToTrajectory(this Rectangle area, uAdventure.Runner.TrajectoryHandler trajectory) { var points = area.isRectangular() ? area.ToRect().ToPoints() : area.getPoints().ToArray(); var aa = new ActiveArea("aux", false, 0, 0, 0, 0); var pointsList = aa.getPoints(); var center = points.Aggregate((v1, v2) => v1 + v2) / points.Length; var adjust = -center + trajectory.closestPoint(center); foreach (var p in points) { pointsList.Add(p + adjust); } return(aa); }
public List <Vector2> getPoints() { return(activeArea.getPoints()); }
private void adaptate() { if (!this.aad.isRectangular() && this.aad.getInfluenceArea() != null) { this.transform.localScale = new Vector3(1, 1, 1); Mesh mesh = new Mesh(); List <Vector3> vertices = new List <Vector3>(); Tess tess = new LibTessDotNet.Tess(); ContourVertex[] contour = new ContourVertex[aad.getPoints().Count]; int i = 0; float minx = float.MaxValue, miny = float.MaxValue, maxx = 0, maxy = 0; foreach (Vector2 v in this.aad.getPoints()) { if (v.x < minx) { minx = v.x; } if (v.x > maxx) { maxx = v.x; } if (v.y < miny) { miny = v.y; } if (v.y > maxy) { maxy = v.y; } } minx = (minx + (maxx - minx) / 2) / 10; miny = 60 - (miny + (maxy - miny) / 2) / 10; foreach (Vector2 v in this.aad.getPoints()) { contour[i].Position = new LibTessDotNet.Vec3 { X = v.x / 10f - minx, Y = 60 - v.y / 10f - miny, Z = this.transform.position.z }; i++; } tess.AddContour(contour, LibTessDotNet.ContourOrientation.CounterClockwise); tess.Tessellate(WindingRule.EvenOdd, LibTessDotNet.ElementType.Polygons, 3); List <int> triangles = new List <int>(); int numTriangles = tess.ElementCount; for (i = 0; i < numTriangles; i++) { vertices.Add(Vec3toVector3(tess.Vertices[tess.Elements[i * 3]].Position)); vertices.Add(Vec3toVector3(tess.Vertices[tess.Elements[i * 3 + 1]].Position)); vertices.Add(Vec3toVector3(tess.Vertices[tess.Elements[i * 3 + 2]].Position)); triangles.AddRange(new int[] { i * 3, i * 3 + 1, i * 3 + 2 }); } mesh.SetVertices(vertices); mesh.SetTriangles(triangles, 0); this.GetComponent <MeshFilter>().sharedMesh = mesh; this.GetComponent <MeshCollider>().sharedMesh = mesh; } }