Пример #1
0
        private static MeshBuilder.ClipCounts UpperBoundApproximateRectClippingResults(Vertex[] vertices, ushort[] indices, Vector4 clipRectMinMax)
        {
            MeshBuilder.ClipCounts clipCounts = default(MeshBuilder.ClipCounts);
            clipCounts.firstClippedIndex    = 2147483647;
            clipCounts.firstDegenerateIndex = -1;
            clipCounts.lastClippedIndex     = -1;
            int num = indices.Length;

            for (int i = 0; i < num; i += 3)
            {
                Vector3 position  = vertices[(int)indices[i]].position;
                Vector3 position2 = vertices[(int)indices[i + 1]].position;
                Vector3 position3 = vertices[(int)indices[i + 2]].position;
                Vector4 vector;
                vector.x = ((position.x < position2.x) ? position.x : position2.x);
                vector.x = ((vector.x < position3.x) ? vector.x : position3.x);
                vector.y = ((position.y < position2.y) ? position.y : position2.y);
                vector.y = ((vector.y < position3.y) ? vector.y : position3.y);
                vector.z = ((position.x > position2.x) ? position.x : position2.x);
                vector.z = ((vector.z > position3.x) ? vector.z : position3.x);
                vector.w = ((position.y > position2.y) ? position.y : position2.y);
                vector.w = ((vector.w > position3.y) ? vector.w : position3.y);
                bool flag = vector.x >= clipRectMinMax.x && vector.z <= clipRectMinMax.z && vector.y >= clipRectMinMax.y && vector.w <= clipRectMinMax.w;
                if (flag)
                {
                    clipCounts.firstDegenerateIndex = -1;
                }
                else
                {
                    clipCounts.firstClippedIndex = ((clipCounts.firstClippedIndex < i) ? clipCounts.firstClippedIndex : i);
                    clipCounts.lastClippedIndex  = i + 2;
                    bool flag2 = vector.x >= clipRectMinMax.z || vector.z <= clipRectMinMax.x || vector.y >= clipRectMinMax.w || vector.w <= clipRectMinMax.y;
                    if (flag2)
                    {
                        clipCounts.firstDegenerateIndex = ((clipCounts.firstDegenerateIndex == -1) ? i : clipCounts.firstDegenerateIndex);
                        clipCounts.degenerateTriangles++;
                    }
                    clipCounts.firstDegenerateIndex = -1;
                    clipCounts.clippedTriangles++;
                    clipCounts.addedTriangles += 4;
                }
            }
            return(clipCounts);
        }
Пример #2
0
        private unsafe static void RectClip(Vertex[] vertices, ushort[] indices, Vector4 clipRectMinMax, MeshWriteData mwd, MeshBuilder.ClipCounts cc, ref int newVertexCount)
        {
            int  num  = cc.lastClippedIndex;
            bool flag = cc.firstDegenerateIndex != -1 && cc.firstDegenerateIndex < num;

            if (flag)
            {
                num = cc.firstDegenerateIndex;
            }
            ushort num2 = (ushort)vertices.Length;

            for (int i = 0; i < cc.firstClippedIndex; i++)
            {
                mwd.SetNextIndex(indices[i]);
            }
            ushort *ptr  = stackalloc ushort[3];
            Vertex *ptr2 = stackalloc Vertex[3];

            for (int j = cc.firstClippedIndex; j < num; j += 3)
            {
                *ptr = indices[j];
                ptr[1] = indices[j + 1];
                ptr[2] = indices[j + 2];
                *ptr2 = vertices[(int)(*ptr)];
                ptr2[1] = vertices[(int)ptr[1]];
                ptr2[2] = vertices[(int)ptr[2]];
                Vector4 vector;
                vector.x = ((ptr2->position.x < ptr2[1].position.x) ? ptr2->position.x : ptr2[1].position.x);
                vector.x = ((vector.x < ptr2[2].position.x) ? vector.x : ptr2[2].position.x);
                vector.y = ((ptr2->position.y < ptr2[1].position.y) ? ptr2->position.y : ptr2[1].position.y);
                vector.y = ((vector.y < ptr2[2].position.y) ? vector.y : ptr2[2].position.y);
                vector.z = ((ptr2->position.x > ptr2[1].position.x) ? ptr2->position.x : ptr2[1].position.x);
                vector.z = ((vector.z > ptr2[2].position.x) ? vector.z : ptr2[2].position.x);
                vector.w = ((ptr2->position.y > ptr2[1].position.y) ? ptr2->position.y : ptr2[1].position.y);
                vector.w = ((vector.w > ptr2[2].position.y) ? vector.w : ptr2[2].position.y);
                bool flag2 = vector.x >= clipRectMinMax.x && vector.z <= clipRectMinMax.z && vector.y >= clipRectMinMax.y && vector.w <= clipRectMinMax.w;
                if (flag2)
                {
                    mwd.SetNextIndex(*ptr);
                    mwd.SetNextIndex(ptr[1]);
                    mwd.SetNextIndex(ptr[2]);
                }
                else
                {
                    bool flag3 = vector.x >= clipRectMinMax.z || vector.z <= clipRectMinMax.x || vector.y >= clipRectMinMax.w || vector.w <= clipRectMinMax.y;
                    if (!flag3)
                    {
                        MeshBuilder.RectClipTriangle(ptr2, ptr, clipRectMinMax, mwd, ref num2);
                    }
                }
            }
            int num3 = indices.Length;

            for (int k = cc.lastClippedIndex + 1; k < num3; k++)
            {
                mwd.SetNextIndex(indices[k]);
            }
            newVertexCount = (int)num2;
            mwd.m_Vertices = mwd.m_Vertices.Slice(0, newVertexCount);
            mwd.m_Indices  = mwd.m_Indices.Slice(0, mwd.currentIndex);
        }
Пример #3
0
        internal static void MakeVectorGraphicsStretchBackground(Vertex[] svgVertices, ushort[] svgIndices, float svgWidth, float svgHeight, Rect targetRect, Rect sourceUV, ScaleMode scaleMode, Color tint, int settingIndexOffset, MeshBuilder.AllocMeshData meshAlloc, out int finalVertexCount, out int finalIndexCount)
        {
            Vector2 vector  = new Vector2(svgWidth * sourceUV.width, svgHeight * sourceUV.height);
            Vector2 vector2 = new Vector2(sourceUV.xMin * svgWidth, sourceUV.yMin * svgHeight);
            Rect    rect    = new Rect(vector2, vector);
            bool    flag    = sourceUV.xMin != 0f || sourceUV.yMin != 0f || sourceUV.width != 1f || sourceUV.height != 1f;
            float   num     = vector.x / vector.y;
            float   num2    = targetRect.width / targetRect.height;
            Vector2 vector3;
            Vector2 vector4;

            switch (scaleMode)
            {
            case ScaleMode.StretchToFill:
                vector3   = new Vector2(0f, 0f);
                vector4.x = targetRect.width / vector.x;
                vector4.y = targetRect.height / vector.y;
                break;

            case ScaleMode.ScaleAndCrop:
            {
                vector3 = new Vector2(0f, 0f);
                bool flag2 = num2 > num;
                if (flag2)
                {
                    vector4.x = (vector4.y = targetRect.width / vector.x);
                    float num3 = targetRect.height / vector4.y;
                    float num4 = rect.height / 2f - num3 / 2f;
                    vector3.y  -= num4 * vector4.y;
                    rect.y     += num4;
                    rect.height = num3;
                    flag        = true;
                }
                else
                {
                    bool flag3 = num2 < num;
                    if (flag3)
                    {
                        vector4.x = (vector4.y = targetRect.height / vector.y);
                        float num5 = targetRect.width / vector4.x;
                        float num6 = rect.width / 2f - num5 / 2f;
                        vector3.x -= num6 * vector4.x;
                        rect.x    += num6;
                        rect.width = num5;
                        flag       = true;
                    }
                    else
                    {
                        vector4.x = (vector4.y = targetRect.width / vector.x);
                    }
                }
                break;
            }

            case ScaleMode.ScaleToFit:
            {
                bool flag4 = num2 > num;
                if (flag4)
                {
                    vector4.x = (vector4.y = targetRect.height / vector.y);
                    vector3.x = (targetRect.width - vector.x * vector4.x) * 0.5f;
                    vector3.y = 0f;
                }
                else
                {
                    vector4.x = (vector4.y = targetRect.width / vector.x);
                    vector3.x = 0f;
                    vector3.y = (targetRect.height - vector.y * vector4.y) * 0.5f;
                }
                break;
            }

            default:
                throw new NotImplementedException();
            }
            MeshBuilder.s_VectorGraphicsStretch.Begin();
            vector3 -= vector2 * vector4;
            int num7 = svgVertices.Length;
            int num8 = svgIndices.Length;

            MeshBuilder.ClipCounts clipCounts = default(MeshBuilder.ClipCounts);
            Vector4 zero  = Vector4.zero;
            bool    flag5 = flag;

            if (flag5)
            {
                bool flag6 = rect.width <= 0f || rect.height <= 0f;
                if (flag6)
                {
                    finalVertexCount = (finalIndexCount = 0);
                    MeshBuilder.s_VectorGraphicsStretch.End();
                    return;
                }
                zero       = new Vector4(rect.xMin, rect.yMin, rect.xMax, rect.yMax);
                clipCounts = MeshBuilder.UpperBoundApproximateRectClippingResults(svgVertices, svgIndices, zero);
                num7      += clipCounts.clippedTriangles * 6;
                num8      += clipCounts.addedTriangles * 3;
                num8      -= clipCounts.degenerateTriangles * 3;
            }
            MeshWriteData meshWriteData = meshAlloc.alloc((uint)num7, (uint)num8, ref meshAlloc);
            bool          flag7         = flag;

            if (flag7)
            {
                MeshBuilder.RectClip(svgVertices, svgIndices, zero, meshWriteData, clipCounts, ref num7);
            }
            else
            {
                meshWriteData.SetAllIndices(svgIndices);
            }
            Debug.Assert(meshWriteData.currentVertex == 0);
            Rect uvRegion = meshWriteData.uvRegion;
            int  num9     = svgVertices.Length;

            for (int i = 0; i < num9; i++)
            {
                Vertex vertex = svgVertices[i];
                vertex.position.x = vertex.position.x * vector4.x + vector3.x;
                vertex.position.y = vertex.position.y * vector4.y + vector3.y;
                vertex.uv.x       = vertex.uv.x * uvRegion.width + uvRegion.xMin;
                vertex.uv.y       = vertex.uv.y * uvRegion.height + uvRegion.yMin;
                vertex.tint      *= tint;
                uint num10 = (uint)(((int)vertex.opacityPageSVGSettingIndex.b << 8 | (int)vertex.opacityPageSVGSettingIndex.a) + settingIndexOffset);
                vertex.opacityPageSVGSettingIndex.b = (byte)(num10 >> 8);
                vertex.opacityPageSVGSettingIndex.a = (byte)num10;
                meshWriteData.SetNextVertex(vertex);
            }
            for (int j = num9; j < num7; j++)
            {
                Vertex vertex2 = meshWriteData.m_Vertices[j];
                vertex2.position.x = vertex2.position.x * vector4.x + vector3.x;
                vertex2.position.y = vertex2.position.y * vector4.y + vector3.y;
                vertex2.uv.x       = vertex2.uv.x * uvRegion.width + uvRegion.xMin;
                vertex2.uv.y       = vertex2.uv.y * uvRegion.height + uvRegion.yMin;
                vertex2.tint      *= tint;
                uint num11 = (uint)(((int)vertex2.opacityPageSVGSettingIndex.b << 8 | (int)vertex2.opacityPageSVGSettingIndex.a) + settingIndexOffset);
                vertex2.opacityPageSVGSettingIndex.b = (byte)(num11 >> 8);
                vertex2.opacityPageSVGSettingIndex.a = (byte)num11;
                meshWriteData.SetNextVertex(vertex2);
            }
            finalVertexCount = meshWriteData.vertexCount;
            finalIndexCount  = meshWriteData.indexCount;
            MeshBuilder.s_VectorGraphicsStretch.End();
        }