/// <summary>Updates the internal triangulated version of the path. Occurs whenever Path is set.</summary> public void Refresh() { #if !NO_BLADE_RUNTIME if (MeshSet) { // Do nothing. return; } if (Path_ == null) { Mesh_ = null; return; } if (Mesh_ == null) { // Create it now: Mesh_ = new Mesh(); } // Build the verts first: int vertCount = Path_.GetVertexCount(Accuracy); Vector3[] verts = new Vector3[vertCount]; List <int> contours = new List <int>(); int index = 0; Path_.GetVertices(verts, null, Accuracy, 0f, 0f, 1f, ref index, contours); // Create uv set: Vector2[] uvs = new Vector2[vertCount]; // UV values are directly based on verts, just a little remapped. // UV is 0-1, verts are -1 to +1. Y is also inverted (Because Unity stores textures "upside down"). for (int i = 0; i < vertCount; i++) { Vector3 vert = verts[i]; uvs[i] = new Vector2( ((vert.x + 1f) / 2f), // Map ((1f - vert.y) / 2f) // Map and invert ); } // Triangulate each contour next. // Create triangulator: if (Triangulator == null) { Triangulator = new Triangulator(null, 0, 0); } // Set verts: Triangulator.Vertices = verts; // Triangulate: int[] tris = Triangulator.Triangulate(contours); // Set verts etc now: Mesh_.triangles = null; Mesh_.vertices = verts; Mesh_.uv = uvs; Mesh_.triangles = tris; // Bounds and normals aren't required, but we do need to upload it: Mesh_.UploadMeshData(true); #endif }