private static void Lerp(EditableBoneWeight first, EditableBoneWeight second, ref EditableBoneWeight result, float t) { result.Clear(); foreach (BoneWeightChannel channel in first) { if (!channel.enabled) { continue; } var weight = channel.weight * (1f - t); if (weight > 0f) { result.AddChannel(channel.boneIndex, weight, true); } } foreach (BoneWeightChannel channel in second) { if (!channel.enabled) { continue; } var weight = channel.weight * t; if (weight > 0f) { result.AddChannel(channel.boneIndex, weight, true); } } result.UnifyChannelsWithSameBoneIndex(); result.Clamp(4); if (result.Sum() > 1f) { result.Normalize(); } result.FilterChannels(0f); }
public static void Normalize(this EditableBoneWeight editableBoneWeight) { ValidateChannels(editableBoneWeight); var sum = editableBoneWeight.Sum(); if (sum == 0f || sum == 1f) { return; } var sumInv = 1f / sum; for (var i = 0; i < editableBoneWeight.Count; ++i) { if (editableBoneWeight[i].enabled) { editableBoneWeight[i].weight *= sumInv; } } }