DEV Community

Shoichi Okaniwa
Shoichi Okaniwa

Posted on • Originally published at qiita.com

Differences Between Python and C++ Versions of the FBX SDK

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;
}
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

In the Python version, the equivalent function is:

def GetPolygonVertices():
    array = []
    # Some processing
    return array
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

The function outputs:

  • index: return value
  • pLast: argument passed by pointer

In the Python version, the function becomes:

def KeyAdd(KTime pTime):
    # Some processing
    return index, pLast
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)