public void OutlineFromAlpha(IOutlineGenerator outlineGenerator, ITextureDataProvider textureDataProvider, float outlineDetail, byte alphaTolerance) { Debug.Assert(spriteMeshData != null, "Assert failed. Expected: spriteMeshData != null. Actual: spriteMeshData == null"); Debug.Assert(textureDataProvider != null, "Assert failed. Expected: textureDataProvider != null. Actual: textureDataProvider == null"); Debug.Assert(textureDataProvider.texture != null, "Assert failed. Expected: textureDataProvider.texture != null. Actual: textureDataProvider.texture == null"); int width, height; textureDataProvider.GetTextureActualWidthAndHeight(out width, out height); Vector2 scale = new Vector2(textureDataProvider.texture.width / (float)width, textureDataProvider.texture.height / (float)height); Vector2 scaleInv = new Vector2(1f / scale.x, 1f / scale.y); Vector2 rectOffset = spriteMeshData.frame.size * 0.5f; Rect scaledRect = spriteMeshData.frame; scaledRect.min = Vector2.Scale(scaledRect.min, scale); scaledRect.max = Vector2.Scale(scaledRect.max, scale); spriteMeshData.Clear(); Vector2[][] paths; outlineGenerator.GenerateOutline(textureDataProvider, scaledRect, outlineDetail, alphaTolerance, false, out paths); int vertexIndexBase = 0; for (int i = 0; i < paths.Length; ++i) { int numPathVertices = paths[i].Length; for (int j = 0; j <= numPathVertices; j++) { if (j < numPathVertices) { spriteMeshData.AddVertex(Vector2.Scale(paths[i][j], scaleInv) + rectOffset, default(BoneWeight)); } if (j > 0) { spriteMeshData.edges.Add(new Edge(vertexIndexBase + j - 1, vertexIndexBase + j % numPathVertices)); } } vertexIndexBase += numPathVertices; } }
internal override void OnCreate() { m_Triangulator = new Triangulator(); m_OutlineGenerator = new OutlineGenerator(); m_WeightGenerator = new BoundedBiharmonicWeightsGenerator(); }