Skip to content

Commit 8fe2fd2

Browse files
committed
fix: don't cycle matrix for anim of nothing changes
1 parent 9356c0f commit 8fe2fd2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/t3d/t3dskeleton.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ void t3d_skeleton_update(T3DSkeleton *skeleton)
6363
int updateLevel = -1;
6464
bool forceUpdate = false;
6565

66-
skeleton->currentBufferIdx = (skeleton->currentBufferIdx + 1) % skeleton->bufferCount;
67-
T3DMat4FP* matStackFP = &skeleton->boneMatricesFP[skeleton->skeletonRef->boneCount * skeleton->currentBufferIdx];
66+
T3DMat4FP* matStackFP = nullptr;
6867

6968
for(int i = 0; i < skeleton->skeletonRef->boneCount; i++)
7069
{
@@ -78,6 +77,14 @@ void t3d_skeleton_update(T3DSkeleton *skeleton)
7877

7978
if(bone->hasChanged || forceUpdate)
8079
{
80+
// only cycle through matrices if at least one bone changes.
81+
// this avoids flickering at the end of an animation, since it would cycle through the last X frames otherwise.
82+
if(matStackFP == nullptr)
83+
{
84+
skeleton->currentBufferIdx = (skeleton->currentBufferIdx + 1) % skeleton->bufferCount;
85+
matStackFP = &skeleton->boneMatricesFP[skeleton->skeletonRef->boneCount * skeleton->currentBufferIdx];
86+
}
87+
8188
// if a bone changed we need to also update any children.
8289
// To do so, update all following bones until we hit one that has the same depth as the changed bone.
8390
if(!forceUpdate)updateLevel = boneDef->depth;

0 commit comments

Comments
 (0)