Skip to content

Commit 5b15272

Browse files
committed
Fix alien movement-attack animation blending
1 parent 2345c19 commit 5b15272

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/engine/renderer/EntityCache.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,35 @@ static void BuildSkeleton( trRefEntity_t* ent ) {
8787
}
8888
}
8989

90-
refSkeleton_t skel;
90+
refSkeleton_t skel {};
91+
92+
/* This follows the original weird and buggy code in cgame
93+
This is used to make alien attack animations blend with the movement animation
94+
Unlike human models, aliens use the same refEntity_t for all their animations (referred to as `legs` in cgame)
95+
The intent seems to have been to blend last and current movement animation, then blend them with the attack animation
96+
(the attack animation isn't blended with the one from the previous frame for whatever reason) */
97+
for ( const BoneMod& boneMod : ent->e.boneMods ) {
98+
if ( boneMod.type == BUILD_EXTRA_BLEND_SKELETON ) {
99+
if ( ent->e.animationHandle ) {
100+
RE_BuildSkeleton( &skel, boneMod.animationHandle, boneMod.startFrame, boneMod.endFrame,
101+
boneMod.lerp, ent->e.clearOrigin );
102+
RE_BlendSkeleton( &ent->skeleton, &skel, boneMod.blendLerp );
103+
}
104+
105+
break;
106+
}
107+
}
108+
91109
if ( ent->e.animationHandle2 ) {
92110
refSkeleton_t* skeleton2 = ent->e.animationHandle ? &skel : &ent->skeleton;
93111

94112
RE_BuildSkeleton( skeleton2, ent->e.animationHandle2, ent->e.startFrame2, ent->e.endFrame2,
95113
ent->e.lerp2, ent->e.clearOrigin2 );
96114

97115
for ( const BoneMod& boneMod : ent->e.boneMods ) {
98-
QuatMultiply2( skeleton2->bones[boneMod.index].t.rot, boneMod.rotation );
116+
if ( boneMod.type == BONE_ROTATE ) {
117+
QuatMultiply2( skeleton2->bones[boneMod.index].t.rot, boneMod.rotation );
118+
}
99119
}
100120

101121
if ( ent->e.animationHandle && ent->e.blendLerp > 0.0 ) {

src/engine/renderer/tr_types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ enum BoneModType {
160160
/* Builds an extra skeleton from refEntity_t::animationHandle, use animationHandle2 for the main skeleton,
161161
* Used to combine torso and legs sketons for human models since they use the same refEntity */
162162
BUILD_EXTRA_SKELETON,
163-
BONE_FROM_EXTRA_SKELETON // Use bone BoneMod::animationHandle from the extra skeleton instead of the main one
163+
BONE_FROM_EXTRA_SKELETON, // Use bone BoneMod::animationHandle from the extra skeleton instead of the main one
164+
BUILD_EXTRA_BLEND_SKELETON
164165
};
165166

166167
struct BoneMod {
@@ -173,6 +174,7 @@ struct BoneMod {
173174
int startFrame;
174175
int endFrame;
175176
float lerp;
177+
float blendLerp;
176178
};
177179

178180
struct alignas(16) refSkeleton_t

0 commit comments

Comments
 (0)