Cycles transform from fbx node

Hi,

I am trying to build cycles scene from fbx file using fbx sdk.
This is how I am calculating the Cycles transform from a FbxNode.

The meshes are not positioned properly they are displayed as if they are thrown a part in different directions.

Any idea what I am doing wrong?
Can someone help me?

Thanks in advance.

FbxAMatrix& fbx_transform = CalculateGlobalTransform(fbx_node);
Transform& cycles_transform = fbx_matrix_to_cycles_transform(&fbx_transform );


FbxAMatrix CalculateGlobalTransform(FbxNode *pNode)
{
  FbxAMatrix &lGlobalTransform = pNode->EvaluateGlobalTransform();
  return lGlobalTransform;
}
Transform fbx_matrix_to_cycles_transform(const FbxAMatrix &matrix)
{
  FbxVector4 &translation = matrix.GetT();
  FbxVector4 &rotation = matrix.GetR();
  FbxVector4 &scale = matrix.GetS();
  Transform &transform = transform_euler(make_float3(rotation.mData[0], rotation.mData[1], rotation.mData[2]));

  transform.x.x = scale.mData[0];
  transform.x.w = translation.mData[0];

  transform.y.y = scale.mData[1];
  transform.y.w = translation.mData[1];

  transform.z.z = scale.mData[2];
  transform.z.w = translation.mData[2];

  return transform;
}

You’re overwriting the rotation with the scale. It’s easier not to decompose that matrix into translation/rotation/scale at all, just copy the first 3 rows of the FBX matrix to the Cycles transform.

1 Like

Thank you @brecht for your quick and continuous support

Hi @brecht,
Instead of copying rows, if I copy columns, it works fine. But the only problem is it is mirrored.
Here is my code. Can you please help me in fixing this?

Thanks in advance.

Transform fbx_matrix_to_cycles_transform(const FbxAMatrix &matrix)
{
  Transform transform;
  transform.x.x = matrix.Get(0, 0);
  transform.x.y = matrix.Get(1, 0);
  transform.x.z = matrix.Get(2, 0);
  transform.x.w = matrix.Get(3, 0);

  transform.y.x = matrix.Get(0, 1);
  transform.y.y = matrix.Get(1, 1);
  transform.y.z = matrix.Get(2, 1);
  transform.y.w = matrix.Get(3, 1);

  transform.z.x = matrix.Get(0, 2);
  transform.z.y = matrix.Get(1, 2);
  transform.z.z = matrix.Get(2, 2);
  transform.z.w = matrix.Get(3, 2);

  return transform;
}

Original:

With Cycles:

Hi All,

What is wrong with the below code?
I have been struggling to make it work. Basically I am trying to map Fbx Matrix to Cycles Transform.

Please help me.
Thanks in advance.

FbxAMatrix GetOffsetMatrix(const FbxNode *pNode)
{
  const FbxVector4 lT = pNode->GetGeometricTranslation(FbxNode::eSourcePivot);
  const FbxVector4 lR = pNode->GetGeometricRotation(FbxNode::eSourcePivot);
  const FbxVector4 lS = pNode->GetGeometricScaling(FbxNode::eSourcePivot);
  return FbxAMatrix(lT, lR, lS);
}
// If I use this implementation, the positions of the meshes are not proper. They are misplaced.
Transform fbx_matrix_to_cycles_transform(const FbxAMatrix &matrix)
{
  Transform transform;
  transform.x.x = matrix.Get(0, 0);
  transform.x.y = matrix.Get(0, 1);
  transform.x.z = matrix.Get(0, 2);
  transform.x.w = matrix.Get(0, 3);

  transform.y.x = matrix.Get(1, 0);
  transform.y.y = matrix.Get(1, 1);
  transform.y.z = matrix.Get(1, 2);
  transform.y.w = matrix.Get(1, 3);

  transform.z.x = matrix.Get(2, 0);
  transform.z.y = matrix.Get(2, 1);
  transform.z.z = matrix.Get(2, 2);
  transform.z.w = matrix.Get(2, 3);
  return transform;
}

// If I use this implementation, the positions of the meshes are proper. but their positions are flipped as // shown in the above images.
Transform TransformUtils::fbx_matrix_to_cycles_transform(const FbxAMatrix &matrix)
{
  Transform transform;
  transform.x.x = matrix.Get(0, 0);
  transform.x.y = matrix.Get(1, 0);
  transform.x.z = matrix.Get(2, 0);
  transform.x.w = matrix.Get(3, 0);

  transform.y.x = matrix.Get(0, 1);
  transform.y.y = matrix.Get(1, 1);
  transform.y.z = matrix.Get(2, 1);
  transform.y.w = matrix.Get(3, 1);

  transform.z.x = matrix.Get(0, 2);
  transform.z.y = matrix.Get(1, 2);
  transform.z.z = matrix.Get(2, 2);
  transform.z.w = matrix.Get(3, 2);
  return transform;
}

FbxAMatrix lGlobalPosition = fbx_node->EvaluateGlobalTransform();
FbxAMatrix lGeometryOffset = GetOffsetMatrix(fbx_node);
FbxAMatrix lFinalPosition = lGlobalPosition * lGeometryOffset;   
Transform cycles_global_transform = fbx_matrix_to_cycles_transform(lFinalPosition);

Cycles uses row major layout so fbx_matrix_to_cycles_transform seems most correct.

But I’m not familiar with how FBX transforms work, or why you are composing matrices like this. I would expect there to be a simpler way to do this in the FBX SDK. For Cycles you need an object space to world space transform matrix.

1 Like