1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Make animation blending and bone overrides interact favorably

This commit is contained in:
Lars Mueller 2025-01-27 18:55:27 +01:00
parent 455f7a4cae
commit 307ab111d0
2 changed files with 16 additions and 9 deletions

View file

@ -181,6 +181,10 @@ void CAnimatedMeshSceneNode::OnAnimate(u32 timeMs)
// anything is rendered so that the transformations of children are up to date
animateJoints();
// Copy old transforms *before* bone overrides have been applied.
// TODO if there are no bone overrides or no animation blending, this is unnecessary.
copyOldTransforms();
OnAnimateCallback(timeMs / 1000.0f);
IAnimatedMeshSceneNode::OnAnimate(timeMs);
@ -610,21 +614,23 @@ void CAnimatedMeshSceneNode::checkJoints()
}
}
void CAnimatedMeshSceneNode::copyOldTransforms()
{
for (u32 i = 0; i < PerJoint.SceneNodes.size(); ++i) {
if (!PerJoint.SceneNodes[i]->Matrix) {
PerJoint.PreTransSaves[i] = PerJoint.SceneNodes[i]->getTransform();
} else {
PerJoint.PreTransSaves[i] = std::nullopt;
}
}
}
void CAnimatedMeshSceneNode::beginTransition()
{
if (!JointsUsed)
return;
if (TransitionTime != 0) {
// Copy the transforms of animated joints
for (u32 i = 0; i < PerJoint.SceneNodes.size(); ++i) {
if (!PerJoint.SceneNodes[i]->Matrix) {
PerJoint.PreTransSaves[i] = PerJoint.SceneNodes[i]->getTransform();
} else {
PerJoint.PreTransSaves[i] = std::nullopt;
}
}
Transiting = core::reciprocal((f32)TransitionTime);
}
TransitingBlend = 0.f;

View file

@ -148,6 +148,7 @@ private:
void buildFrameNr(u32 timeMs);
void checkJoints();
void copyOldTransforms();
void beginTransition();
core::array<video::SMaterial> Materials;