#include <fbxsdk.h>
#include "../Common/Common.h"
#include "../Common/AnimationUtility.h"
#include "../Common/GeometryUtility.h"
const char * SAMPLE_FILENAME_BEFORE_CONVECTION = "pivot_before_convection.fbx";
const char * SAMPLE_FILENAME_AFTER_CONVECTION = "pivot_after_convection.fbx";
const char * PYRAMID_NAME = "Pyramid";
const double KEY_TIME[] = {0.0, 0.5, 1.0};
const float KEY_VALUE[] = {0.0, 90.0, 180.0};
int main(int , char** )
{
FbxManager* lSdkManager = NULL;
FbxScene* lScene = NULL;
InitializeSdkObjects(lSdkManager, lScene);
FbxAnimStack * lAnimStack;
FbxAnimLayer * lAnimLayer = CreateDefaultAnimStackAndLayer(lScene, lAnimStack);
FbxNode * lPyramidNode = CreatePyramid(lScene, PYRAMID_NAME, 4, 4);
lPyramidNode->SetRotationActive(true);
lPyramidNode->SetRotationPivot(FbxNode::eSourcePivot, FbxVector4(0, 2, 0));
lPyramidNode->SetPostRotation(FbxNode::eSourcePivot, FbxVector4(0, 0, -90));
FbxAnimCurve * lAnimCurve = lPyramidNode->LclRotation.GetCurve(lAnimLayer, "Y", true);
if (lAnimCurve)
{
const int lKeyCount = sizeof(KEY_TIME)/sizeof(double);
for (int lKeyIndex = 0; lKeyIndex < lKeyCount; ++lKeyIndex)
{
FbxTime lTime;
FbxAnimCurveKey lKey;
lTime.SetSecondDouble(KEY_TIME[lKeyIndex]);
lKey.Set(lTime, KEY_VALUE[lKeyIndex]);
lAnimCurve->KeyAdd(lTime, lKey);
}
}
FbxTime lTime;
lTime.SetSecondDouble(0.5);
FbxAMatrix lLocalTransform = lPyramidNode->EvaluateLocalTransform(lTime);
FbxAMatrix lGlobalTransform = lPyramidNode->EvaluateGlobalTransform(lTime);
bool lResult = SaveScene(lSdkManager, lScene, SAMPLE_FILENAME_BEFORE_CONVECTION);
lPyramidNode->SetPivotState(FbxNode::eSourcePivot, FbxNode::ePivotActive);
lPyramidNode->SetPivotState(FbxNode::eDestinationPivot, FbxNode::ePivotActive);
lPyramidNode->SetPostRotation(FbxNode::eDestinationPivot, FbxVector4(0, 0, 0));
lPyramidNode->SetRotationPivot(FbxNode::eDestinationPivot, FbxVector4(0, 0, 0));
lScene->GetRootNode()->ConvertPivotAnimationRecursive(lAnimStack->GetName(), FbxNode::eDestinationPivot, 30.0);
lPyramidNode->SetRotationPivot(FbxNode::eSourcePivot, FbxVector4(0, 0, 0));
lPyramidNode->SetPostRotation(FbxNode::eSourcePivot, FbxVector4(0, 0, 0));
lResult = SaveScene(lSdkManager, lScene, SAMPLE_FILENAME_AFTER_CONVECTION);
DestroySdkObjects(lSdkManager, lResult);
return 0;
}