public static void TessellateBorder(MeshGenerationContextUtils.BorderParams borderParams, float posZ, MeshBuilder.AllocMeshData meshAlloc) { if (borderParams.rect.width < kEpsilon || borderParams.rect.height < kEpsilon) { return; } Profiler.BeginSample("TessellateBorder"); var halfSize = new Vector2(borderParams.rect.width * 0.5f, borderParams.rect.height * 0.5f); borderParams.topLeftRadius = Vector2.Min(borderParams.topLeftRadius, halfSize); borderParams.topRightRadius = Vector2.Min(borderParams.topRightRadius, halfSize); borderParams.bottomRightRadius = Vector2.Min(borderParams.bottomRightRadius, halfSize); borderParams.bottomLeftRadius = Vector2.Min(borderParams.bottomLeftRadius, halfSize); borderParams.leftWidth = Mathf.Min(borderParams.leftWidth, halfSize.x); borderParams.topWidth = Mathf.Min(borderParams.topWidth, halfSize.y); borderParams.rightWidth = Mathf.Min(borderParams.rightWidth, halfSize.x); borderParams.bottomWidth = Mathf.Min(borderParams.bottomWidth, halfSize.y); UInt16 vertexCount = 0, indexCount = 0; CountBorderTriangles(ref borderParams, ref vertexCount, ref indexCount); var mesh = meshAlloc.Allocate(vertexCount, indexCount); vertexCount = 0; indexCount = 0; TessellateBorderInternal(ref borderParams, posZ, mesh, ref vertexCount, ref indexCount); Debug.Assert(vertexCount == mesh.vertexCount); Debug.Assert(indexCount == mesh.indexCount); Profiler.EndSample(); }
///<summary> /// Tessellates the border OR the content: /// If any of the left/right/top/bottom border parameters is greater than Epsilon, we tessellate ONLY a border. /// Otherwise we tessellate ONLY the content. /// </summary> /// <param name="vertexFlags">Flags are only used for content, not for a border.</param> public static void TessellateRect(MeshGenerationContextUtils.RectangleParams rectParams, float posZ, MeshBuilder.AllocMeshData meshAlloc) { if (rectParams.rect.width < kEpsilon || rectParams.rect.height < kEpsilon) { return; } Profiler.BeginSample("TessellateRect"); var halfSize = new Vector2(rectParams.rect.width * 0.5f, rectParams.rect.height * 0.5f); rectParams.topLeftRadius = Vector2.Min(rectParams.topLeftRadius, halfSize); rectParams.topRightRadius = Vector2.Min(rectParams.topRightRadius, halfSize); rectParams.bottomRightRadius = Vector2.Min(rectParams.bottomRightRadius, halfSize); rectParams.bottomLeftRadius = Vector2.Min(rectParams.bottomLeftRadius, halfSize); UInt16 vertexCount = 0, indexCount = 0; CountRectTriangles(ref rectParams, ref vertexCount, ref indexCount); var mesh = meshAlloc.Allocate(vertexCount, indexCount); vertexCount = 0; indexCount = 0; TessellateRectInternal(ref rectParams, posZ, mesh, ref vertexCount, ref indexCount); if ((mesh.m_Flags == VertexFlags.IsAtlasTexturedPoint) || (mesh.m_Flags == VertexFlags.IsAtlasTexturedBilinear) || (mesh.m_Flags == VertexFlags.IsCustomTextured)) { ComputeUVs(rectParams.rect, rectParams.uv, mesh.uvRegion, mesh.m_Vertices); } Debug.Assert(vertexCount == mesh.vertexCount); Debug.Assert(indexCount == mesh.indexCount); Profiler.EndSample(); }
internal static void MakeText(MeshInfo meshInfo, Vector2 offset, MeshBuilder.AllocMeshData meshAlloc) { int num = MeshBuilder.LimitTextVertices(meshInfo.vertexCount, true); int num2 = num / 4; MeshWriteData meshWriteData = meshAlloc.Allocate((uint)(num2 * 4), (uint)(num2 * 6)); int i = 0; int num3 = 0; int num4 = 0; while (i < num2) { meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3, offset)); meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3 + 1, offset)); meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3 + 2, offset)); meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(meshInfo, num3 + 3, offset)); meshWriteData.SetNextIndex((ushort)num3); meshWriteData.SetNextIndex((ushort)(num3 + 1)); meshWriteData.SetNextIndex((ushort)(num3 + 2)); meshWriteData.SetNextIndex((ushort)(num3 + 2)); meshWriteData.SetNextIndex((ushort)(num3 + 3)); meshWriteData.SetNextIndex((ushort)num3); i++; num3 += 4; num4 += 6; } }
private static void MakeQuad(Rect rcPosition, Rect rcTexCoord, Color color, float posZ, MeshBuilder.AllocMeshData meshAlloc) { MeshWriteData meshWriteData = meshAlloc.Allocate(4u, 6u); float x = rcPosition.x; float xMax = rcPosition.xMax; float yMax = rcPosition.yMax; float y = rcPosition.y; Rect uvRegion = meshWriteData.uvRegion; float x2 = rcTexCoord.x * uvRegion.width + uvRegion.xMin; float x3 = rcTexCoord.xMax * uvRegion.width + uvRegion.xMin; float y2 = rcTexCoord.y * uvRegion.height + uvRegion.yMin; float y3 = rcTexCoord.yMax * uvRegion.height + uvRegion.yMin; meshWriteData.SetNextVertex(new Vertex { position = new Vector3(x, yMax, posZ), tint = color, uv = new Vector2(x2, y2) }); meshWriteData.SetNextVertex(new Vertex { position = new Vector3(xMax, yMax, posZ), tint = color, uv = new Vector2(x3, y2) }); meshWriteData.SetNextVertex(new Vertex { position = new Vector3(x, y, posZ), tint = color, uv = new Vector2(x2, y3) }); meshWriteData.SetNextVertex(new Vertex { position = new Vector3(xMax, y, posZ), tint = color, uv = new Vector2(x3, y3) }); meshWriteData.SetNextIndex(0); meshWriteData.SetNextIndex(2); meshWriteData.SetNextIndex(1); meshWriteData.SetNextIndex(1); meshWriteData.SetNextIndex(2); meshWriteData.SetNextIndex(3); }
internal static void MakeText(NativeArray <UnityEngine.UIElements.TextVertex> uiVertices, Vector2 offset, MeshBuilder.AllocMeshData meshAlloc) { int num = MeshBuilder.LimitTextVertices(uiVertices.Length, true); int num2 = num / 4; MeshWriteData meshWriteData = meshAlloc.Allocate((uint)(num2 * 4), (uint)(num2 * 6)); int i = 0; int num3 = 0; while (i < num2) { meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(uiVertices[num3], offset)); meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(uiVertices[num3 + 1], offset)); meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(uiVertices[num3 + 2], offset)); meshWriteData.SetNextVertex(MeshBuilder.ConvertTextVertexToUIRVertex(uiVertices[num3 + 3], offset)); meshWriteData.SetNextIndex((ushort)num3); meshWriteData.SetNextIndex((ushort)(num3 + 1)); meshWriteData.SetNextIndex((ushort)(num3 + 2)); meshWriteData.SetNextIndex((ushort)(num3 + 2)); meshWriteData.SetNextIndex((ushort)(num3 + 3)); meshWriteData.SetNextIndex((ushort)num3); i++; num3 += 4; } }
internal static void MakeSlicedQuad(ref MeshGenerationContextUtils.RectangleParams rectParams, float posZ, MeshBuilder.AllocMeshData meshAlloc) { MeshWriteData meshWriteData = meshAlloc.Allocate(16u, 54u); float num = 1f; Texture2D texture2D = rectParams.texture as Texture2D; bool flag = texture2D != null; if (flag) { num = texture2D.pixelsPerPoint; } float num2 = (float)rectParams.texture.width; float num3 = (float)rectParams.texture.height; float num4 = num / num2; float num5 = num / num3; float num6 = Mathf.Max(0f, (float)rectParams.leftSlice); float num7 = Mathf.Max(0f, (float)rectParams.rightSlice); float num8 = Mathf.Max(0f, (float)rectParams.bottomSlice); float num9 = Mathf.Max(0f, (float)rectParams.topSlice); float num10 = Mathf.Clamp(num6 * num4, 0f, 1f); float num11 = Mathf.Clamp(num7 * num4, 0f, 1f); float num12 = Mathf.Clamp(num8 * num5, 0f, 1f); float num13 = Mathf.Clamp(num9 * num5, 0f, 1f); MeshBuilder.k_TexCoordSlicesX[0] = rectParams.uv.min.x; MeshBuilder.k_TexCoordSlicesX[1] = rectParams.uv.min.x + num10; MeshBuilder.k_TexCoordSlicesX[2] = rectParams.uv.max.x - num11; MeshBuilder.k_TexCoordSlicesX[3] = rectParams.uv.max.x; MeshBuilder.k_TexCoordSlicesY[0] = rectParams.uv.max.y; MeshBuilder.k_TexCoordSlicesY[1] = rectParams.uv.max.y - num12; MeshBuilder.k_TexCoordSlicesY[2] = rectParams.uv.min.y + num13; MeshBuilder.k_TexCoordSlicesY[3] = rectParams.uv.min.y; Rect uvRegion = meshWriteData.uvRegion; for (int i = 0; i < 4; i++) { MeshBuilder.k_TexCoordSlicesX[i] = MeshBuilder.k_TexCoordSlicesX[i] * uvRegion.width + uvRegion.xMin; MeshBuilder.k_TexCoordSlicesY[i] = (rectParams.uv.min.y + rectParams.uv.max.y - MeshBuilder.k_TexCoordSlicesY[i]) * uvRegion.height + uvRegion.yMin; } float num14 = num6 + num7; bool flag2 = num14 > rectParams.rect.width; if (flag2) { float num15 = rectParams.rect.width / num14; num6 *= num15; num7 *= num15; } float num16 = num8 + num9; bool flag3 = num16 > rectParams.rect.height; if (flag3) { float num17 = rectParams.rect.height / num16; num8 *= num17; num9 *= num17; } MeshBuilder.k_PositionSlicesX[0] = rectParams.rect.x; MeshBuilder.k_PositionSlicesX[1] = rectParams.rect.x + num6; MeshBuilder.k_PositionSlicesX[2] = rectParams.rect.xMax - num7; MeshBuilder.k_PositionSlicesX[3] = rectParams.rect.xMax; MeshBuilder.k_PositionSlicesY[0] = rectParams.rect.yMax; MeshBuilder.k_PositionSlicesY[1] = rectParams.rect.yMax - num8; MeshBuilder.k_PositionSlicesY[2] = rectParams.rect.y + num9; MeshBuilder.k_PositionSlicesY[3] = rectParams.rect.y; for (int j = 0; j < 16; j++) { int num18 = j % 4; int num19 = j / 4; meshWriteData.SetNextVertex(new Vertex { position = new Vector3(MeshBuilder.k_PositionSlicesX[num18], MeshBuilder.k_PositionSlicesY[num19], posZ), uv = new Vector2(MeshBuilder.k_TexCoordSlicesX[num18], MeshBuilder.k_TexCoordSlicesY[num19]), tint = rectParams.color }); } meshWriteData.SetAllIndices(MeshBuilder.slicedQuadIndices); }