Autodesk FBX SDK for Unity (com.autodesk.fbx)

repository·main·Indexed 42 days ago

https://github.com/unity-technologies/com.autodesk.fbx

C# bindings for the Autodesk FBX SDK, specifically tailored to support the Unity Fbx Exporter package. Version 5.1.3 provides access to the FBX SDK via the FbxSdk and Autodesk.Fbx namespaces, mirroring the original C++ API structure. It is available for Unity 2018.3 or later and includes support for standalone builds on Windows, OSX, and Linux via the FBXSDK_RUNTIME symbol.

Tokens
3.1K
Snippets
16
Records
24
Agent score
53%

What's inside Autodesk FBX SDK for Unity

  1. Use the Autodesk.Fbx namespace

    main

    All FBX SDK bindings are contained within the Autodesk.Fbx namespace. To use the library in a C# project (such as a Unity plugin), include the using Autodesk.Fbx; directive.

    Note that most core objects, such as FbxManager, implement IDisposable and should be wrapped in using blocks to ensure proper resource management and memory cleanup of the underlying native SDK components.

    using Autodesk.Fbx;
    using UnityEditor;
    using UnityEngine;
    
    public class HelloFbx {
      [MenuItem("Fbx/Hello")]
      public static void Hello() {
        using(var manager = FbxManager.Create()) {
          Debug.LogFormat("FBX SDK is version {0}", FbxManager.GetVersion());
        }
      }
    }
  2. Understand the limitations of the C# FBX SDK bindings

    main

    The C# bindings expose only a subset of the full C++ Autodesk FBX SDK. Users should be aware of the following constraints:

    • No Downcasting: You cannot downcast SDK C# objects. For example, if a C++ method returns an FbxDeformer, you cannot cast it to an FbxSkinDeformer in C#. This makes the package unsuitable for building FBX importers.
    • Runtime Stability: Performing invalid operations via C# can cause the Unity Editor or standalone application to crash. For example, using an FbxProperty after the parent FbxNode has been deleted leads to undefined behavior.
    • Linux Support: Linux support is currently experimental and not officially supported by Unity. If using Linux, you must ensure libstdc++ 6.0.28 or higher is installed.
  3. Run tests for FbxSharp

    main

    To run the built-in tests, follow these steps:

    1. Create a new 3D project in Unity.
    2. Copy the build/install/com.autodesk.fbx folder from your build directory into the Packages folder of your new Unity project.
    3. In the Unity Editor, navigate to Window > General > Test Runner to execute the tests.
  4. Replace a function with a custom implementation

    main

    You can replace a potentially unsafe or complex C++ function with a custom wrapper. This involves ignoring the original function, renaming it to avoid collision, and using %extend to provide a new version with a safer signature that calls the original internally.

    /* Example: Replacing a variadic SetCode function to avoid crashes */
    %ignore FbxStatus::SetCode(const EStatusCode rhs, const char* pErrorMsg, ...);
    %rename("SetCode") FbxStatus::SetCodeNoFormat;
    
    %extend FbxStatus {
      void SetCodeNoFormat(const EStatusCode rhs, const char* pErrorMsg) {
        $self->SetCode(rhs, "%s", pErrorMsg);
      }
    }
  5. Unignore classes and specific methods

    main

    When using an IGNORE_ALL_INCLUDE_SOME strategy, you can selectively expose classes and specific methods to C# using the %rename directive. To unignore a specific method, you must provide the full signature including parameter types and default values.

    // Unignore an entire class
    %rename("%s") FbxIOBase;
    
    // Unignore a specific method by its full signature
    %rename("%s") FbxIOBase::Initialize(const char *pFileName, int pFileFormat=-1, FbxIOSettings* pIOSettings=NULL);
  6. Include the Autodesk FBX SDK in a standalone build

    main

    By default, this package is only available for use within the Unity Editor. To use the SDK at runtime in standalone builds (Windows, OSX, or Linux only), you must define a specific scripting symbol:

    1. Open Edit > Project Settings in the Unity Editor.
    2. Navigate to Player > Other Settings.
    3. Under Configuration, locate the Scripting Define Symbols field.
    4. Add FBXSDK_RUNTIME to the list of symbols.
    FBXSDK_RUNTIME