【发布时间】:2022-06-15 01:33:58
【问题描述】:
我已经下载了 GLTF 示例 Fox https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Fox 并试图让动画通过 SharpGLTF 工作。
到目前为止,在联合 worldTransform * inverseBindMatrix 中传递时看起来很好
这是计算骨骼变换的代码。我希望任何人都知道可能出了什么问题,我一直在努力让它工作 3 天,但不知道该去哪里找了。
private void UpdateBone (Node node, Matrix4x4 parentTransformation) {
Skin skin = skeleton.skin;
(Node joint, System.Numerics.Matrix4x4 inverseBindMatrix) = skin.GetJoint(0);
for (var i = 0; i < skin.JointsCount; i++) {
(joint, inverseBindMatrix) = skin.GetJoint(i);
if (joint.Name == node.Name) break;
}
Matrix4x4 scale = Matrix4x4.Identity;
Matrix4x4 rotation = Matrix4x4.Identity;
Matrix4x4 translation = Matrix4x4.Identity;
IEnumerable<AnimationChannel> jointChannels = currentAnimation.logicalAnimation.FindChannels(joint);
foreach (var jointChannel in jointChannels) {
if (jointChannel.GetTranslationSampler() is { } translationSampler) {
translation = Matrix4x4.Translation(Vector3.FromSystemVector(translationSampler.GetLinearKeys().First().Value));
}
if (jointChannel.GetRotationSampler() is { } rotationSampler) {
rotation = Matrix4x4.RotationQuaternion((Quaternion) rotationSampler.GetLinearKeys().First().Value);
}
if (jointChannel.GetScaleSampler() is { } scaleSampler) {
scale = Matrix4x4.Scaling(Vector3.FromSystemVector(scaleSampler.GetLinearKeys().First().Value));
}
}
Matrix4x4 localTransformation = translation * rotation * scale;
Matrix4x4 globalTransformation = parentTransformation * localTransformation;
skeletonState.BoneTransformations[node.LogicalIndex] = Matrix4x4.Identity;
foreach (var child in node.VisualChildren) {
if (child is null || !child.IsSkinJoint) continue;
UpdateBone(child, globalTransformation);
}
}
【问题讨论】: