BoneWeight CreateBoneWeightFromWeights(List<float> weights)
{
BoneWeight boneWeight = new BoneWeight();
float weight = 0f;
int index = -1;
weight = weights.Max();
if(weight < 0.01f) weight = 0f;
index = weight > 0f? weights.IndexOf(weight) : -1;
boneWeight.weight0 = weight;
boneWeight.boneIndex0 = index;
if(index >= 0) weights[index] = 0f;
weight = weights.Max();
if(weight < 0.01f) weight = 0f;
index = weight > 0f? weights.IndexOf(weight) : -1;
boneWeight.weight1 = weight;
boneWeight.boneIndex1 = index;
if(index >= 0) weights[index] = 0f;
weight = weights.Max();
if(weight < 0.01f) weight = 0f;
index = weight > 0f? weights.IndexOf(weight) : -1;
boneWeight.weight2 = weight;
boneWeight.boneIndex2 = index;
if(index >= 0) weights[index] = 0f;
weight = weights.Max();
if(weight < 0.01f) weight = 0f;
index = weight > 0f? weights.IndexOf(weight) : -1;
boneWeight.weight3 = weight;
boneWeight.boneIndex3 = index;
float sum = boneWeight.weight0 +
boneWeight.weight1 +
boneWeight.weight2 +
boneWeight.weight3;
if(sum > 0f)
{
boneWeight.weight0 /= sum;
boneWeight.weight1 /= sum;
boneWeight.weight2 /= sum;
boneWeight.weight3 /= sum;
}
return boneWeight;
}