Skip to content

Commit

Permalink
bug fix with fps
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRadai committed Dec 2, 2024
1 parent 24aa02c commit e796144
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ std::vector<FbxNode*> FBXTranslator::createFbxMorphemeSkeleton(FbxScene* pScene,
}

//Creates FBX animation take from an NSA file input, adding the FLVER rig
bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name, std::vector<int> morphemeToFlverBoneMap)
bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name, std::vector<int> morphemeToFlverBoneMap, int fps)
{
MR::AnimationSourceHandle* animHandle = pAnim->getHandle();

Expand All @@ -434,16 +434,15 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> 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();
Expand Down Expand Up @@ -478,7 +477,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkele
{
int keyIndex;

float animTime = GetTimeByAnimFrame(animDuration, animSampleRate, frame);
float animTime = GetTimeByAnimFrame(animDuration, fps, frame);

FbxAMatrix transform = ConvertToFbxAMatrix(pAnim->getTransformAtTime(animTime, boneIndex));

Expand Down Expand Up @@ -537,7 +536,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkele
}

//Creates an FBXTake from the NSA file input, adding the morpheme rig
bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name)
bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name, int fps)
{
MR::AnimationSourceHandle* animHandle = pAnim->getHandle();

Expand All @@ -562,7 +561,6 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkele
FbxTime start;
start.SetSecondDouble(0.0);

float animSampleRate = 60;
float animDuration = animSourceNSA->getDuration(animSourceNSA);

FbxTime end;
Expand All @@ -571,7 +569,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> 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();
Expand Down Expand Up @@ -601,7 +599,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> 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)
Expand All @@ -611,7 +609,7 @@ bool FBXTranslator::createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkele
}

FbxTime keyTime;
keyTime.SetFrame(RMath::timeToFrame(animTime, 30));
keyTime.SetFrame(RMath::timeToFrame(animTime, fps));

FbxVector4 translation = transform.GetT();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace FBXTranslator
std::vector<FbxNode*> createFbxFlverSkeleton(FbxScene* pScene, FlverModel* pModel, FbxPose* pBindPoses);
std::vector<FbxNode*> createFbxMorphemeSkeleton(FbxScene* pScene, MR::AnimRigDef* pRig, FbxPose* pBindPoses);

bool createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name, std::vector<int> morphemeToFlverBoneMap);
bool createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name);
bool createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name, std::vector<int> morphemeToFlverBoneMap, int fps);
bool createFbxTake(FbxScene* pScene, std::vector<FbxNode*> pSkeleton, AnimObject* pAnim, std::string name, int fps);

bool createFbxModel(FbxScene* pScene, FlverModel* pModel, std::string modelName, FbxPose* pBindPoses, std::vector<FbxNode*> pBoneList, std::filesystem::path export_path);
bool createFbxModel(FbxScene* pScene, FlverModel* pModel, std::string modelName, FbxPose* pBindPoses, std::vector<FbxNode*> pBoneList, std::filesystem::path export_path, std::vector<int> flverToMorphemeBoneMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ namespace XMDTranslator

XMD::XAnimCycle* animCycle = static_cast<XMD::XAnimCycle*>(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);
Expand Down

0 comments on commit e796144

Please sign in to comment.