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 RemoveBone_DisablesChannelsWithSameBoneIndex_DecrementsIndicesHigherThanBoneIndex_NormalizeBoneWeight() { EditableBoneWeight editableBoneWeight = new EditableBoneWeight(); editableBoneWeight.AddChannel(new BoneWeightData(0, 0.4f), true); editableBoneWeight.AddChannel(new BoneWeightData(1, 0.3f), true); editableBoneWeight.AddChannel(new BoneWeightData(2, 0.2f), true); editableBoneWeight.AddChannel(new BoneWeightData(3, 0.1f), true); editableBoneWeight.RemoveBone(1); 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.False(editableBoneWeight.IsChannelEnabled(3), "Channel should be disabled"); Assert.AreEqual(0, editableBoneWeight.GetBoneWeightData(0).boneIndex, "Incorrect boneIndex"); Assert.AreEqual(1, editableBoneWeight.GetBoneWeightData(1).boneIndex, "Incorrect boneIndex"); Assert.AreEqual(2, editableBoneWeight.GetBoneWeightData(2).boneIndex, "Incorrect boneIndex"); Assert.AreEqual(0, editableBoneWeight.GetBoneWeightData(3).boneIndex, "Incorrect boneIndex"); Assert.AreEqual(0.571428537f, editableBoneWeight.GetBoneWeightData(0).weight, "Incorrect boneWeight"); Assert.AreEqual(0.285714269f, editableBoneWeight.GetBoneWeightData(1).weight, "Incorrect boneWeight"); Assert.AreEqual(0.142857134f, editableBoneWeight.GetBoneWeightData(2).weight, "Incorrect boneWeight"); Assert.AreEqual(0f, editableBoneWeight.GetBoneWeightData(3).weight, "Incorrect boneWeight"); Assert.AreEqual(0.99999994f, editableBoneWeight.GetBoneWeightData(0).weight + editableBoneWeight.GetBoneWeightData(1).weight + editableBoneWeight.GetBoneWeightData(2).weight + editableBoneWeight.GetBoneWeightData(3).weight, "BoneWeight is not normalized"); }
public void IsChannelEnabled_WithInvalidChannelIndex_TrowsException() { EditableBoneWeight e = new EditableBoneWeight(); e.AddChannel(new BoneWeightData(), true); Assert.Throws <IndexOutOfRangeException>(() => e.IsChannelEnabled(-1)); Assert.Throws <IndexOutOfRangeException>(() => e.IsChannelEnabled(1)); }
public void SetBoneWeightData_DisablesChannelsWithZeroWeight() { EditableBoneWeight e = new EditableBoneWeight(); e.SetFromBoneWeight(new BoneWeight()); Assert.IsFalse(e.IsChannelEnabled(0), "Channel should be disabled"); Assert.IsFalse(e.IsChannelEnabled(1), "Channel should be disabled"); Assert.IsFalse(e.IsChannelEnabled(2), "Channel should be disabled"); Assert.IsFalse(e.IsChannelEnabled(3), "Channel should be disabled"); }
public void FilterChannels_DisablesChannelsWithWeightBelowTolerance() { EditableBoneWeight editableBoneWeight = new EditableBoneWeight(); editableBoneWeight.AddChannel(new BoneWeightData(0, 0.2f), true); editableBoneWeight.AddChannel(new BoneWeightData(1, 0.2f), true); editableBoneWeight.AddChannel(new BoneWeightData(2, 0.3f), true); editableBoneWeight.AddChannel(new BoneWeightData(3, 0.3f), true); editableBoneWeight.FilterChannels(0.25f); Assert.False(editableBoneWeight.IsChannelEnabled(0), "Channel should be disabled"); Assert.False(editableBoneWeight.IsChannelEnabled(1), "Channel should be disabled"); Assert.True(editableBoneWeight.IsChannelEnabled(2), "Channel should be enabled"); Assert.True(editableBoneWeight.IsChannelEnabled(3), "Channel should be enabled"); Assert.AreEqual(0f, editableBoneWeight.GetBoneWeightData(0).weight, "Incorrect boneWeight"); Assert.AreEqual(0f, editableBoneWeight.GetBoneWeightData(1).weight, "Incorrect boneWeight"); Assert.AreEqual(0.3f, editableBoneWeight.GetBoneWeightData(2).weight, "Incorrect boneWeight"); Assert.AreEqual(0.3f, editableBoneWeight.GetBoneWeightData(3).weight, "Incorrect boneWeight"); }
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 UnifyChannelsWithSameBoneIndex_AddsWeightsInSameChannel_DisablesRepeatedChannels() { EditableBoneWeight editableBoneWeight = new EditableBoneWeight(); editableBoneWeight.AddChannel(new BoneWeightData(0, 0.1f), true); editableBoneWeight.AddChannel(new BoneWeightData(1, 0.2f), true); editableBoneWeight.AddChannel(new BoneWeightData(0, 0.3f), true); editableBoneWeight.AddChannel(new BoneWeightData(3, 0.4f), true); editableBoneWeight.UnifyChannelsWithSameBoneIndex(); Assert.AreEqual(0.4f, editableBoneWeight.GetBoneWeightData(0).weight, "Incorrect boneWeight"); Assert.AreEqual(0.2f, editableBoneWeight.GetBoneWeightData(1).weight, "Incorrect boneWeight"); Assert.AreEqual(0f, editableBoneWeight.GetBoneWeightData(2).weight, "Incorrect boneWeight"); Assert.False(editableBoneWeight.IsChannelEnabled(2), "Channel should be disabled"); Assert.AreEqual(0.4f, editableBoneWeight.GetBoneWeightData(3).weight, "Incorrect boneWeight"); }