public void GenerateOutline_WithScaledDownTexture_ProducesVerticesAndEdges() { var path = "OutlineTests/scaled-down-square"; var textureAsset = Resources.Load <Texture2D>(path); Assert.IsNotNull(textureAsset, "texture asset not found"); var spriteEditorDataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(textureAsset)) as ISpriteEditorDataProvider; spriteEditorDataProvider.InitSpriteEditorDataProvider(); var textureDataProvider = spriteEditorDataProvider.GetDataProvider <ITextureDataProvider>(); var rects = spriteEditorDataProvider.GetSpriteRects(); Assert.AreEqual(1, rects.Length, "Sprite rect not found"); var spriteRect = rects[0]; m_SpriteMeshData.frame = spriteRect.rect; m_SpriteMeshDataController.OutlineFromAlpha(new OutlineGenerator(), textureDataProvider, 0f, 0); Assert.AreEqual(30, m_SpriteMeshData.vertices.Count, "Incorrect number of vertices generated"); Assert.AreEqual(30, m_SpriteMeshData.edges.Count, "Incorrect number of edges generated"); }
void AutoGenerateSpriteSkinData(SpriteMetaData metaData) { //If bone data exist but skinning data doesn't exist, auto generate them if (metaData.spriteBone != null && metaData.spriteBone.Count > 0 && (metaData.vertices == null || metaData.vertices.Count == 0)) { var spriteMeshDataController = new SpriteMeshDataController(); var smd = new SpriteMeshData(); smd.spriteID = metaData.spriteID; smd.frame = metaData.rect; smd.pivot = metaData.pivot; smd.bones = ModuleUtility.CreateSpriteBoneData(metaData.spriteBone.ToArray(), Matrix4x4.TRS(metaData.rect.position, Quaternion.identity, Vector3.one)); spriteMeshDataController.spriteMeshData = smd; spriteMeshDataController.OutlineFromAlpha(new OutlineGenerator(), GetDataProvider <ITextureDataProvider>(), 0.05f, 200); spriteMeshDataController.Triangulate(new Triangulator()); spriteMeshDataController.Subdivide(new Triangulator(), 0.25f); spriteMeshDataController.CalculateWeights(new BoundedBiharmonicWeightsGenerator(), null, 0.01f); spriteMeshDataController.SortTrianglesByDepth(); List <Vertex2DMetaData> vmd = new List <Vertex2DMetaData>(smd.vertices.Count); foreach (var v in smd.vertices) { vmd.Add(new Vertex2DMetaData() { position = v.position - smd.frame.position, boneWeight = v.editableBoneWeight.ToBoneWeight(true) }); } List <Vector2Int> emd = new List <Vector2Int>(smd.edges.Count); foreach (var e in smd.edges) { emd.Add(new Vector2Int(e.index1, e.index2)); } metaData.vertices = vmd; metaData.indices = smd.indices.ToArray(); metaData.edges = emd.ToArray(); } }