From 19f8cc783e960e10db84e184fde71a9549bdaadd Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Sat, 4 May 2019 16:47:06 -0700 Subject: [PATCH] Ignore animation 'takes', calculate frame intervals ourselves. Lifted from comment in source: Individual animations are often concatenated on the timeline, and the only certain way to identify precisely what interval they occupy is to depth-traverse the entire animation stack, and examine the actual keys. There is a deprecated concept of an "animation take" which is meant to provide precisely this time interval information, but the data is not actually derived by the SDK from source-of-truth data structures, but rather provided directly by the FBX exporter, and not sanity checked. Some exporters calculate it correctly. Others do not. In any case, we now ignore it completely. --- src/fbx/Fbx2Raw.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/fbx/Fbx2Raw.cpp b/src/fbx/Fbx2Raw.cpp index e1a10fe..ab64d4b 100644 --- a/src/fbx/Fbx2Raw.cpp +++ b/src/fbx/Fbx2Raw.cpp @@ -742,24 +742,35 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o pScene->SetCurrentAnimationStack(pAnimStack); - FbxTakeInfo* takeInfo = pScene->GetTakeInfo(animStackName); - if (takeInfo == nullptr) { - fmt::printf("Warning:: animation '%s' has no Take information. Skipping.\n", animStackName); - // not all animstacks have a take - continue; + FbxLongLong firstFrameIndex = -1; + FbxLongLong lastFrameIndex = -1; + for (int layerIx = 0; layerIx < pAnimStack->GetMemberCount(); layerIx++) { + auto* layer = pAnimStack->GetMember(layerIx); + for (int nodeIx = 0; nodeIx < layer->GetMemberCount(); nodeIx++) { + auto* node = layer->GetMember(nodeIx); + FbxTimeSpan nodeTimeSpan; + if (node->GetAnimationInterval(nodeTimeSpan)) { + FbxLongLong firstNodeFrame = nodeTimeSpan.GetStart().GetFrameCount(eMode); + FbxLongLong lastNodeFrame = nodeTimeSpan.GetStop().GetFrameCount(eMode); + if (firstFrameIndex == -1 || firstNodeFrame < firstFrameIndex) { + firstFrameIndex = firstNodeFrame; + } + if (lastFrameIndex == -1 || lastNodeFrame < lastFrameIndex) { + lastFrameIndex = lastNodeFrame; + } + } + } } + RawAnimation animation; + animation.name = animStackName; + + fmt::printf( + "Animation %s: [%lu - %lu]\n", std::string(animStackName), firstFrameIndex, lastFrameIndex); + if (verboseOutput) { fmt::printf("animation %zu: %s (%d%%)", animIx, (const char*)animStackName, 0); } - FbxTime start = takeInfo->mLocalTimeSpan.GetStart(); - FbxTime end = takeInfo->mLocalTimeSpan.GetStop(); - - RawAnimation animation; - animation.name = animStackName; - - FbxLongLong firstFrameIndex = start.GetFrameCount(eMode); - FbxLongLong lastFrameIndex = end.GetFrameCount(eMode); for (FbxLongLong frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; frameIndex++) { FbxTime pTime; // first frame is always at t = 0.0