我正在嘗試使用 gltf 2.0 資產實作骨骼影片。
我目前能夠轉換骨架并正確渲染模型。編輯關節的變換(例如旋轉)時,模型會按預期移動。
問題是,一旦我嘗試使用影片采樣器輸出的變換,骨架就完全錯誤了。我的測驗表明,影片第一個關鍵幀的變換矩陣會匹配初始姿勢中關節的變換,但實際上它們完全不同!我不太清楚這些變換到底應該適合渲染演算法的哪個位置。
我的渲染演算法大致如下:
render_scene() {
render_node(root_node, transform::IDENTIY)
}
render_node(node, outer_transform) {
next_transform = outer_transform * node.transform
if (node.has_skin) {
update_joint_matrices(next_transform, node.joints)
}
if (node.has_mesh) {
// draw calls
}
for child in node.children {
render_node(child, next_transform)
}
}
update_joint_matrices(outer_transform, joints) {
world_transforms = []
// Parent nodes are always processed before child nodes
for joint in joints {
if joint.is_root {
world_transforms[joint] = outer_transform * joint.transform
} else {
world_transforms[joint] = world_transforms[joint.parent] * joint.transform
}
}
joint_matrices = []
for joint in 0..world_transforms.len() {
joint_matrices[joint] = world_transforms[joint] * inverse_bind_matrices[joint]
}
// send joint matrices to the GPU
}
頂點著色器的相關部分如下所示:
void main() {
mat4 modelTransform;
modelTransform =
(inWeights.x * jointMatrices[int(inJoints.x)])
(inWeights.y * jointMatrices[int(inJoints.y)])
(inWeights.z * jointMatrices[int(inJoints.z)])
(inWeights.w * jointMatrices[int(inJoints.w)]);
}
gl_Position = projection * view * modelTransform * vec4(inPos, 1.0);
}
另外,規范中有一條我不太明白的注釋:
Only the joint transforms are applied to the skinned mesh; the transform of the skinned mesh node MUST be ignored.
uj5u.com熱心網友回復:
好的,我解決了這個問題。問題是我沒有正確加載四元數。四元數應解釋為原始 XYZW 值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/453190.html
標籤:animation rust graphics gltf skinning
下一篇:D3.JS地球上的點不隨地球旋轉
