private static bool TryGetMeshData(Sprite sprite, SpriteConfigData data, out Vector2[] vertices, out ushort[] triangles, MeshRenderType meshRenderType)
        {
            vertices  = Array.Empty <Vector2>();
            triangles = Array.Empty <ushort>();

            if (data == null || !data.overriden)
            {
                return(false);
            }

            Vector2[][] paths = OutlineUtil.GenerateOutline(sprite, data, meshRenderType);
            TriangulationUtil.Triangulate(paths, data.edgeSmoothing, data.useNonZero, out vertices, out triangles);

            //validate
            if (vertices.Length >= ushort.MaxValue)
            {
                Debug.LogErrorFormat($"Too many veretics! Sprite '{sprite.name}' has {vertices.Length} vertices.");
                return(false);
            }

            return(true);
        }
Пример #2
0
        public static bool TryGetVertexAndTriangle2D(this Sprite sprite, SpriteConfigData configData, out Vector2[] vertices, out ushort[] triangles, MeshRenderType meshRenderType)
        {
            vertices  = Array.Empty <Vector2>();
            triangles = Array.Empty <ushort>();

            if (configData == null || sprite == null ||
                configData.mode == SpriteConfigData.Mode.UnityDefaultForTransparent ||
                configData.mode == SpriteConfigData.Mode.UnityDefaultForOpaque)
            {
                return(false);
            }

            Vector2[][] paths = OutlineUtil.GenerateOutline(sprite, configData, meshRenderType);

            if (meshRenderType == MeshRenderType.Grid)
            {
                vertices  = paths[0];
                triangles = new ushort[vertices.Length];

                for (var i = 0; i < triangles.Length; i++)
                {
                    triangles[i] = (ushort)i;
                }
            }
            else
            {
                TriangulationUtil.Triangulate(paths, configData.edgeSmoothing, configData.useNonZero, out vertices, out triangles);
            }

            //validate
            if (vertices.Length >= ushort.MaxValue)
            {
                Debug.LogErrorFormat($"Too many vertices! Sprite '{sprite.name}' has {vertices.Length} vertices.");
                return(false);
            }

            return(true);
        }