void FillMesh(Lines li) { li.ClearMeshes(); var lines = li.lines; if (lines.Count == 0) { return; } int maxLines = 64000 / 4; int meshesCount = lines.Count / maxLines + 1; int lineStartIndex = 0; for (int mi = 0; mi < meshesCount; mi++) { var curLinesCount = (mi == meshesCount - 1) ? lines.Count % maxLines : maxLines; var vertices = new Vector3[curLinesCount * 4]; var tangents = new Vector4[curLinesCount * 4]; var normals = new Vector3[curLinesCount * 4]; var indices = new int[curLinesCount * 6]; int curV = 0; var t0 = new Vector4(-1.0f, -1.0f); var t1 = new Vector4(-1.0f, +1.0f); var t2 = new Vector4(+1.0f, -1.0f); var t3 = new Vector4(+1.0f, +1.0f); for (int i = 0; i < curLinesCount; i++) { var l = lines[i + lineStartIndex]; var t = l.b - l.a; vertices[curV] = l.a; tangents[curV] = t0; normals[curV] = t; curV++; vertices[curV] = l.a; tangents[curV] = t1; normals[curV] = t; curV++; vertices[curV] = l.b; tangents[curV] = t2; normals[curV] = t; curV++; vertices[curV] = l.b; tangents[curV] = t3; normals[curV] = t; curV++; indices[i * 6 + 0] = i * 4 + 0; indices[i * 6 + 1] = i * 4 + 1; indices[i * 6 + 2] = i * 4 + 2; indices[i * 6 + 3] = i * 4 + 3; indices[i * 6 + 4] = i * 4 + 2; indices[i * 6 + 5] = i * 4 + 1; } var mesh = CreateMesh(li, li.style); mesh.vertices = vertices; mesh.tangents = tangents; mesh.normals = normals; mesh.SetIndices(indices, MeshTopology.Triangles, 0, true); //mesh.RecalculateBounds(); lineStartIndex += curLinesCount; } }
void FillMesh(Lines li) { li.ClearMeshes(); bool needStitchPhase = li.style.dashes.Length > 1; var lines = li.lines; if (lines.Count == 0) { return; } int maxLines = 64000 / 4; int meshesCount = lines.Count / maxLines + 1; int lineStartIndex = 0; for (int mi = 0; mi < meshesCount; mi++) { var curLinesCount = (mi == meshesCount - 1) ? lines.Count % maxLines : maxLines; var vertices = new Vector3[curLinesCount * 4]; var tangents = new Vector4[curLinesCount * 4]; var normals = new Vector3[curLinesCount * 4]; var coords = new Vector2[curLinesCount * 4]; Vector3[] normalsLeft = null; Vector3[] normalsRight = null; if (UseSilhouetteNormals) { normalsLeft = new Vector3[curLinesCount * 4]; normalsRight = new Vector3[curLinesCount * 4]; } var indices = new int[curLinesCount * 6]; int curV = 0; var t0 = new Vector4(-1.0f, -1.0f); var t1 = new Vector4(-1.0f, +1.0f); var t2 = new Vector4(+1.0f, -1.0f); var t3 = new Vector4(+1.0f, +1.0f); float phase = 0f; for (int i = 0; i < curLinesCount; i++) { var l = lines[i + lineStartIndex]; bool needZeroPhase = false; if (needStitchPhase && i < curLinesCount - 1) { var nl = lines[i + 1 + lineStartIndex]; if (l.b == nl.b) { nl.Swap(); lines[i + 1 + lineStartIndex] = nl; } else if (l.a == nl.b) { nl.Swap(); lines[i + 1 + lineStartIndex] = nl; l.Swap(); } else if (l.a == nl.a) { l.Swap(); } if (l.b != nl.a) { needZeroPhase = true; } } var t = l.b - l.a; vertices[curV] = l.a; tangents[curV] = t0; normals[curV] = t; coords[curV] = new Vector2(phase, -1f); if (UseSilhouetteNormals) { normalsLeft[curV] = l.nl; normalsRight[curV] = l.nr; } curV++; vertices[curV] = l.a; tangents[curV] = t1; normals[curV] = t; coords[curV] = new Vector2(phase, 1f); if (UseSilhouetteNormals) { normalsLeft[curV] = l.nl; normalsRight[curV] = l.nr; } curV++; phase += t.magnitude; vertices[curV] = l.b; tangents[curV] = t2; normals[curV] = t; coords[curV] = new Vector2(phase, -1f); if (UseSilhouetteNormals) { normalsLeft[curV] = l.nl; normalsRight[curV] = l.nr; } curV++; vertices[curV] = l.b; tangents[curV] = t3; normals[curV] = t; coords[curV] = new Vector2(phase, 1f); if (UseSilhouetteNormals) { normalsLeft[curV] = l.nl; normalsRight[curV] = l.nr; } curV++; indices[i * 6 + 0] = i * 4 + 0; indices[i * 6 + 1] = i * 4 + 1; indices[i * 6 + 2] = i * 4 + 2; indices[i * 6 + 3] = i * 4 + 3; indices[i * 6 + 4] = i * 4 + 2; indices[i * 6 + 5] = i * 4 + 1; if (needZeroPhase) { //Debug.LogFormat("clear phase {0} {1}", l.b.ToStr(), nl.a.ToStr()); phase = 0f; } } var mesh = CreateMesh(li, li.style); mesh.vertices = vertices; mesh.tangents = tangents; mesh.normals = normals; if (UseSilhouetteNormals) { mesh.SetUVs(1, normalsLeft); mesh.SetUVs(2, normalsRight); } mesh.uv = coords; mesh.SetIndices(indices, MeshTopology.Triangles, 0, true); //mesh.RecalculateBounds(); lineStartIndex += curLinesCount; } }