Add picking the longest animation from the imported file instead of the first one as default

#2490
This commit is contained in:
Wojtek Figat
2024-08-29 09:53:22 +02:00
parent ec412d9be0
commit e925af534e
2 changed files with 14 additions and 2 deletions

View File

@@ -638,7 +638,17 @@ CreateAssetResult ImportModel::CreateAnimation(CreateAssetContext& context, Mode
// Save animation data
MemoryWriteStream stream(8182);
const int32 animIndex = options && options->ObjectIndex != -1 ? options->ObjectIndex : 0; // Single animation per asset
int32 animIndex = options ? options->ObjectIndex : -1; // Single animation per asset
if (animIndex == -1)
{
// Pick the longest animation by default (eg. to skip ref pose anim if exported as the first one)
animIndex = 0;
for (int32 i = 1; i < modelData.Animations.Count(); i++)
{
if (modelData.Animations[i].GetLength() > modelData.Animations[animIndex].GetLength())
animIndex = i;
}
}
if (modelData.Pack2AnimationHeader(&stream, animIndex))
return CreateAssetResult::Error;
if (context.AllocateChunk(0))

View File

@@ -1053,14 +1053,16 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
}
if (EnumHasAnyFlags(options.ImportTypes, ImportDataTypes::Animations))
{
int32 index = 0;
for (auto& animation : data.Animations)
{
LOG(Info, "Imported animation '{}' has {} channels, duration: {} frames, frames per second: {}", animation.Name, animation.Channels.Count(), animation.Duration, animation.FramesPerSecond);
LOG(Info, "Imported animation '{}' at index {} has {} channels, duration: {} frames ({} seconds), frames per second: {}", animation.Name, index, animation.Channels.Count(), animation.Duration, animation.GetLength(), animation.FramesPerSecond);
if (animation.Duration <= ZeroTolerance || animation.FramesPerSecond <= ZeroTolerance)
{
errorMsg = TEXT("Invalid animation duration.");
return true;
}
index++;
}
}
switch (options.Type)