public static void AddBoneData(ref VertexBoneData vbd, int boneId, float weight) { for (int i = 0; i < NumBonesPerVertex; i++) { if (vbd.Weights[i] == 0.0f) { vbd.Ids[i] = boneId; vbd.Weights[i] = weight; return; } } }
void LoadBones(int meshIndex, Mesh mesh, ref List <VertexBoneData> bones) { for (int i = 0; i < mesh.BoneCount; i++) { var boneIndex = 0; var boneName = mesh.Bones[i].Name; if (!BoneMapping.ContainsKey(boneName)) { boneIndex = NumBones; NumBones++; BoneInfo bi = new BoneInfo(); BoneInfo.Add(bi); var biToChange = BoneInfo[boneIndex]; biToChange.BoneOffset = mesh.Bones[i].OffsetMatrix.ToOtk(); BoneInfo[boneIndex] = biToChange; BoneMapping[boneName] = boneIndex; } else { boneIndex = BoneMapping[boneName]; } for (int j = 0; j < mesh.Bones[i].VertexWeightCount; j++) { int vertexId = Entries[meshIndex].BaseVertex + mesh.Bones[i].VertexWeights[j].VertexID; float weight = mesh.Bones[i].VertexWeights[j].Weight; var bone = bones[vertexId]; VertexBoneData.AddBoneData(ref bone, boneIndex, weight); bones[vertexId] = bone; } } }