Differences Between Python and C++ Versions of the FBX SDK
This article is a translated version of my original post on Qiita. Original (Japanese): https://qiita.com/segur/items/8114d723374c8156789c
Differences Between Python and C++ Versions of the FBX SDK
I read this official document and noted down my understanding. Differences between FBX SDK and Python FBX
The Python version includes most of the functions from the C++ version, but the following differences exist.
Template Functions and Template Classes in C++ Are Not Available in Python
Template functions are a C++ syntax, and they look like this:
template<class T> T Add(T a, T b)
{
return a + b;
}
The T can accept various types.
Since Python does not have a template function syntax, it provides separate functions for each type.
Array Outputs: Pointers in C++ vs. Lists in Python
When a function outputs data similar to an array, the differences are as follows:
- In C++, output is handled via pointers.
- In Python, output is handled via lists.
For example, in the C++ version, there is a function called GetPolygonVertices. (Reference: FbxMesh Class Reference)
Here is a function example (contents are illustrative):
int* GetPolygonVertices(){
int* array = new int[num];
// Some processing
return array;
}
In the Python version, the equivalent function is:
def GetPolygonVertices():
array = []
# Some processing
return array
Passing Pointers in C++ Becomes Tuples in Python
In cases where a function outputs multiple values, the differences are as follows:
- C++ outputs to arguments passed by pointer.
- Python outputs as a tuple (multiple return values).
For example, in the C++ version, there is a function called KeyAdd. (Reference: FbxAnimCurve Class Reference)
Here's an example (contents are illustrative):
int KeyAdd(KTime pTime, int *pLast){
// Some processing
return index;
}
The function outputs:
index: return valuepLast: argument passed by pointer
In the Python version, the function becomes:
def KeyAdd(KTime pTime):
# Some processing
return index, pLast
The first return value is index, and the second is pLast.
Conclusion
It's interesting to compare the differences in syntax between C++ and Python.