From e796144a4d4ef3a788999f5cb0424b23c7f207a8 Mon Sep 17 00:00:00 2001 From: Radai Date: Mon, 2 Dec 2024 17:33:53 +0100 Subject: [PATCH] bug fix with fps --- .../FBXTranslator/FBXTranslator.cpp | 18 ++++++++---------- .../FBXTranslator/FBXTranslator.h | 4 ++-- .../XMDTranslator/XMDTranslator.cpp | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.cpp b/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.cpp index 3ed6434d..18940b0a 100644 --- a/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.cpp +++ b/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.cpp @@ -409,7 +409,7 @@ std::vector FBXTranslator::createFbxMorphemeSkeleton(FbxScene* pScene, } //Creates FBX animation take from an NSA file input, adding the FLVER rig -bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name, std::vector morphemeToFlverBoneMap) +bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name, std::vector morphemeToFlverBoneMap, int fps) { MR::AnimationSourceHandle* animHandle = pAnim->getHandle(); @@ -434,16 +434,15 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele FbxTime start; start.SetSecondDouble(0.0); - float animSampleRate = 30.f; float animDuration = animSourceNSA->getDuration(animSourceNSA); FbxTime end; - end.SetFrame(RMath::timeToFrame(animDuration, 30)); + end.SetFrame(RMath::timeToFrame(animDuration, fps)); FbxTimeSpan timeSpan = FbxTimeSpan(start, end); pAnimStack->SetLocalTimeSpan(timeSpan); - const int keyframeCount = animSampleRate * animDuration; + const int keyframeCount = fps * animDuration; const int boneCount = animHandle->getChannelCount(); const int trajectoryBoneIndex = animHandle->getRig()->getTrajectoryBoneIndex(); @@ -478,7 +477,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele { int keyIndex; - float animTime = GetTimeByAnimFrame(animDuration, animSampleRate, frame); + float animTime = GetTimeByAnimFrame(animDuration, fps, frame); FbxAMatrix transform = ConvertToFbxAMatrix(pAnim->getTransformAtTime(animTime, boneIndex)); @@ -537,7 +536,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele } //Creates an FBXTake from the NSA file input, adding the morpheme rig -bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name) +bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name, int fps) { MR::AnimationSourceHandle* animHandle = pAnim->getHandle(); @@ -562,7 +561,6 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele FbxTime start; start.SetSecondDouble(0.0); - float animSampleRate = 60; float animDuration = animSourceNSA->getDuration(animSourceNSA); FbxTime end; @@ -571,7 +569,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele FbxTimeSpan timeSpan = FbxTimeSpan(start, end); pAnimStack->SetLocalTimeSpan(timeSpan); - int keyframeCount = animSampleRate * animDuration; + int keyframeCount = fps * animDuration; int boneCount = animHandle->getChannelCount(); const int trajectoryBoneIndex = animHandle->getRig()->getTrajectoryBoneIndex(); @@ -601,7 +599,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele { int keyIndex; - float animTime = GetTimeByAnimFrame(animDuration, animSampleRate, frame); + float animTime = GetTimeByAnimFrame(animDuration, fps, frame); FbxAMatrix transform = ConvertToFbxAMatrix(pAnim->getTransformAtTime(animTime, boneIndex)); if (boneIndex == rootBoneIndex) @@ -611,7 +609,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector pSkele } FbxTime keyTime; - keyTime.SetFrame(RMath::timeToFrame(animTime, 30)); + keyTime.SetFrame(RMath::timeToFrame(animTime, fps)); FbxVector4 translation = transform.GetT(); diff --git a/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.h b/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.h index b9943e67..4cca4575 100644 --- a/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.h +++ b/DS2AnimToolset/morphemeEditor/FileTranslator/FBXTranslator/FBXTranslator.h @@ -12,8 +12,8 @@ namespace FBXTranslator std::vector createFbxFlverSkeleton(FbxScene* pScene, FlverModel* pModel, FbxPose* pBindPoses); std::vector createFbxMorphemeSkeleton(FbxScene* pScene, MR::AnimRigDef* pRig, FbxPose* pBindPoses); - bool createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name, std::vector morphemeToFlverBoneMap); - bool createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name); + bool createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name, std::vector morphemeToFlverBoneMap, int fps); + bool createFbxTake(FbxScene* pScene, std::vector pSkeleton, AnimObject* pAnim, std::string name, int fps); bool createFbxModel(FbxScene* pScene, FlverModel* pModel, std::string modelName, FbxPose* pBindPoses, std::vector pBoneList, std::filesystem::path export_path); bool createFbxModel(FbxScene* pScene, FlverModel* pModel, std::string modelName, FbxPose* pBindPoses, std::vector pBoneList, std::filesystem::path export_path, std::vector flverToMorphemeBoneMap); diff --git a/DS2AnimToolset/morphemeEditor/FileTranslator/XMDTranslator/XMDTranslator.cpp b/DS2AnimToolset/morphemeEditor/FileTranslator/XMDTranslator/XMDTranslator.cpp index 913f70f5..87a78e55 100644 --- a/DS2AnimToolset/morphemeEditor/FileTranslator/XMDTranslator/XMDTranslator.cpp +++ b/DS2AnimToolset/morphemeEditor/FileTranslator/XMDTranslator/XMDTranslator.cpp @@ -555,7 +555,7 @@ namespace XMDTranslator XMD::XAnimCycle* animCycle = static_cast(xmd->CreateNode(XMD::XFn::AnimCycle)); - int animLenFrames = RMath::timeToFrame(animObj->getAnimLenght(), fps) + 1; + const int animLenFrames = RMath::timeToFrame(animObj->getAnimLenght(), fps); animCycle->SetName(takeName); animCycle->SetFrameRate(fps);