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 LerpBoneWeight_AllIndicesDifferent() { BoneWeight first = new BoneWeight(); first.boneIndex0 = 0; first.boneIndex1 = 1; first.boneIndex2 = 2; first.boneIndex3 = 3; first.weight0 = 0.1f; first.weight1 = 0.2f; first.weight2 = 0.3f; first.weight3 = 0.4f; BoneWeight second = new BoneWeight(); second.boneIndex0 = 4; second.boneIndex1 = 5; second.boneIndex2 = 6; second.boneIndex3 = 7; second.weight0 = 0.4f; second.weight1 = 0.3f; second.weight2 = 0.2f; second.weight3 = 0.1f; BoneWeight result = EditableBoneWeightUtility.Lerp(first, second, 0f); Assert.IsTrue(ContainsChannel(result, 3, 0.4f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.3f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 1, 0.2f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 0, 0.1f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 0.2f); Assert.IsTrue(ContainsChannel(result, 3, 0.319999993f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.24000001f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 1, 0.159999996f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 4, 0.0800000057f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 0.5f); Assert.IsTrue(ContainsChannel(result, 4, 0.200000003f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 3, 0.200000003f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.150000006f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 5, 0.150000006f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 0.8f); Assert.IsTrue(ContainsChannel(result, 4, 0.320000023f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 5, 0.24000001f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 6, 0.160000011f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 7, 0.0800000057f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 1f); Assert.IsTrue(ContainsChannel(result, 4, 0.4f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 5, 0.3f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 6, 0.2f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 7, 0.1f), "Does not contain expected weights"); }
public void LerpBoneWeight_SomeIndicesInCommon() { BoneWeight first = new BoneWeight(); first.boneIndex0 = 0; first.boneIndex1 = 1; first.boneIndex2 = 2; first.boneIndex3 = 3; first.weight0 = 0.1f; first.weight1 = 0.2f; first.weight2 = 0.3f; first.weight3 = 0.4f; BoneWeight second = new BoneWeight(); second.boneIndex0 = 0; second.boneIndex1 = 4; second.boneIndex2 = 2; second.boneIndex3 = 5; second.weight0 = 0.4f; second.weight1 = 0.3f; second.weight2 = 0.2f; second.weight3 = 0.1f; BoneWeight result = EditableBoneWeightUtility.Lerp(first, second, 0f); Assert.IsTrue(ContainsChannel(result, 3, 0.4f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.3f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 1, 0.2f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 0, 0.1f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 0.2f); Assert.IsTrue(ContainsChannel(result, 3, 0.319999993f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.279999971f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 1, 0.159999996f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 0, 0.159999996f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 0.5f); Assert.IsTrue(ContainsChannel(result, 0, 0.25000003f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.249999985f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 3, 0.200000003f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 4, 0.150000006f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 0.8f); Assert.IsTrue(ContainsChannel(result, 0, 0.340000033f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 4, 0.239999995f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.219999999f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 5, 0.0799999982f), "Does not contain expected weights"); result = EditableBoneWeightUtility.Lerp(first, second, 1f); Assert.IsTrue(ContainsChannel(result, 0, 0.4f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 4, 0.3f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 2, 0.2f), "Does not contain expected weights"); Assert.IsTrue(ContainsChannel(result, 5, 0.1f), "Does not contain expected weights"); }
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."); }
public void LerpBoneWeight_AllIndicesDifferent() { var first = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 1, boneIndex2 = 2, boneIndex3 = 3, weight0 = 0.1f, weight1 = 0.2f, weight2 = 0.3f, weight3 = 0.4f }; var second = new BoneWeight() { boneIndex0 = 4, boneIndex1 = 5, boneIndex2 = 6, boneIndex3 = 7, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; var result = EditableBoneWeightUtility.Lerp(first, second, 0f); var expected = new BoneWeight() { boneIndex0 = 3, boneIndex1 = 2, boneIndex2 = 1, boneIndex3 = 0, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.2f); expected = new BoneWeight() { boneIndex0 = 3, boneIndex1 = 2, boneIndex2 = 1, boneIndex3 = 4, weight0 = 0.319999993f, weight1 = 0.24000001f, weight2 = 0.159999996f, weight3 = 0.0800000057f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.5f); expected = new BoneWeight() { boneIndex0 = 4, boneIndex1 = 3, boneIndex2 = 2, boneIndex3 = 5, weight0 = 0.200000003f, weight1 = 0.200000003f, weight2 = 0.150000006f, weight3 = 0.150000006f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.8f); expected = new BoneWeight() { boneIndex0 = 4, boneIndex1 = 5, boneIndex2 = 6, boneIndex3 = 7, weight0 = 0.320000023f, weight1 = 0.24000001f, weight2 = 0.160000011f, weight3 = 0.0800000057f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 1f); expected = new BoneWeight() { boneIndex0 = 4, boneIndex1 = 5, boneIndex2 = 6, boneIndex3 = 7, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; AssertBoneWeightContainsChannels(expected, result); }
public void LerpBoneWeight_SomeIndicesInCommon() { var first = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 1, boneIndex2 = 2, boneIndex3 = 3, weight0 = 0.1f, weight1 = 0.2f, weight2 = 0.3f, weight3 = 0.4f }; var second = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 4, boneIndex2 = 2, boneIndex3 = 5, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; var result = EditableBoneWeightUtility.Lerp(first, second, 0f); var expected = new BoneWeight() { boneIndex0 = 3, boneIndex1 = 2, boneIndex2 = 1, boneIndex3 = 0, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.2f); expected = new BoneWeight() { boneIndex0 = 3, boneIndex1 = 2, boneIndex2 = 1, boneIndex3 = 0, weight0 = 0.320000023f, weight1 = 0.280000001f, weight2 = 0.160000011f, weight3 = 0.160000011f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.5f); expected = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 2, boneIndex2 = 3, boneIndex3 = 4, weight0 = 0.25000003f, weight1 = 0.249999985f, weight2 = 0.200000003f, weight3 = 0.150000006f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.8f); expected = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 4, boneIndex2 = 2, boneIndex3 = 5, weight0 = 0.340000033f, weight1 = 0.239999995f, weight2 = 0.219999999f, weight3 = 0.0799999982f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 1f); Assert.AreEqual(0, result.boneIndex0, "Incorrect boneIndex"); Assert.AreEqual(4, result.boneIndex1, "Incorrect boneIndex"); Assert.AreEqual(2, result.boneIndex2, "Incorrect boneIndex"); Assert.AreEqual(5, result.boneIndex3, "Incorrect boneIndex"); Assert.AreEqual(0.4f, result.weight0, "Incorrect boneWeight"); Assert.AreEqual(0.3f, result.weight1, "Incorrect boneWeight"); Assert.AreEqual(0.2f, result.weight2, "Incorrect boneWeight"); Assert.AreEqual(0.1f, result.weight3, "Incorrect boneWeight"); expected = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 4, boneIndex2 = 2, boneIndex3 = 5, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; AssertBoneWeightContainsChannels(expected, result); }
public void LerpBoneWeight_AllIndicesInCommon() { var first = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 1, boneIndex2 = 2, boneIndex3 = 3, weight0 = 0.1f, weight1 = 0.2f, weight2 = 0.3f, weight3 = 0.4f }; var second = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 1, boneIndex2 = 2, boneIndex3 = 3, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; var result = EditableBoneWeightUtility.Lerp(first, second, 0f); var expected = new BoneWeight() { boneIndex0 = 3, boneIndex1 = 2, boneIndex2 = 1, boneIndex3 = 0, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.2f); expected = new BoneWeight() { boneIndex0 = 3, boneIndex1 = 2, boneIndex2 = 1, boneIndex3 = 0, weight0 = 0.340000033f, weight1 = 0.279999942f, weight2 = 0.219999984f, weight3 = 0.159999982f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.5f); expected = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 2, boneIndex2 = 3, boneIndex3 = 1, weight0 = 0.25000003f, weight1 = 0.25f, weight2 = 0.25f, weight3 = 0.249999985f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 0.8f); expected = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 1, boneIndex2 = 2, boneIndex3 = 3, weight0 = 0.340000033f, weight1 = 0.279999971f, weight2 = 0.220000014f, weight3 = 0.159999996f }; AssertBoneWeightContainsChannels(expected, result); result = EditableBoneWeightUtility.Lerp(first, second, 1f); expected = new BoneWeight() { boneIndex0 = 0, boneIndex1 = 1, boneIndex2 = 2, boneIndex3 = 3, weight0 = 0.4f, weight1 = 0.3f, weight2 = 0.2f, weight3 = 0.1f }; AssertBoneWeightContainsChannels(expected, result); }
public void ToBoneWeight_WithNoChannels_CreatesDefaultBoneWeight() { BoneWeight boneWeight = EditableBoneWeightUtility.ToBoneWeight(new EditableBoneWeight(), false); Assert.AreEqual(new BoneWeight(), boneWeight, "Empty EditableBoneWeight should generate a default BoneWeight"); }