【问题标题】:Vertex array is too large. A sprite mesh may not have more than 65535 vertices. Unity顶点数组太大。一个精灵网格不能有超过 65535 个顶点。统一
【发布时间】:2020-08-10 07:24:43
【问题描述】:

我尝试统一使用 svg 文件

我在包管理器中设置了vectorgraphics 2.00

但出现导入文件错误

我的 svgfile 最大大小是顶点 2500 亿和 7mb

我知道网格最大顶点 4000 亿,但我不知道 sprite 最大顶点

平均大小 1600kb 图片this

Vertex array is too large. A sprite mesh may not have more than 65535 vertices.
UnityEngine.Sprite:OverrideGeometry(Vector2[], UInt16[])
Unity.VectorGraphics.VectorUtils:BuildSprite(List`1, Rect, Single, Alignment, Vector2, UInt16, Boolean) (at Library/PackageCache/com.unity.vectorgraphics@2.0.0-preview.12/Runtime/VectorSprite.cs:119)
Unity.VectorGraphics.Editor.SVGImporter:BuildSpriteFromGeometry(List`1, Rect) (at Library/PackageCache/com.unity.vectorgraphics@2.0.0-preview.12/Editor/SVGImporter.cs:344)
Unity.VectorGraphics.Editor.SVGImporter:OnImportAsset(AssetImportContext) (at Library/PackageCache/com.unity.vectorgraphics@2.0.0-preview.12/Editor/SVGImporter.cs:317)
UnityEditor.Experimental.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)
UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

 public static Sprite BuildSprite(List<Geometry> geoms, Rect rect, float svgPixelsPerUnit, Alignment alignment, Vector2 customPivot, UInt16 gradientResolution, bool flipYAxis = false)
    {
        // Generate atlas
        var texAtlas = GenerateAtlasAndFillUVs(geoms, gradientResolution);

        List<Vector2> vertices;
        List<UInt16> indices;
        List<Color> colors;
        List<Vector2> uvs;
        List<Vector2> settingIndices;
        FillVertexChannels(geoms, 1.0f, texAtlas != null, out vertices, out indices, out colors, out uvs, out settingIndices, flipYAxis);

        Texture2D texture = texAtlas != null ? texAtlas.Texture : null;

        if (rect == Rect.zero)
        {
            rect = VectorUtils.Bounds(vertices);
            VectorUtils.RealignVerticesInBounds(vertices, rect, flipYAxis);
        }
        else if (flipYAxis)
        {
            VectorUtils.FlipVerticesInBounds(vertices, rect);

            // The provided rect should normally contain the whole geometry, but since VectorUtils.SceneNodeBounds doesn't
            // take the strokes into account, some triangles may appear outside the rect. We clamp the vertices as a workaround for now.
            VectorUtils.ClampVerticesInBounds(vertices, rect);
        }

        var pivot = GetPivot(alignment, customPivot, rect, flipYAxis);

        // The Sprite.Create(Rect, Vector2, float, Texture2D) method is internal. Using reflection
        // until it becomes public.
        var spriteCreateMethod = typeof(Sprite).GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic, Type.DefaultBinder, new Type[] { typeof(Rect), typeof(Vector2), typeof(float), typeof(Texture2D) }, null);
      //it is error part

var sprite = spriteCreateMethod.Invoke(null, new object[] { rect, pivot, svgPixelsPerUnit, texture }) as Sprite;

                    //it is error part  
            sprite.OverrideGeometry(vertices.ToArray(), indices.ToArray());
            

【问题讨论】:

  • 看起来您需要在导入之前简化要导入的文件。
  • @RobertLongson SVG 裁剪简单吗?如果你剪切一个svg,你能确保在屏幕上显示不同的svg时,彼此的位置关系不会被破坏吗?
  • 并非如此。您可能会发现像 Inkscape 这样的 SVG 编辑器具有一些简化 SVG 文件的功能。切割和重新组装对于此处的问答来说过于宽泛,您需要尝试并提出更具体的问题。
  • 您可以将Mesh.indexFormat 网格索引器格式更改为UInt32,它最多允许4,294,967,295,但您真的不应该开始使用反射...看起来一般您应该采取那里的不同路线
  • 你为什么不例如使用正确的 Sprite.Create(Texture2D, Rect, Vector2, float) 重载 ... ?

标签: c# unity3d svg


【解决方案1】:

不是结果

svg 项目被删除

【讨论】:

    猜你喜欢
    • 2018-02-09
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 2021-05-04
    相关资源
    最近更新 更多