Пример #1
0
        internal static void MakeText(NativeArray <TextVertex> uiVertices, Vector2 offset, AllocMeshData meshAlloc)
        {
            int quadCount = uiVertices.Length / 4;

            if (quadCount > k_MaxTextQuadCount)
            {
                Debug.LogError("MakeTextMeshHandle: text is too long and generates too many vertices");
                quadCount = k_MaxTextQuadCount;
            }

            var mesh = meshAlloc.Allocate((uint)(quadCount * 4), (uint)(quadCount * 6));

            for (int q = 0, v = 0; q < quadCount; ++q, v += 4)
            {
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 0], offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 1], offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 2], offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 3], offset));

                mesh.SetNextIndex((UInt16)(v + 0));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 1));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 0));
                mesh.SetNextIndex((UInt16)(v + 3));
            }
        }
Пример #2
0
        internal static void MakeText(TextCore.MeshInfo meshInfo, Vector2 offset, AllocMeshData meshAlloc)
        {
            int quadCount = meshInfo.vertexCount / 4;

            if (quadCount > k_MaxTextQuadCount)
            {
                Debug.LogError("MakeText: text is too long and generates too many vertices");
                quadCount = k_MaxTextQuadCount;
            }

            var mesh = meshAlloc.Allocate((uint)(quadCount * 4), (uint)(quadCount * 6));

            for (int q = 0, v = 0, i = 0; q < quadCount; ++q, v += 4, i += 6)
            {
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 0, offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 1, offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 2, offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 3, offset));

                mesh.SetNextIndex((UInt16)(v + 0));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 1));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 0));
                mesh.SetNextIndex((UInt16)(v + 3));
            }
        }
Пример #3
0
        private static void MakeSlicedQuad(ref MeshGenerationContextUtils.RectangleParams rectParams, float posZ, AllocMeshData meshAlloc)
        {
            var mesh = meshAlloc.Allocate(16, 9 * 6);

            float pixelsPerPoint = 1;
            var   texture2D      = rectParams.texture as Texture2D;

            if (texture2D != null)
            {
                pixelsPerPoint = texture2D.pixelsPerPoint;
            }

            float uConversion = pixelsPerPoint / rectParams.texture.width;
            float vConversion = pixelsPerPoint / rectParams.texture.height;

            k_TexCoordSlicesX[0] = rectParams.uv.min.x;
            k_TexCoordSlicesX[1] = rectParams.uv.min.x + rectParams.leftSlice * uConversion;
            k_TexCoordSlicesX[2] = rectParams.uv.max.x - rectParams.rightSlice * uConversion;
            k_TexCoordSlicesX[3] = rectParams.uv.max.x;

            k_TexCoordSlicesY[0] = rectParams.uv.max.y;
            k_TexCoordSlicesY[1] = rectParams.uv.max.y - rectParams.bottomSlice * vConversion;
            k_TexCoordSlicesY[2] = rectParams.uv.min.y + rectParams.topSlice * vConversion;
            k_TexCoordSlicesY[3] = rectParams.uv.min.y;

            var uvRegion = mesh.uvRegion;

            for (int i = 0; i < 4; i++)
            {
                k_TexCoordSlicesX[i] = k_TexCoordSlicesX[i] * uvRegion.width + uvRegion.xMin;
                k_TexCoordSlicesY[i] = (rectParams.uv.min.y + rectParams.uv.max.y - k_TexCoordSlicesY[i]) * uvRegion.height + uvRegion.yMin;
            }

            k_PositionSlicesX[0] = rectParams.rect.x;
            k_PositionSlicesX[1] = rectParams.rect.x + rectParams.leftSlice;
            k_PositionSlicesX[2] = rectParams.rect.xMax - rectParams.rightSlice;
            k_PositionSlicesX[3] = rectParams.rect.xMax;

            k_PositionSlicesY[0] = rectParams.rect.yMax;
            k_PositionSlicesY[1] = rectParams.rect.yMax - rectParams.bottomSlice;
            k_PositionSlicesY[2] = rectParams.rect.y + rectParams.topSlice;
            k_PositionSlicesY[3] = rectParams.rect.y;

            float flags = (float)mesh.m_Flags;

            for (int i = 0; i < 16; ++i)
            {
                int x = i % 4;
                int y = i / 4;
                mesh.SetNextVertex(new Vertex()
                {
                    position = new Vector3(k_PositionSlicesX[x], k_PositionSlicesY[y], posZ),
                    uv       = new Vector2(k_TexCoordSlicesX[x], k_TexCoordSlicesY[y]),
                    tint     = rectParams.color,
                    flags    = flags
                });
            }
            mesh.SetAllIndices(slicedQuadIndices);
        }
Пример #4
0
        private static void MakeQuad(Rect rcPosition, Rect rcTexCoord, Color color, float posZ, AllocMeshData meshAlloc)
        {
            var mesh = meshAlloc.Allocate(4, 6);

            float x0 = rcPosition.x;
            float x3 = rcPosition.xMax;
            float y0 = rcPosition.yMax;
            float y3 = rcPosition.y;

            var   uvRegion = mesh.uvRegion;
            float u0       = rcTexCoord.x * uvRegion.width + uvRegion.xMin;
            float u3       = rcTexCoord.xMax * uvRegion.width + uvRegion.xMin;
            float v0       = rcTexCoord.y * uvRegion.height + uvRegion.yMin;
            float v3       = rcTexCoord.yMax * uvRegion.height + uvRegion.yMin;

            float flags = (float)mesh.m_Flags;

            mesh.SetNextVertex(new Vertex()
            {
                position = new Vector3(x0, y0, posZ),
                tint     = color,
                uv       = new Vector2(u0, v0),
                flags    = flags
            });
            mesh.SetNextVertex(new Vertex()
            {
                position = new Vector3(x3, y0, posZ),
                tint     = color,
                uv       = new Vector2(u3, v0),
                flags    = flags
            });
            mesh.SetNextVertex(new Vertex()
            {
                position = new Vector3(x0, y3, posZ),
                tint     = color,
                uv       = new Vector2(u0, v3),
                flags    = flags
            });
            mesh.SetNextVertex(new Vertex()
            {
                position = new Vector3(x3, y3, posZ),
                tint     = color,
                uv       = new Vector2(u3, v3),
                flags    = flags
            });

            mesh.SetNextIndex(0);
            mesh.SetNextIndex(1);
            mesh.SetNextIndex(2);

            mesh.SetNextIndex(1);
            mesh.SetNextIndex(3);
            mesh.SetNextIndex(2);
        }
Пример #5
0
        internal static void MakeText(NativeArray <TextVertex> uiVertices, Vector2 offset, AllocMeshData meshAlloc)
        {
            int vertexCount = LimitTextVertices(uiVertices.Length);
            int quadCount   = vertexCount / 4;
            var mesh        = meshAlloc.Allocate((uint)(quadCount * 4), (uint)(quadCount * 6));

            for (int q = 0, v = 0; q < quadCount; ++q, v += 4)
            {
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 0], offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 1], offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 2], offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(uiVertices[v + 3], offset));

                mesh.SetNextIndex((UInt16)(v + 0));
                mesh.SetNextIndex((UInt16)(v + 1));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 3));
                mesh.SetNextIndex((UInt16)(v + 0));
            }
        }
Пример #6
0
        internal static void MakeText(TextCore.MeshInfo meshInfo, Vector2 offset, AllocMeshData meshAlloc)
        {
            int vertexCount = LimitTextVertices(meshInfo.vertexCount);
            int quadCount   = vertexCount / 4;
            var mesh        = meshAlloc.Allocate((uint)(quadCount * 4), (uint)(quadCount * 6));

            for (int q = 0, v = 0, i = 0; q < quadCount; ++q, v += 4, i += 6)
            {
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 0, offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 1, offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 2, offset));
                mesh.SetNextVertex(ConvertTextVertexToUIRVertex(meshInfo, v + 3, offset));

                mesh.SetNextIndex((UInt16)(v + 0));
                mesh.SetNextIndex((UInt16)(v + 1));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 2));
                mesh.SetNextIndex((UInt16)(v + 3));
                mesh.SetNextIndex((UInt16)(v + 0));
            }
        }
Пример #7
0
        internal static void MakeSlicedQuad(ref MeshGenerationContextUtils.RectangleParams rectParams, float posZ, AllocMeshData meshAlloc)
        {
            var mesh = meshAlloc.Allocate(16, 9 * 6);

            float pixelsPerPoint = 1;
            var   texture2D      = rectParams.texture as Texture2D;

            if (texture2D != null)
            {
                pixelsPerPoint = texture2D.pixelsPerPoint;
            }

            float texWidth    = rectParams.texture.width;
            float texHeight   = rectParams.texture.height;
            float uConversion = pixelsPerPoint / texWidth;
            float vConversion = pixelsPerPoint / texHeight;

            float leftSlice   = Mathf.Max(0.0f, rectParams.leftSlice);
            float rightSlice  = Mathf.Max(0.0f, rectParams.rightSlice);
            float bottomSlice = Mathf.Max(0.0f, rectParams.bottomSlice);
            float topSlice    = Mathf.Max(0.0f, rectParams.topSlice);

            // Clamp UVs in the [0,1] range
            float uvLeftSlice   = Mathf.Clamp(leftSlice * uConversion, 0.0f, 1.0f);
            float uvRightSlice  = Mathf.Clamp(rightSlice * uConversion, 0.0f, 1.0f);
            float uvBottomSlice = Mathf.Clamp(bottomSlice * vConversion, 0.0f, 1.0f);
            float uvTopslice    = Mathf.Clamp(topSlice * vConversion, 0.0f, 1.0f);

            k_TexCoordSlicesX[0] = rectParams.uv.min.x;
            k_TexCoordSlicesX[1] = rectParams.uv.min.x + uvLeftSlice;
            k_TexCoordSlicesX[2] = rectParams.uv.max.x - uvRightSlice;
            k_TexCoordSlicesX[3] = rectParams.uv.max.x;

            k_TexCoordSlicesY[0] = rectParams.uv.max.y;
            k_TexCoordSlicesY[1] = rectParams.uv.max.y - uvBottomSlice;
            k_TexCoordSlicesY[2] = rectParams.uv.min.y + uvTopslice;
            k_TexCoordSlicesY[3] = rectParams.uv.min.y;

            var uvRegion = mesh.uvRegion;

            for (int i = 0; i < 4; i++)
            {
                k_TexCoordSlicesX[i] = k_TexCoordSlicesX[i] * uvRegion.width + uvRegion.xMin;
                k_TexCoordSlicesY[i] = (rectParams.uv.min.y + rectParams.uv.max.y - k_TexCoordSlicesY[i]) * uvRegion.height + uvRegion.yMin;
            }

            // Prevent overlapping slices
            float sliceWidth = (leftSlice + rightSlice);

            if (sliceWidth > rectParams.rect.width)
            {
                float rescale = rectParams.rect.width / sliceWidth;
                leftSlice  *= rescale;
                rightSlice *= rescale;
            }

            float sliceHeight = (bottomSlice + topSlice);

            if (sliceHeight > rectParams.rect.height)
            {
                float rescale = rectParams.rect.height / sliceHeight;
                bottomSlice *= rescale;
                topSlice    *= rescale;
            }

            k_PositionSlicesX[0] = rectParams.rect.x;
            k_PositionSlicesX[1] = rectParams.rect.x + leftSlice;
            k_PositionSlicesX[2] = rectParams.rect.xMax - rightSlice;
            k_PositionSlicesX[3] = rectParams.rect.xMax;

            k_PositionSlicesY[0] = rectParams.rect.yMax;
            k_PositionSlicesY[1] = rectParams.rect.yMax - bottomSlice;
            k_PositionSlicesY[2] = rectParams.rect.y + topSlice;
            k_PositionSlicesY[3] = rectParams.rect.y;

            for (int i = 0; i < 16; ++i)
            {
                int x = i % 4;
                int y = i / 4;
                mesh.SetNextVertex(new Vertex()
                {
                    position = new Vector3(k_PositionSlicesX[x], k_PositionSlicesY[y], posZ),
                    uv       = new Vector2(k_TexCoordSlicesX[x], k_TexCoordSlicesY[y]),
                    tint     = rectParams.color
                });
            }
            mesh.SetAllIndices(slicedQuadIndices);
        }