public void CreateFromBoneWeight_WithBoneIndicesDistinct_CreatesFourEnabledChannels()
        {
            var boneWeight = new BoneWeight()
            {
                boneIndex0 = 0,
                boneIndex1 = 1,
                boneIndex2 = 2,
                boneIndex3 = 3,
                weight0    = 0.1f,
                weight1    = 0.2f,
                weight2    = 0.3f,
                weight3    = 0.4f
            };
            var e = EditableBoneWeightUtility.CreateFromBoneWeight(boneWeight);

            Assert.AreEqual(4, e.Count(), "Incorrect number of channels.");
            Assert.True(e[0].enabled, "Channel should be enabled.");
            Assert.True(e[1].enabled, "Channel should be enabled.");
            Assert.True(e[2].enabled, "Channel should be enabled.");
            Assert.True(e[3].enabled, "Channel should be enabled.");
            Assert.AreEqual(0, e[0].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(1, e[1].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(2, e[2].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(3, e[3].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(0.1f, e[0].weight, "Channel has incorrect weight.");
            Assert.AreEqual(0.2f, e[1].weight, "Channel has incorrect weight.");
            Assert.AreEqual(0.3f, e[2].weight, "Channel has incorrect weight.");
            Assert.AreEqual(0.4f, e[3].weight, "Channel has incorrect weight.");
        }
        public void CreateFromBoneWeight_WithRepetedBoneIndices_CreatesFourChannels_UnifyingTheRepeatedIndices()
        {
            var boneWeight = new BoneWeight()
            {
                boneIndex0 = 0,
                boneIndex1 = 1,
                boneIndex2 = 0,
                boneIndex3 = 1,
                weight0    = 0.1f,
                weight1    = 0.2f,
                weight2    = 0.3f,
                weight3    = 0.4f
            };

            var e = EditableBoneWeightUtility.CreateFromBoneWeight(boneWeight);

            Assert.AreEqual(4, e.Count(), "Incorrect number of channels.");
            Assert.True(e[0].enabled, "Channel should be enabled.");
            Assert.True(e[1].enabled, "Channel should be enabled.");
            Assert.False(e[2].enabled, "Channel should be disabled.");
            Assert.False(e[3].enabled, "Channel should be disabled.");
            Assert.AreEqual(0, e[0].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(1, e[1].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(0, e[2].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(1, e[3].boneIndex, "Channel has incorrect boneIndex.");
            Assert.AreEqual(0.4f, e[0].weight, 0.001f, "Channel has incorrect weight.");
            Assert.AreEqual(0.6f, e[1].weight, 0.001f, "Channel has incorrect weight.");
            Assert.AreEqual(0f, e[2].weight, 0.001f, "Channel has incorrect weight.");
            Assert.AreEqual(0f, e[3].weight, 0.001f, "Channel has incorrect weight.");
        }
        public void CalculateWeightsSafe_SetWeightsOnlyToVerticesWithoutInfluences()
        {
            IWeightsGenerator generator = Substitute.For <IWeightsGenerator>();

            m_SpriteMeshDataController.CreateVertex(Vector2.zero);
            m_SpriteMeshDataController.CreateVertex(Vector2.one);

            m_SpriteMeshData.vertices[0].editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(new BoneWeight());
            m_SpriteMeshData.vertices[1].editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(new BoneWeight()
            {
                weight0 = 0.5f
            });

            BoneWeight[] weigts = new BoneWeight[]
            {
                new BoneWeight()
                {
                    weight0 = 1f
                },
                new BoneWeight()
                {
                    weight0 = 1f
                }
            };

            generator.Calculate(Arg.Any <Vector2[]>(), Arg.Any <Edge[]>(), Arg.Any <Vector2[]>(), Arg.Any <Edge[]>(), Arg.Any <int[]>()).Returns(weigts);

            m_SpriteMeshDataController.CalculateWeightsSafe(generator, null, 0f);

            BoneWeight result1 = m_SpriteMeshData.vertices[0].editableBoneWeight.ToBoneWeight(false);
            BoneWeight result2 = m_SpriteMeshData.vertices[1].editableBoneWeight.ToBoneWeight(false);

            Assert.AreEqual(1f, result1.weight0, "Incorrect bone weight");
            Assert.AreEqual(0.5f, result2.weight0, "Incorrect bone weight");
        }
        public void CreateFromBoneWeight_WithRepetedBoneIndices_CreatesFourChannels_UnifyingTheRepeatedIndices()
        {
            BoneWeight boneWeight = new BoneWeight();

            boneWeight.boneIndex0 = 0;
            boneWeight.boneIndex1 = 1;
            boneWeight.boneIndex2 = 0;
            boneWeight.boneIndex3 = 1;
            boneWeight.weight0    = 0.1f;
            boneWeight.weight1    = 0.2f;
            boneWeight.weight2    = 0.3f;
            boneWeight.weight3    = 0.4f;
            EditableBoneWeight editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(boneWeight);

            Assert.AreEqual(4, editableBoneWeight.GetChannelCount(), "Incorrect number of channels.");
            Assert.True(editableBoneWeight.IsChannelEnabled(0), "Channel should be enabled.");
            Assert.True(editableBoneWeight.IsChannelEnabled(1), "Channel should be enabled.");
            Assert.False(editableBoneWeight.IsChannelEnabled(2), "Channel should be disabled.");
            Assert.False(editableBoneWeight.IsChannelEnabled(3), "Channel should be disabled.");
            Assert.AreEqual(0, editableBoneWeight.GetBoneWeightData(0).boneIndex, "Incorrect bone index");
            Assert.AreEqual(1, editableBoneWeight.GetBoneWeightData(1).boneIndex, "Incorrect bone index");
            Assert.AreEqual(0, editableBoneWeight.GetBoneWeightData(2).boneIndex, "Incorrect bone index");
            Assert.AreEqual(1, editableBoneWeight.GetBoneWeightData(3).boneIndex, "Incorrect bone index");
            Assert.AreEqual(0.4f, editableBoneWeight.GetBoneWeightData(0).weight, 0.00001f, "Incorrect weight");
            Assert.AreEqual(0.6f, editableBoneWeight.GetBoneWeightData(1).weight, "Incorrect weight");
            Assert.AreEqual(0f, editableBoneWeight.GetBoneWeightData(2).weight, "Incorrect weight");
            Assert.AreEqual(0f, editableBoneWeight.GetBoneWeightData(3).weight, "Incorrect weight");
        }
        public void NormalizeWeights()
        {
            m_SpriteMeshDataController.CreateVertex(Vector2.zero);

            m_SpriteMeshData.vertices[0].editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(new BoneWeight()
            {
                weight0 = 0.1f
            });

            m_SpriteMeshDataController.NormalizeWeights(null);

            BoneWeight result = m_SpriteMeshData.vertices[0].editableBoneWeight.ToBoneWeight(false);

            Assert.AreEqual(1f, result.weight0, "Incorrect bone weight");
        }
        public void NormalizeWeights_WithSelection_NormalizeSelectedVertices()
        {
            m_SelectedVertices.Add(1);

            m_SpriteMeshDataController.CreateVertex(Vector2.zero);
            m_SpriteMeshDataController.CreateVertex(Vector2.zero);

            m_SpriteMeshData.vertices[0].editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(new BoneWeight()
            {
                weight0 = 0.1f
            });
            m_SpriteMeshData.vertices[1].editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(new BoneWeight()
            {
                weight0 = 0.1f
            });

            m_SpriteMeshDataController.NormalizeWeights(m_Selection);

            BoneWeight result0 = m_SpriteMeshData.vertices[0].editableBoneWeight.ToBoneWeight(false);
            BoneWeight result1 = m_SpriteMeshData.vertices[1].editableBoneWeight.ToBoneWeight(false);

            Assert.AreEqual(0.1f, result0.weight0, "Incorrect bone weight");
            Assert.AreEqual(1f, result1.weight0, "Incorrect bone weight");
        }
        public void CreateFromBoneWeight_WithBoneIndicesDistinct_CreatesFourEnabledChannels()
        {
            BoneWeight boneWeight = new BoneWeight();

            boneWeight.boneIndex0 = 0;
            boneWeight.boneIndex1 = 1;
            boneWeight.boneIndex2 = 2;
            boneWeight.boneIndex3 = 3;
            boneWeight.weight0    = 0.1f;
            boneWeight.weight1    = 0.2f;
            boneWeight.weight2    = 0.3f;
            boneWeight.weight3    = 0.4f;
            EditableBoneWeight editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(boneWeight);

            Assert.AreEqual(4, editableBoneWeight.GetChannelCount(), "Incorrect number of channels.");
            Assert.True(editableBoneWeight.IsChannelEnabled(0), "Channel should be enabled.");
            Assert.True(editableBoneWeight.IsChannelEnabled(1), "Channel should be enabled.");
            Assert.True(editableBoneWeight.IsChannelEnabled(2), "Channel should be enabled.");
            Assert.True(editableBoneWeight.IsChannelEnabled(3), "Channel should be enabled.");
            Assert.AreEqual(new BoneWeightData(0, 0.1f), editableBoneWeight.GetBoneWeightData(0), "Channel has incorrect data.");
            Assert.AreEqual(new BoneWeightData(1, 0.2f), editableBoneWeight.GetBoneWeightData(1), "Channel has incorrect data.");
            Assert.AreEqual(new BoneWeightData(2, 0.3f), editableBoneWeight.GetBoneWeightData(2), "Channel has incorrect data.");
            Assert.AreEqual(new BoneWeightData(3, 0.4f), editableBoneWeight.GetBoneWeightData(3), "Channel has incorrect data.");
        }