more misc animation fixes

This commit is contained in:
Ricardo Luís Vaz Silva 2025-02-04 17:36:01 -03:00
parent ec42c77289
commit eb7c99b34a
2 changed files with 43 additions and 34 deletions

View file

@ -5160,9 +5160,34 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s
tic += ticFrac;
}
FModel * mdl = Models[(self->modelData->models.Size() > 0 && self->modelData->models[0].modelID >= 0) ? self->modelData->models[0].modelID : BaseSpriteModelFrames[self->GetClass()].modelIDs[0]];
int animID = -1;
if(self->modelData->animationIDs.Size() > 0 && self->modelData->animationIDs[0] >= 0)
{
animID = self->modelData->animationIDs[0];
}
else
{
animID = BaseSpriteModelFrames[self->GetClass()].animationIDs[0];
}
FModel * animation = nullptr;
if (animID >= 0 && animID < Models.Size())
{
animation = Models[animID];
}
else if(self->modelData->models.Size() && self->modelData->models[0].modelID >= 0 && self->modelData->models[0].modelID < Models.Size())
{
animation = Models[self->modelData->models[0].modelID];
}
else
{
animation = Models[BaseSpriteModelFrames[self->GetClass()].modelIDs[0]];
}
int animStart = animation->FindFirstFrame(animName);
int animStart = mdl->FindFirstFrame(animName);
if(animStart == FErr_NotFound)
{
self->modelData->curAnim.flags = MODELANIM_NONE;
@ -5187,28 +5212,7 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s
calcFrames(self->modelData->curAnim, tic, to, inter);
const TArray<TRS>* animationData = nullptr;
int animationid = -1;
const FSpriteModelFrame * smf = &BaseSpriteModelFrames[self->GetClass()];
if (self->modelData->animationIDs.Size() > 0 && self->modelData->animationIDs[0] >= 0)
{
animationid = self->modelData->animationIDs[0];
}
else if(smf->modelsAmount > 0)
{
animationid = smf->animationIDs[0];
}
FModel* animation = mdl;
if (animationid >= 0)
{
animation = Models[animationid];
animationData = animation->AttachAnimationData();
}
const TArray<TRS>* animationData = animation->AttachAnimationData();
self->modelData->prevAnim = animation->PrecalculateFrame(self->modelData->prevAnim, to, inter, animationData);
}
@ -5225,11 +5229,11 @@ void SetAnimationInternal(AActor * self, FName animName, double framerate, int s
self->modelData->prevAnim = nullptr;
}
int animEnd = mdl->FindLastFrame(animName);
int animEnd = animation->FindLastFrame(animName);
if(framerate < 0)
{
framerate = mdl->FindFramerate(animName);
framerate = animation->FindFramerate(animName);
}
int len = animEnd - animStart;
@ -5475,6 +5479,12 @@ void ChangeModelNative(
if(generatorindex != -1) mobj->modelData->modelFrameGenerators[modelindex] = generatorindex;
}
if(!(mobj->modelData->curAnim.flags & MODELANIM_NONE) && animationindex == 0 && (mobj->modelData->animationIDs.Size() == 0 || mobj->modelData->animationIDs[0] != queryAnimation))
{ // reset current animation if animation file changes
mobj->modelData->curAnim.flags |= MODELANIM_NONE;
mobj->modelData->prevAnim = nullptr;
}
if(mobj->modelData->animationIDs.Size() == animationindex)
{
mobj->modelData->animationIDs.Push(queryAnimation);

View file

@ -147,7 +147,7 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod
// so we make the "undistorted" behavior opt-in
if (smf_flags & MDL_CORRECTPIXELSTRETCH)
{
stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch;
stretch = (smf->modelIDs[0] >= 0 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch;
objectToWorldMatrix.scale(1, stretch, 1);
}
@ -188,7 +188,7 @@ void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteMod
if (!(smf_flags & MDL_CORRECTPIXELSTRETCH))
{
stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch;
stretch = (smf->modelIDs[0] >= 0 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch;
objectToWorldMatrix.scale(1, stretch, 1);
}
@ -396,7 +396,6 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
TArray<FTextureID> surfaceskinids;
const TArray<VSMatrix> *boneData;
int boneStartingPosition = -1;
bool evaluatedSingle = false;
@ -522,9 +521,11 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
bool nextFrame = smfNext && modelframe != modelframenext;
// [RL0] while per-model animations aren't done, DECOUPLEDANIMATIONS does the same as MODELSAREATTACHMENTS
if(!evaluatedSingle)
{
const TArray<VSMatrix> *boneData = nullptr;
FModel* animation = mdl;
const TArray<TRS>* animationData = nullptr;
@ -536,7 +537,7 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
if(is_decoupled)
{
if(decoupled_frame.frame1 != -1)
if(decoupled_frame.frame1 >= 0)
{
boneData = animation->CalculateBones(actor->modelData->prevAnim, decoupled_frame, inter, animationData);
}
@ -551,8 +552,6 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr
boneStartingPosition = boneData ? screen->mBones->UploadBones(*boneData) : -1;
evaluatedSingle = true;
}
boneData = nullptr;
}
mdl->RenderFrame(renderer, tex, modelframe, nextFrame ? modelframenext : modelframe, nextFrame ? inter : -1.f, translation, ssidp, boneStartingPosition);
@ -986,10 +985,10 @@ void ParseModelDefLump(int Lump)
if (isframe)
{
sc.MustGetString();
if (smf.modelIDs[index] != -1)
if (smf.modelIDs[index] >= 0)
{
FModel *model = Models[smf.modelIDs[index]];
if (smf.animationIDs[index] != -1)
if (smf.animationIDs[index] >= 0)
{
model = Models[smf.animationIDs[index]];
}