Commit 81c7cb6
authored
[rmodels] Fix glTF skinning when joints have non-joint parent nodes (#5876)
* [rmodels] Fix glTF skinning when joints have non-joint parent nodes
Some glTF exporters (notably wow.export, but also various other DCC pipelines) place skin joints under intermediate non-joint transform nodes that carry part of the bind-pose offset. raylib's existing LoadBoneInfoGLTF and LoadModelAnimationsGLTF only inspected a joint's immediate parent and only sampled joint-local TRS, so any transform stored on an intermediate non-joint ancestor was silently dropped, producing exploded or stretched meshes at runtime.
Two surgical changes:
LoadBoneInfoGLTF: walk the parent chain past any non-joint ancestors when looking up parentIndex, instead of comparing only against node.parent. Joints whose direct parent is a non-joint were previously treated as skeleton roots.
LoadModelAnimationsGLTF: precompute a per-joint extOffset matrix that bakes in the static TRS contribution of any intermediate non-joint nodes between the joint and its nearest joint ancestor. Apply it to each frame's joint TRS before BuildPoseFromParentJoints so the per-frame world transforms match the bind-pose world transforms (LoadGLTF already used cgltf_node_transform_world for bindPose, so this aligns the two code paths).
The replaced root-only worldTransform adjustment is a strict subset of the new per-joint extOffset machinery, so it has been removed.
Spec-compliant files (the six skeletal-skinning .glb examples shipped with raylib) render bit-identically before and after; previously broken files (e.g. wow.export's babyoctopus.gltf) now match the reference rendering from f3d, the Khronos sample viewer, and three.js.
* Resolve review: NULL-check joint offset allocation, fail fast
[rmodels] Address review feedback on glTF joint offset handling
Resolve the open review points raised on PR #5876 for the per-joint
extOffset precompute in LoadModelAnimationsGLTF.
* NULL check: validate the extOffset RL_MALLOC result before use, which
was previously missing.
* Fail-fast handling: detect the allocation failure at its source and
abort animation loading (log a warning, free resources, return NULL)
instead of propagating a NULL pointer into the per-frame loop.
* Brace formatting: expand the collapsed one-line joint-match check
(if (...) { isJoint = true; break; }) into raylib's standard Allman
brace style.
* Readability: break the deeply nested MatrixMultiply(MatrixMultiply(...))
into named nodeScale/nodeRotation/nodeTranslation/nodeTransform locals,
mirroring the existing S/R/T composition later in the function.
* Spacing/line breaks: add blank lines within the precompute block to
match the surrounding code style.1 parent 186d3ce commit 81c7cb6
1 file changed
Lines changed: 71 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5375 | 5375 | | |
5376 | 5376 | | |
5377 | 5377 | | |
5378 | | - | |
| 5378 | + | |
| 5379 | + | |
| 5380 | + | |
5379 | 5381 | | |
5380 | | - | |
5381 | | - | |
| 5382 | + | |
| 5383 | + | |
5382 | 5384 | | |
5383 | | - | |
| 5385 | + | |
5384 | 5386 | | |
5385 | | - | |
5386 | | - | |
| 5387 | + | |
5387 | 5388 | | |
| 5389 | + | |
5388 | 5390 | | |
5389 | 5391 | | |
5390 | 5392 | | |
| |||
6515 | 6517 | | |
6516 | 6518 | | |
6517 | 6519 | | |
| 6520 | + | |
| 6521 | + | |
| 6522 | + | |
| 6523 | + | |
| 6524 | + | |
| 6525 | + | |
| 6526 | + | |
| 6527 | + | |
| 6528 | + | |
| 6529 | + | |
| 6530 | + | |
| 6531 | + | |
| 6532 | + | |
| 6533 | + | |
| 6534 | + | |
| 6535 | + | |
| 6536 | + | |
| 6537 | + | |
| 6538 | + | |
| 6539 | + | |
6518 | 6540 | | |
6519 | 6541 | | |
6520 | 6542 | | |
6521 | | - | |
6522 | | - | |
6523 | | - | |
6524 | | - | |
6525 | | - | |
6526 | | - | |
6527 | | - | |
6528 | | - | |
6529 | | - | |
6530 | | - | |
6531 | | - | |
| 6543 | + | |
| 6544 | + | |
| 6545 | + | |
| 6546 | + | |
| 6547 | + | |
| 6548 | + | |
| 6549 | + | |
| 6550 | + | |
| 6551 | + | |
| 6552 | + | |
| 6553 | + | |
| 6554 | + | |
| 6555 | + | |
| 6556 | + | |
| 6557 | + | |
| 6558 | + | |
| 6559 | + | |
| 6560 | + | |
| 6561 | + | |
| 6562 | + | |
| 6563 | + | |
| 6564 | + | |
| 6565 | + | |
| 6566 | + | |
| 6567 | + | |
| 6568 | + | |
| 6569 | + | |
| 6570 | + | |
| 6571 | + | |
6532 | 6572 | | |
6533 | 6573 | | |
6534 | 6574 | | |
| |||
6637 | 6677 | | |
6638 | 6678 | | |
6639 | 6679 | | |
6640 | | - | |
6641 | | - | |
6642 | | - | |
6643 | | - | |
6644 | | - | |
| 6680 | + | |
| 6681 | + | |
| 6682 | + | |
| 6683 | + | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
6645 | 6692 | | |
6646 | 6693 | | |
6647 | | - | |
6648 | | - | |
6649 | | - | |
6650 | | - | |
6651 | | - | |
6652 | | - | |
6653 | | - | |
6654 | 6694 | | |
6655 | 6695 | | |
6656 | 6696 | | |
6657 | 6697 | | |
6658 | 6698 | | |
6659 | 6699 | | |
6660 | 6700 | | |
| 6701 | + | |
| 6702 | + | |
6661 | 6703 | | |
6662 | 6704 | | |
6663 | 6705 | | |
| |||
0 commit comments