private void ApplyBoneMatricesInternal(SkeletonAnimRigNode node, MeshEntity entity, Matrix4x4[] boneMatrices, float timeStamp, Matrix4x4 parentTransform) { string name = node.Name; Matrix4x4 nodeTransform = node.LocalTransform; SkeletonAnimChannel animChannel = GetMeshAnimBone(name); if (animChannel != null) { nodeTransform = animChannel.GetMatrixAtTimestamp(timeStamp); } Matrix4x4 globalTransform = nodeTransform * parentTransform; MeshBone bone = BoneIndexFromEntity(entity, name); if (bone != null) { boneMatrices[bone.BoneIndex] = bone.OffsetMatrix * globalTransform; } if (node.Children == null) { return; } for (var i = 0; i < node.Children.Length; i++) { SkeletonAnimRigNode child = node.Children[i]; ApplyBoneMatricesInternal(child, entity, boneMatrices, timeStamp, globalTransform); } }
private MeshBone BoneIndexFromEntity(MeshEntity entity, string boneName) { for (var i = 0; i < entity.Meshes.Length; i++) { Mesh mesh = entity.Meshes[i]; if (mesh.Bones == null) { continue; } for (var j = 0; j < mesh.Bones.Length; j++) { MeshBone bone = mesh.Bones[j]; if (bone.Name == boneName) { return(bone); } } } return(null); }