Getting the transformation matrix for a node
 
 
 

To get the default translation, rotation, and scaling (default TRS properties) of a node, access the node’s LclTranslation, LclRotation, and LclScaling properties:

KFbxNode myNode;   // A properly initialized node object
 
// Get the node’s default TRS properties
fbxDouble3 myNodeLclTranslation = myNode->LclTranslation.Get();
fbxDouble3 myNodeLclRotation    = myNode->LclRotation.Get();
fbxDouble3 myNodeLclScaling     = myNode->LclScaling.Get();

All three member functions return vectors of type fbxDouble3. The value of each vector is a triplet of X, Y, and Z coordinates. The value of one of these vectors is an offset from the corresponding default TRS property vector for the parent node. A node’s default TRS properties are therefore local to the parent node.

The actual TRS properties for the node at a given point in time depend on:

You can get the node’s TRS properties in the scene’s global coordinate system expressed as a transformation matrix (often called the transform) by calling the GetNodeGlobalTransform member function of the scene’s evaluator and passing the node as a parameter (see KFbxKFbxAnimEvaluator::GetNodeGlobalTransform). This function allows you to get:

KFbxAnimEvaluator* mySceneEvaluator = myScene->getEvaluator();
 
// Get node’s default TRS properties as a transformation matrix
KFbxXMatrix& myNodeDefaultGlobalTransform = 
    mySceneEvaluator->GetNodeGlobalTransform(myNode);
 
// Get transform containing node’s actual TRS properties at a point in time
Ktime myTime;    // Defaults to myTime=0
KFbxXMatrix& myNodeActualGlobalTransform = 
    mySceneEvaluator->GetNodeGlobalTransform(myNode, myTime);

Similarly, the local transformation matrix of a node can be obtained in the following way:

KFbxMatrix lLocalMatrix = myNode->GetScene()->GetEvaluator()->GetNodeLocalTransform(myNode, myTime)
NoteDirectly setting the global transformation matrix of a node is not supported in the FBX SDK.

Baking transform components into the standard TRS transforms

The KFbxNode::ConvertPivotAnimationRecursive() function lets you bake transform components: pre- and post-rotation, rotation and scale pivots and offsets - inside the standard transforms - Translation, Rotation, Scaling. Here is a code snippet.

// Do this setup for each node (KFbxNode).
// We set up what we want to bake via ConvertPivotAnimationRecursive.
// When the destination is set to 0, baking will occur.
// When the destination value is set to the source’s value, the source values will be retained and not baked.
{
    KFbxVector4 lZero(0,0,0);

    // Activate pivot converting
    pNode->SetPivotState(KFbxNode::eSOURCE_SET, KFbxNode::ePIVOT_STATE_ACTIVE);
    pNode->SetPivotState(KFbxNode::eDESTINATION_SET, KFbxNode::ePIVOT_STATE_ACTIVE);

    // We want to set all these to 0 and bake them into the transforms.
    pNode->SetPostRotation(KFbxNode::eDESTINATION_SET, lZero);
    pNode->SetPreRotation(KFbxNode::eDESTINATION_SET, lZero);
    pNode->SetRotationOffset(KFbxNode::eDESTINATION_SET, lZero);
    pNode->SetScalingOffset(KFbxNode::eDESTINATION_SET, lZero);
    pNode->SetRotationPivot(KFbxNode::eDESTINATION_SET, lZero);
    pNode->SetScalingPivot(KFbxNode::eDESTINATION_SET, lZero);

    // This is to import in a system that supports rotation order.
    // If rotation order is not supported, do this instead:
    // pNode->SetRotationOrder(KFbxNode::eDESTINATION_SET , KFbxNode::eEULER_XYZ);
    ERotationOrder lRotationOrder;
    pNode->GetRotationOrder(KFbxNode::eSOURCE_SET , lRotationOrder);
    pNode->SetRotationOrder(KFbxNode::eDESTINATION_SET , lRotationOrder);

    // Similarly, this is the case where geometric transforms are supported by the system.
    // If geometric transforms are not supported, set them to zero instead of
    // the source’s geometric transforms.
    // Geometric transform = local transform, not inherited by children.
    pNode->SetGeometricTranslation(KFbxNode::eDESTINATION_SET, pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET));
    pNode->SetGeometricRotation(KFbxNode::eDESTINATION_SET, pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET));
    pNode->SetGeometricScaling(KFbxNode::eDESTINATION_SET, pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET));

    // Idem for quaternions.
    pNode->SetUseQuaternionForInterpolation(KFbxNode::eDESTINATION_SET, pNode->GetUseQuaternionForInterpolation(KFbxNode::eSOURCE_SET));
}

// When the setup is done, call ConvertPivotAnimationRecursive to the scene’s root node.
// Sampling rate e.g. 30.0.
mScene->GetRootNode()->ConvertPivotAnimationRecursive(KFbxNode::eDESTINATION_SET, lSamplingRate );
NoteTo avoid re-computing the pivots matrices and updating the animation curves each time one of the parameters is changed, the FBX SDK only applies the new settings when an explicit call is made to ResetPivotSetAndConvertAnimation() or ConvertPivotAnimationRecursive().

Notes on scene conversion

A scene's axis and unit system can be respectively changed using the following functions:

Note that calls to ConvertScene() do not change the vertex values of meshes, and only affect node transforms and animations. If the scene is already in the required axis system or required unit system, a call to ConvertScene() will have no effect on the scene. For example:

NoteIf your scene is improperly scaled after unit conversion, this might be caused by different nodes inherit types (ETransformInheritType), specifically the nodes with inherit type eINHERIT_Rrs. To avoid this problem, make sure to avoid unit conversion on these nodes by using the conversion options in the following code snippet. This code snippet additionally illustrates how to convert a scene's units from centimeters (cm) into meters (m):
if(lScene->GetGlobalSettings().GetSystemUnit() == KFbxSystemUnit::cm)
{
  const KFbxSystemUnit::KFbxUnitConversionOptions lConversionOptions = {
    false, /* mConvertRrsNodes */
    true, /* mConvertAllLimits */
    true, /* mConvertClusters */
    true, /* mConvertLightIntensity */
    true, /* mConvertPhotometricLProperties */
    true  /* mConvertCameraClipPlanes */
  };
  
  // Convert the scene to meters using the defined options.
  KFbxSystemUnit::m.ConvertScene(lScene, lConversionOptions);
}

See Also