private static void GenerateMesh(RageSpline rs, bool refreshTriangulation) { // if(rs.GetFill() != RageSpline.Fill.None) // rs.ShiftOverlappingControlPoints(); bool fillAntialiasing = false; float aaWidth = rs.GetAntialiasingWidth(); if (aaWidth > 0f) { if (rs.inverseTriangleDrawOrder) { fillAntialiasing = true; } else if (rs.GetOutline() == RageSpline.Outline.None || Mathf.Abs(rs.GetOutlineNormalOffset()) > (rs.GetOutlineWidth() + (aaWidth))) { fillAntialiasing = true; } } bool outlineAntialiasing = rs.GetAntialiasingWidth() > 0f; bool multipleMaterials = false; var renderer = rs.GetComponent <Renderer>(); if (renderer != null) { if (renderer.sharedMaterials.GetLength(0) > 1) { multipleMaterials = true; } } RageSpline.RageVertex[] outlineVerts = rs.GenerateOutlineVerts(outlineAntialiasing, multipleMaterials); RageSpline.RageVertex[] fillVerts = rs.GenerateFillVerts(fillAntialiasing, multipleMaterials); int vertexCount = outlineVerts.Length + fillVerts.Length; Vector3[] verts = new Vector3[vertexCount]; Vector2[] uvs = null; Vector2[] uvs2 = null; if (rs.PinUvs) { uvs = new Vector2[vertexCount]; uvs2 = new Vector2[vertexCount]; } Color[] colors = new Color[vertexCount]; for (int i = 0; i < fillVerts.Length; i++) { verts[i] = fillVerts[i].position; colors[i] = fillVerts[i].color; if (uvs == null) { continue; } uvs[i] = fillVerts[i].uv1; uvs2[i] = fillVerts[i].uv2; } for (int i = 0; i < outlineVerts.Length; i++) { int v = i + fillVerts.Length; verts[v] = outlineVerts[i].position; colors[v] = outlineVerts[i].color; if (uvs == null) { continue; } uvs[v] = outlineVerts[i].uv1; uvs2[v] = outlineVerts[i].uv2; } var mFilter = rs.GetComponent(typeof(MeshFilter)) as MeshFilter; if (verts.Length > 0) { verts[0] += new Vector3(0f, 0f, -0.001f); } if (mFilter != null) { var mesh = mFilter.sharedMesh; if (mesh == null) { mesh = new Mesh(); } if (refreshTriangulation) { mesh.Clear(); } //if (rs.optimize) Debug.Log ("mesh verts: " + mesh.vertices.Length + " | triangs: " + mesh.triangles.Length); mesh.vertices = verts; if (refreshTriangulation) { rs.GenerateTriangles(mesh, fillVerts, new RageSpline.RageVertex[0], outlineVerts, fillAntialiasing, false, outlineAntialiasing, multipleMaterials); } if (rs.PinUvs) { mesh.uv = uvs; mesh.uv2 = uvs2; } mesh.colors = colors; mesh.RecalculateBounds(); mFilter.sharedMesh = mesh; } }