public void SortTrianglesByDept_TrianglesAreSortedBySpriteBoneDepth()
        {
            m_SpriteMeshDataController.CreateVertex(Vector2.zero);
            m_SpriteMeshDataController.CreateVertex(Vector2.zero);
            m_SpriteMeshData.vertices[0].editableBoneWeight.SetFromBoneWeight(new BoneWeight()
            {
                weight0 = 1f
            });
            m_SpriteMeshData.vertices[1].editableBoneWeight.SetFromBoneWeight(new BoneWeight()
            {
                boneIndex0 = 1, weight0 = 1f
            });
            m_SpriteMeshData.indices.AddRange(new int[] { 0, 0, 0, 1, 1, 1 });
            m_SpriteMeshData.bones.Add(new SpriteBoneData()
            {
                depth = 1
            });
            m_SpriteMeshData.bones.Add(new SpriteBoneData()
            {
                depth = -1
            });

            m_SpriteMeshDataController.SortTrianglesByDepth();

            Assert.AreEqual(new int[] { 1, 1, 1, 0, 0, 0 }, m_SpriteMeshData.indices.ToArray(), "Incorrect triangles");
        }
Example #2
0
        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();
            }
        }