Ejemplo n.º 1
0
        public void CreateVertex_SetsAverageWeightsFromNeighboursToNewVertex()
        {
            m_SpriteMeshData.CreateVertex(Vector2.zero);
            m_SpriteMeshData.CreateVertex(Vector2.right);
            m_SpriteMeshData.CreateVertex(Vector2.one);
            m_SpriteMeshData.CreateVertex(Vector2.up);

            m_SpriteMeshData.vertices[0].editableBoneWeight.SetFromBoneWeight(new BoneWeight()
            {
                boneIndex0 = 0, weight0 = 1f
            });
            m_SpriteMeshData.vertices[1].editableBoneWeight.SetFromBoneWeight(new BoneWeight()
            {
                boneIndex0 = 1, weight0 = 1f
            });
            m_SpriteMeshData.vertices[2].editableBoneWeight.SetFromBoneWeight(new BoneWeight()
            {
                boneIndex0 = 2, weight0 = 1f
            });
            m_SpriteMeshData.vertices[3].editableBoneWeight.SetFromBoneWeight(new BoneWeight()
            {
                boneIndex0 = 3, weight0 = 1f
            });

            m_SpriteMeshData.CreateEdge(0, 1);
            m_SpriteMeshData.CreateEdge(1, 2);
            m_SpriteMeshData.CreateEdge(2, 3);
            m_SpriteMeshData.CreateEdge(3, 0);

            m_SpriteMeshData.indices.AddRange(new int[] { 0, 1, 2, 0, 2, 3 });

            m_SpriteMeshData.bones.Add(new SpriteBoneData());
            m_SpriteMeshData.bones.Add(new SpriteBoneData());
            m_SpriteMeshData.bones.Add(new SpriteBoneData());
            m_SpriteMeshData.bones.Add(new SpriteBoneData());

            m_MousePosition = new Vector2(0.25f, 0.75f);

            m_View.DoCreateVertex().Returns(true);

            m_SpriteMeshController.OnGUI();

            Assert.AreEqual(5, m_SpriteMeshData.vertices.Count, "Incorrect number of vertices");

            var result = m_SpriteMeshData.vertices[4].editableBoneWeight.ToBoneWeight(false);

            Assert.IsTrue(ContainsChannel(result, 3, 0.5f), "Does not contain expected weights");
            Assert.IsTrue(ContainsChannel(result, 2, 0.25f), "Does not contain expected weights");
            Assert.IsTrue(ContainsChannel(result, 0, 0.25f), "Does not contain expected weights");
            Assert.IsTrue(ContainsChannel(result, 0, 0.0f), "Does not contain expected weights");
        }
 private void CreateTwoVerticesAndEdge(Vector2 v1, Vector2 v2)
 {
     m_SpriteMeshData.CreateVertex(v1);
     m_SpriteMeshData.CreateVertex(v2);
     m_SpriteMeshData.CreateEdge(m_SpriteMeshData.vertices.Count - 2, m_SpriteMeshData.vertices.Count - 1);
 }