### Install Core Files, C# Scripts, and Runtime Tests for Unity FBX SDK (CMake) Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake section defines the installation procedures for various components of the Unity FBX SDK. It includes copying protocol buffer definitions, "package.json", generated C# scripts from SWIG, optimized C# scripts, and documentation files like "CHANGELOG.md", "LICENSE.md", and "Third Party Notices.md". Additionally, it installs the entire runtime test framework, including Editor and Runtime test assets and their metadata, ensuring all necessary files are deployed to the correct locations. ```CMake install(DIRECTORY ${CMAKE_SOURCE_DIR}/proto.com.autodesk.fbx/ DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx PATTERN "*.in" EXCLUDE) install(FILES ${CMAKE_BINARY_DIR}/package.json DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx) install(DIRECTORY ${CMAKE_BINARY_DIR}/swig/generated/csharp/ DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Runtime/Scripts FILES_MATCHING PATTERN "*.cs") install(DIRECTORY ${CMAKE_SOURCE_DIR}/Source/optimized/ DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Runtime/Scripts FILES_MATCHING PATTERN "*.cs") install(FILES ${CMAKE_SOURCE_DIR}/CHANGELOG.md DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx) install(FILES ${CMAKE_SOURCE_DIR}/LICENSE.md DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx) install(FILES "${CMAKE_SOURCE_DIR}/Third Party Notices.md" DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx) # Copy the test-run framework install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests/RuntimeTests/Editor" DESTINATION "${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests/") install(FILES "${CMAKE_SOURCE_DIR}/tests/RuntimeTests/Editor.meta" DESTINATION "${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests") install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests/RuntimeTests/Runtime" DESTINATION "${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests/") install(FILES "${CMAKE_SOURCE_DIR}/tests/RuntimeTests/Runtime.meta" DESTINATION "${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests") ``` -------------------------------- ### Basic FbxSdk C# Usage Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/README.md An example demonstrating how to integrate and use the FbxSdk assembly within C# code. It shows accessing global functions via FbxSdk.Globals and managing an FbxManager instance by creating and destroying it. ```C# // Using FbxSdk Assembly using FbxSdk; // global functions found in FbxSdk.Globals var a = FbxSdk.Globals.FbxGetDataTypeNameForIO(b); var sdkManager = FbxManager.Create(); sdkManager.Destroy(); ``` -------------------------------- ### Install Unity FBX SDK Native Library to Editor Plugins (CMake) Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake snippet handles the installation of the "UnityFbxSdkNative" library. On Windows (WIN32), it installs the library into an architecture-specific subdirectory within the "Editor/Plugins" path. For other platforms, it installs directly into the "Editor/Plugins" directory, ensuring the native library is correctly placed for Unity. ```CMake if (WIN32) install(TARGETS UnityFbxSdkNative DESTINATION "${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Editor/Plugins/Win${WIN_ARCHITECTURE_UPPER}") else() install(TARGETS UnityFbxSdkNative DESTINATION "${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Editor/Plugins") endif() ``` -------------------------------- ### Configure CMake to compile against local FBXSDK version Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This CMake snippet shows how to set the `FBXSDK_INSTALL_PATH` variable to a local development directory. This allows the project to compile against a specific, locally installed version of the FBXSDK instead of a system-wide one. ```CMake set(FBXSDK_INSTALL_PATH "~/Development/FbxSharp/spike") ``` -------------------------------- ### Locating SWIG Directive File (swig.swg) Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This snippet provides common file paths for the `swig.swg` file, which contains a complete list of SWIG directives. The paths vary depending on the operating system (OSX, Linux, Windows) where SWIG is installed, helping users find the reference file. ```Shell # OSX /opt/local/share/swig/swig.swg # Linux /usr/local/share/swig/swig.swg # Windows /path/to/swig/directory/Lib/swig.swg ``` -------------------------------- ### Initialize FBX Manager and Get SDK Version in C# Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/proto.com.autodesk.fbx/Documentation~/api_index.md This snippet demonstrates how to initialize the Autodesk FBX SDK manager and retrieve its version using the C# bindings. It requires the "Autodesk.Fbx" namespace and Unity Editor context for the "MenuItem" attribute. ```C# 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()); } } } ``` -------------------------------- ### Configure Unity Package Manager for FBX SDK Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/examples/runtime/HOWTO-useThisExample.txt This snippet shows how to modify the `Packages/manifest.json` file to include the `com.autodesk.fbx` package dependency at a specific preview version, and set the registry for package resolution. This is a crucial step for integrating the FBX SDK into a Unity project. ```JSON { "dependencies": { "com.autodesk.fbx": "1.7.0-preview" }, "registry": "https://staging-packages.unity.com" } ``` -------------------------------- ### SWIG: Replacing C++ Functions with Custom Implementations Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This SWIG example demonstrates how to replace an existing C++ function, `FbxStatus::SetCode`, with a custom implementation, `SetCodeNoFormat`. It uses `%ignore` to hide the original function and `%extend` to provide a new wrapper that calls the original with a formatted string, making it safer for C# interop. ```SWIG /* * SetCode takes a format string and a vararg. That can crash. Make C# pass in * just a string (which you can already format in C# easily) */ %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); } } ``` -------------------------------- ### Selective ignore/unignore for classes, methods, and enums with SWIG Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This SWIG snippet demonstrates advanced `%rename` directives for fine-grained control over what gets ignored or unignored. It shows how to unignore all classes with a specific name and how to ignore everything within a class except its enum items. ```SWIG %rename("%s", %$isclass) ClassName; // unignore all classes with name ClassName // ignore everything in a class except the class itself and the // enum items (these will only show up in C# if we unignore the enum itself) %rename("$ignore", "not" %$isenumitem, regextarget=1, fullname=1) "ClassName::.*"; ``` -------------------------------- ### Define Global and Local Symbols for LIBUNITYFBXSDKNATIVE_1.0 Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/Source/version-script.txt This snippet illustrates a version script used to control symbol visibility for the `LIBUNITYFBXSDKNATIVE_1.0` library. It designates symbols starting with 'CSharp' and 'SWIG' as globally accessible, while all other symbols are restricted to local visibility within the library. ```Linker Script LIBUNITYFBXSDKNATIVE_1.0 { global: CSharp*; SWIG*; local: *; }; ``` -------------------------------- ### Prevent null argument crashes using SWIG check typemaps Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This SWIG snippet provides a `%typemap(check, canthrow=1)` example to prevent functions from crashing when passed null arguments. It checks for null pointers and throws a `SWIG_CSharpNullReferenceException` if a null is detected, ensuring safer interop. ```SWIG // make sure function doesn't crash if we pass it a null string as parameter %typemap(check, canthrow=1) const char* parameter %{ if(!$1){ SWIG_CSharpSetPendingException(SWIG_CSharpNullReferenceException, "$1_basetype $1_name is null"); return $null; } %} // for checking multiple variabls of the same function %typemap(check, canthrow=1) (const char* parameter1, const char* parameter2) %{ if(!$1){ SWIG_CSharpSetPendingException(SWIG_CSharpNullReferenceException, "$1_basetype $1_name is null"); return $null; } %} ``` -------------------------------- ### Configure and Build Native C++ Tests for Unity FBX SDK (CMake) Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake block defines the build process for native C++ tests within the Unity FBX SDK, active when the "YAMATO" variable is 'OFF'. It includes setting up a "vector_test" executable to verify C# and C++ vector behavior, and compiling "unity_tests" for native performance benchmarks. Platform-specific suffixes are applied to the test executables, and test artifacts are installed to the "Tests" directory. ```CMake if (${YAMATO} STREQUAL "OFF") ########################################################################### # enable a test that the C# and C++ vectors behave the same add_executable(vector_test tests/Vectors/Vectors.cpp) target_link_libraries(vector_test ${FBXSDK_LIBRARY} ${CMAKE_DL_LIBS}) # need to include DL libs for Linux add_custom_command(OUTPUT vector_test.txt COMMAND vector_test ARGS ">" vector_test.txt DEPENDS vector_test) add_custom_target(vector_test_output ALL DEPENDS vector_test.txt) ########################################################################### # build the native C++ unit tests add_executable(unity_tests tests/NativePerformance/PerformanceBenchmarks.cpp) target_link_libraries(unity_tests ${FBXSDK_LIBRARY} ${CMAKE_DL_LIBS}) # need to include DL libs for Linux set_target_properties(unity_tests PROPERTIES OUTPUT_NAME "PerformanceBenchmarks") if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set_target_properties(unity_tests PROPERTIES SUFFIX "-mac-x64") elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") set_target_properties(unity_tests PROPERTIES SUFFIX "-win-${WIN_ARCHITECTURE}.exe") elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") find_package(Threads) set_target_properties(unity_tests PROPERTIES SUFFIX "-linux-x64") target_link_libraries(unity_tests ${CMAKE_THREAD_LIBS_INIT}) # need to include pthread libs for Linux endif() install(DIRECTORY ${CMAKE_SOURCE_DIR}/proto.com.autodesk.fbx.testing/ DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests PATTERN "*.in" EXCLUDE) # copy C++ performance tests install(TARGETS unity_tests DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests) install(FILES ${CMAKE_BINARY_DIR}/vector_test.txt DESTINATION ${CMAKE_INSTALL_PREFIX}/com.autodesk.fbx/Tests) endif() ``` -------------------------------- ### Setting Unity Editor Version in Project Configuration Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/TestProjects/FbxSDK/ProjectSettings/ProjectVersion.txt This configuration line, typically found in Unity project asset or meta files, explicitly defines the Unity editor version used to create or last modify the project. It includes major, minor, and patch versions, and can also indicate beta builds (e.g., 'b6'). This setting helps Unity determine compatibility and guides users to the appropriate editor version for opening the project. ```YAML m_EditorVersion: 2018.3.0b6 ``` -------------------------------- ### Locate FbxSharp API Documentation Files Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/README.md Shows the file paths where the generated API documentation can be found after compiling the FbxSharp project. The documentation is available in HTML format and also packaged as a zip file within the Unity package structure. ```plaintext FbxSharp/build/docs/html/index.html FbxSharp/build/install/com.autodesk.fbx/Documentation~/docs.zip ``` -------------------------------- ### Build FbxSharp from Source Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/README.md Instructions to clone the FbxSharp repository and build the project using a Python script. This process requires Unity 2018.4, CMake 3.12, SWIG 3.0.12, and Python 2.7.x or 3.x, along with specific development tools for Windows or macOS. ```bash git clone https://github.com/Unity-Technologies/com.autodesk.fbx.git cd com.autodesk.fbx python build.py ``` -------------------------------- ### Autodesk FBX SDK C# Bindings API Reference Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/proto.com.autodesk.fbx/Documentation~/api_index.md Reference for key components of the Autodesk FBX SDK C# bindings, including the primary namespace and essential classes for managing the SDK. ```APIDOC Namespace: Autodesk.Fbx Description: Contains the C# bindings for the Autodesk FBX SDK. Class: FbxManager Description: Manages the FBX SDK environment. Methods: Create(): FbxManager Description: Creates and initializes an instance of the FbxManager. Returns: An initialized FbxManager object. GetVersion(): string Description: Retrieves the version string of the FBX SDK. Returns: A string representing the FBX SDK version. ``` -------------------------------- ### Find Required Development Packages and Git Information Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This section uses CMake's 'find_package' command to locate essential development tools and libraries, including SWIG, FBXSDK, Python Interpreter, and Git. It also sets up include directories for source files and the FBX SDK, and retrieves Git tag, revision, and repository URL for versioning purposes. ```CMake find_package(SWIG 3.0.12 REQUIRED) include(${SWIG_USE_FILE}) include(cmake/UseFixHeaders.cmake) find_package(FBXSDK REQUIRED) #find_package(Unity REQUIRED) #find_package(CSharpCompiler REQUIRED) find_package(Doxygen) set(Python_ADDITIONAL_VERSIONS 2.7) find_package(PythonInterp REQUIRED) include(cmake/RunPythonScript.cmake) # Set up the include directories include_directories(Source) include_directories(${FBXSDK_INCLUDE_DIR}) # Get git tag as package version find_package(Git REQUIRED) execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags HEAD OUTPUT_VARIABLE PACKAGE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) # only keep x.y.z[-preview.n] string(REGEX REPLACE "^.*([0-9]\.[0-9]\.[0-9].*)$" "\\1" PACKAGE_VERSION "${PACKAGE_VERSION}") # Get git revision hash as package revision execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD OUTPUT_VARIABLE PACKAGE_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE) # Get git repo url execute_process(COMMAND ${GIT_EXECUTABLE} config --get remote.origin.url OUTPUT_VARIABLE PACKAGE_REPO_URL OUTPUT_STRIP_TRAILING_WHITESPACE) configure_file(${CMAKE_SOURCE_DIR}/proto.com.autodesk.fbx/package.json.in ${CMAKE_BINARY_DIR}/package.json @ONLY) ``` -------------------------------- ### Handle REF/OUTPUT arguments in C# using SWIG typemaps Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This SWIG snippet shows how to use `%apply` typemaps to correctly translate C++ reference (`&`) arguments into C# `out` or `ref` parameters. `OUTPUT` maps to `out`, and `INOUT` maps to `ref`. ```SWIG %apply int & OUTPUT { int & pMajor }; // will show up as 'out' in C# %apply int & INOUT { int& pMajor }; // will show up as 'ref' in C# ``` -------------------------------- ### Discover FbxLight Immutables with CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `fbxsharp_discover_immutables` to generate an interface file (`fbxlightimmutables.i`) containing constants and properties for the `FbxLight` class. It depends on `SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS` and includes the `fbxlight.h` header file. ```CMake fbxsharp_discover_immutables(OUTPUT ${CMAKE_BINARY_DIR}/fbxlightimmutables.i TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS HEADERS ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/geometry/fbxlight.h ) ``` -------------------------------- ### Unignore specific class and methods using SWIG %rename Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md When using an 'ignore all, include some' approach, this SWIG snippet demonstrates how to explicitly unignore a class and its specific methods. It uses the `%rename("%s")` directive to make `FbxIOBase` and its `Initialize` method visible for porting. ```SWIG %rename("%s") FbxIOBase; // explicitly unignored the following methods: %rename("%s") FbxIOBase::Initialize(const char *pFileName, int pFileFormat=-1, FbxIOSettings* pIOSettings=NULL); ``` -------------------------------- ### Configure macOS Universal Binary Architecture Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Sets default architectures for macOS builds to 'arm64' and 'x86_64' to create a universal binary, if CMAKE_OSX_ARCHITECTURES is not already defined. It also logs the macOS deployment target and the selected architectures. ```CMake if (APPLE) if (NOT CMAKE_OSX_ARCHITECTURES) set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64") endif() message("Building on macos ${CMAKE_OSX_DEPLOYMENT_TARGET} for arch ${CMAKE_OSX_ARCHITECTURES}") endif() ``` -------------------------------- ### Run Post-Build Script to Add Runtime Define Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command executes a Python script (`add-runtime-define.py`) as a post-build step for the `UnityFbxSdkNative` target. The script operates on the generated C# output directory, likely adding a runtime define or configuration setting. ```CMake fbxsharp_run_python_postbuild(TARGET UnityFbxSdkNative SCRIPT ${CMAKE_SOURCE_DIR}/scripts/add-runtime-define.py ARGS ${CMAKE_BINARY_DIR}/swig/generated/csharp) ``` -------------------------------- ### Generate Weak Pointer Handles File with CMake and Python Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `fbxsharp_run_python` to execute a Python script (`discover-weakpointerhandles.py`) that generates the `weakpointerhandles.i` file. This file identifies types requiring weak-pointer handling, using the previously generated `fbxsdk.typedefs` and specifying top-level hierarchy arguments like `FbxEmitter` and `FbxManager`. ```CMake fbxsharp_run_python(OUTPUT ${CMAKE_BINARY_DIR}/weakpointerhandles.i SCRIPT ${CMAKE_SOURCE_DIR}/scripts/discover-weakpointerhandles.py DEPENDS ${CMAKE_BINARY_DIR}/fbxsdk.typedefs TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS ARGS ${CMAKE_BINARY_DIR}/weakpointerhandles.i ${CMAKE_BINARY_DIR}/fbxsdk.typedefs "FbxEmitter" "FbxManager") ``` -------------------------------- ### Discover FbxMarker Immutables with CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `fbxsharp_discover_immutables` to generate an interface file (`fbxmarkerimmutables.i`) containing constants and properties for the `FbxMarker` class. It depends on `SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS` and includes the `fbxmarker.h` header file. ```CMake fbxsharp_discover_immutables(OUTPUT ${CMAKE_BINARY_DIR}/fbxmarkerimmutables.i TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS HEADERS ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/geometry/fbxmarker.h ) ``` -------------------------------- ### Fetch Platform-Specific FBX SDK and SWIG Dependencies Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This code block identifies the current operating system (macOS, Windows, or Linux) and sets the appropriate artifact names and IDs for the FBX SDK and SWIG. It then uses the 'stevedore' tool to unpack these platform-specific dependencies into the build directory and configures the SWIG_LIB environment variable. ```CMake set(stevedore_repo_name testing) if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") # the artifact is named x64 but it's actually universal set(fbxsdk_artifact_name fbxsdk-mac-x64) set(fbxsdk_artifact_id 2020.3.4_f4efeddec28f0b3510b95445abbea79d3346896501ec49a1efd89d89ca0ea624.7z) set(swig_artifact_name swig-mac-x64) set(swig_artifact_id 3.0.12_814b172e58d71a5f5a35d3e4a1bd07a16d50ac223249d561719a9e71409115e3.7z) set(swig_executable_name swig) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") # the artifact is named x64 but it's actually universal set(fbxsdk_artifact_name fbxsdk-win-x64) set(fbxsdk_artifact_id 2020.3.4-VS2019_fe9152b548177ed45b439ea59b29bf520bcaa416889c5ba4b5552c6f4a59cabd.7z) set(swig_artifact_name swig-win-x64) set(swig_artifact_id 3.0.12_2e184e8ce59cca5da026ac275ef53aff60e8b60ec5edb576efced3f7168f82d8.7z) set(swig_executable_name swig.exe) elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(fbxsdk_artifact_name fbxsdk-linux-x64) set(fbxsdk_artifact_id 2020.3.4_e2b2ef2738cfaacc7912941f5d80d6f64d3b77c93b63f5e50f09351f5a81889c.7z) set(swig_artifact_name swig-linux-x64) set(swig_artifact_id 3.0.12_f3f14d565afd0ec44d3d77298f708f41bd12ef1fa209a1535226cf3e30a5f15b.7z) set(swig_executable_name swig) endif() stevedore(internal-unpack ${stevedore_repo_name} ${fbxsdk_artifact_name}/${fbxsdk_artifact_id} "${CMAKE_BINARY_DIR}/deps/${fbxsdk_artifact_name}") stevedore(internal-unpack ${stevedore_repo_name} ${swig_artifact_name}/${swig_artifact_id} "${CMAKE_BINARY_DIR}/deps/${swig_artifact_name}") file(GLOB_RECURSE SWIG_EXECUTABLE "${CMAKE_BINARY_DIR}/deps/${swig_artifact_name}/${swig_executable_name}") file(GLOB_RECURSE swig_lib "${CMAKE_BINARY_DIR}/deps/${swig_artifact_name}/swig.swg") get_filename_component(swig_lib "${swig_lib}" DIRECTORY) file(TO_NATIVE_PATH "${swig_lib}" swig_lib_native) set(ENV{SWIG_LIB} "${swig_lib_native}") message("FOUND ${swig_lib_native}") endif() ``` -------------------------------- ### Compile SWIG module with multiple .i files Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This snippet demonstrates how to structure SWIG interface files to include multiple `.i` files within a main module definition. It uses `#define EXCLUDE_INTERFACE_FILES` and `%include` directives to combine different header and SWIG directive files into a single compilation unit. ```SWIG #define EXCLUDE_INTERFACE_FILES # porting this file... %include "fbxemitter.i" ``` -------------------------------- ### Run Post-Build Script for IL2CPP Fix Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command executes a Python script (`il2cpp-fix-swighelpers.py`) as a post-build step for the `UnityFbxSdkNative` target. The script targets `NativeMethods.cs`, likely applying fixes or adjustments necessary for compatibility with Unity's IL2CPP scripting backend. ```CMake fbxsharp_run_python_postbuild(TARGET UnityFbxSdkNative SCRIPT ${CMAKE_SOURCE_DIR}/scripts/il2cpp-fix-swighelpers.py ARGS ${CMAKE_BINARY_DIR}/swig/generated/csharp/NativeMethods.cs) ``` -------------------------------- ### Discover FbxTexture Immutables with CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `fbxsharp_discover_immutables` to generate an interface file (`fbxtextureimmutables.i`) containing constants and properties for `FbxTexture` and `FbxFileTexture` classes. It depends on `SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS` and includes specific FBX SDK header files. ```CMake fbxsharp_discover_immutables(OUTPUT ${CMAKE_BINARY_DIR}/fbxtextureimmutables.i TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS HEADERS ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/shading/fbxtexture.h ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/shading/fbxfiletexture.h ) ``` -------------------------------- ### Discover FbxSurfaceMaterial Immutables with CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `fbxsharp_discover_immutables` to generate an interface file (`fbxsurfaceimmutables.i`) containing constants and properties for `FbxSurfaceMaterial`, `FbxSurfaceLambert`, and `FbxSurfacePhong` classes. It depends on `SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS` and includes specific FBX SDK header files. ```CMake fbxsharp_discover_immutables(OUTPUT ${CMAKE_BINARY_DIR}/fbxsurfaceimmutables.i TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS HEADERS ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/shading/fbxsurfacematerial.h ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/shading/fbxsurfacelambert.h ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/shading/fbxsurfacephong.h ) ``` -------------------------------- ### Append CMake Module and Prefix Paths Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Adds custom CMake module and prefix paths to allow the build system to find additional modules and dependencies. This helps in organizing and locating project-specific CMake scripts and external libraries. ```CMake list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/deps") ``` -------------------------------- ### Run Post-Build Script to Replace DllImport Statements Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command executes a Python script (`replace-dllimport.py`) as a post-build step for the `UnityFbxSdkNative` target. The script modifies the `NativeMethods.cs` file, likely to adjust `DllImport` statements for compatibility or specific build environments. ```CMake fbxsharp_run_python_postbuild(TARGET UnityFbxSdkNative SCRIPT ${CMAKE_SOURCE_DIR}/scripts/replace-dllimport.py ARGS ${CMAKE_BINARY_DIR}/swig/generated/csharp/NativeMethods.cs) ``` -------------------------------- ### Configure SWIG C# Output Directory in CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command sets the `CMAKE_SWIG_OUTDIR` variable to specify the output directory for generated C# files from SWIG. This ensures that the generated C# bindings are placed in the correct location within the build directory. ```CMake SET(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/swig/generated/csharp) ``` -------------------------------- ### Add SWIG Library for UnityFbxSdkNative in CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `swig_add_library` to define the `UnityFbxSdkNative` module. It specifies that the library is of `MODULE` type, uses `csharp` as the target language, and processes the `Source/fbxsdk.i` SWIG interface file to generate the native bindings. ```CMake swig_add_library(UnityFbxSdkNative TYPE MODULE LANGUAGE csharp SOURCES Source/fbxsdk.i) ``` -------------------------------- ### Set C++ Standard and Platform-Specific Compiler Flags Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Sets the C++ standard to C++11 for the project. It then configures platform-specific compiler flags: '/WX' for MSVC (warnings as errors), strict warnings with specific suppressions for Apple (due to FBX SDK warnings), and general warnings for other platforms. ```CMake set(CMAKE_CXX_STANDARD 11) if(MSVC) set(PROJECT_COMPILE_FLAGS "/WX") elseif(CMAKE_HOST_APPLE) # Be as strict as possible, but FBX SDK hits a couple of warnings. set(PROJECT_COMPILE_FLAGS "-Werror -Wno-error=null-dereference -Wno-error=deprecated-declarations") else() # No Werror because there's invalid use of incomplete type FbxAnimEvaluator in fbxproperty.h set(PROJECT_COMPILE_FLAGS "-Wall -Wno-format -Wno-strict-aliasing") endif() add_definitions(${PROJECT_COMPILE_FLAGS}) ``` -------------------------------- ### Link SWIG Library with FBX SDK Library Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake command uses `swig_link_libraries` to link the `UnityFbxSdkNative` SWIG-generated library with the core `FBXSDK_LIBRARY`. This step is essential to ensure that the generated native module can correctly interact with the underlying FBX SDK. ```CMake swig_link_libraries(UnityFbxSdkNative ${FBXSDK_LIBRARY}) ``` -------------------------------- ### Set SWIG Virtual Method Flag Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Configures SWIG (Simplified Wrapper and Interface Generator) to prevent the generation of stubs for inherited virtual methods by setting the '-fvirtual' flag. This optimizes the generated wrapper code. ```CMake SET(CMAKE_SWIG_FLAGS -fvirtual) ``` -------------------------------- ### Configure MSVC Runtime Library Linkage Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Ensures that MSVC builds use the multithreaded, static version of the runtime library. It appends '/MD' to release flags and '/MDd' to debug flags, which is crucial for correct linking on Windows. ```CMake if (MSVC) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") endif() ``` -------------------------------- ### Enable Stevedore Dependency Management Option Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Defines a CMake option `USE_STEVEDORE` to control whether Stevedore is used for dependency management, defaulting to OFF. If enabled, it includes the `cmake/Stevedore.cmake` module to handle dependency fetching, useful for continuous integration environments. ```CMake option(USE_STEVEDORE "Use stevedore to get dependencies (useful on continuous integration platforms, default off)" OFF) if (${USE_STEVEDORE} STREQUAL "ON") include(cmake/Stevedore.cmake) ``` -------------------------------- ### Access global definitions in C# via Globals class Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This C# snippet illustrates how global defines, functions, and variables from the C++ side are exposed in C#. They are typically placed into a `Globals.cs` file, allowing access via `FbxSdk.Globals.VarName`. ```C# public class Globals { } ``` -------------------------------- ### Generate SWIG Typedefs for Weak Pointer Handling with CMake Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake `add_custom_command` generates a `fbxsdk.typedefs` file by running SWIG in debug-typedef mode. This is the first step in a two-step process to autogenerate `weakpointerhandles.i`, which is crucial for weak-pointer handling in the generated C# bindings. It uses specific SWIG flags and output directories. ```CMake get_filename_component(FBXSDK_SWIG_I_FILE Source/fbxsdk.i ABSOLUTE) add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/fbxsdk.typedefs COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/fbxsdk.typedefs.temp" COMMAND "${SWIG_EXECUTABLE}" ARGS "-debug-typedef" "-DSWIG_GENERATING_TYPEDEFS" "-c++" "-csharp" "-Werror" "-outdir" "${CMAKE_BINARY_DIR}/fbxsdk.typedefs.temp" "-o" "${CMAKE_BINARY_DIR}/fbxsdk.typedefs.temp/wrap.cxx" ${CMAKE_SWIG_FLAGS} -I${FBXSDK_INCLUDE_DIR} ${FBXSDK_SWIG_I_FILE} ">" "${CMAKE_BINARY_DIR}/fbxsdk.typedefs" BYPRODUCTS "${CMAKE_BINARY_DIR}/fbxsdk.typedefs.temp" MAIN_DEPENDENCY ${FBXSDK_SWIG_I_FILE} DEPENDS ${SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS} ) ``` -------------------------------- ### Configure Platform-Specific Linking for Unity FBX SDK Native Library (CMake) Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake snippet configures platform-specific linking options for the "UnityFbxSdkNative" library. On macOS (Darwin), it sets the target as a bundle and links with an exported symbols list. On Linux, it uses a version script and enables garbage collection sections for the linker. ```CMake if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set_target_properties(UnityFbxSdkNative PROPERTIES BUNDLE TRUE) target_link_libraries(UnityFbxSdkNative "-exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/Source/exported_symbols.txt -Wl,-x,-dead_strip") elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") target_link_libraries(UnityFbxSdkNative "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/Source/version-script.txt -Wl,-x,--gc-sections") endif() ``` -------------------------------- ### Discover Immutable Constants and Properties from FBX SDK Headers Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This CMake snippet utilizes a custom function, 'fbxsharp_discover_immutables', to extract immutable constants from 'fbxdatatypes.h' and properties from 'fbxdocumentinfo.h'. The discovered information is written to generated '.i' files, which are likely used by SWIG for type mapping and interface generation. ```CMake fbxsharp_discover_immutables(OUTPUT ${CMAKE_BINARY_DIR}/fbxdatatypeconstants.i TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS HEADERS ${FBXSDK_INCLUDE_DIR}/fbxsdk/core/fbxdatatypes.h ) # Find the properties for FbxDocumentInfo. fbxsharp_discover_immutables(OUTPUT ${CMAKE_BINARY_DIR}/fbxdocumentinfoimmutables.i TARGETDEPS SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS HEADERS ${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/fbxdocumentinfo.h ) ``` -------------------------------- ### Detect Windows Target Architecture Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Determines the target architecture for Windows builds (e.g., x64, arm64) based on CMAKE_GENERATOR_PLATFORM or environment variables. It stores the architecture in both uppercase (WIN_ARCHITECTURE_UPPER) and lowercase (WIN_ARCHITECTURE) variables and logs the detected platform. ```CMake if (WIN32) if (CMAKE_GENERATOR_PLATFORM) string(TOUPPER "${CMAKE_GENERATOR_PLATFORM}" WIN_ARCHITECTURE_UPPER) elseif("$ENV{PROCESSOR_ARCHITECTURE}" STREQUAL "AMD64") set(WIN_ARCHITECTURE_UPPER "X64") else() set(WIN_ARCHITECTURE_UPPER "$ENV{PROCESSOR_ARCHITECTURE}") endif() string(TOLOWER "${WIN_ARCHITECTURE_UPPER}" WIN_ARCHITECTURE) message(STATUS "Target platform is ${WIN_ARCHITECTURE}") endif() ``` -------------------------------- ### Set CMake Minimum Version and Default Build Type Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Configures the minimum required CMake version (3.08) and sets the default build type to 'Release' if not explicitly defined. It also adds a memory debug flag for 'Debug' builds and logs the current build type and generator platform for Windows. ```CMake cmake_minimum_required (VERSION 3.08) # Default is a release build. if (NOT CMAKE_BUILD_TYPE) # CMAKE_BUILD_TYPE is special, so we have to CACHE FORCE to actually set it, # or else our 'set' has very wonky scope. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) elseif (CMAKE_BUILD_TYPE STREQUAL "Debug") list(APPEND CMAKE_CXX_FLAGS "-DMEMORY_DEBUG") endif() message(STATUS "Building for ${CMAKE_BUILD_TYPE}") if (WIN32) message(STATUS "Building on ${CMAKE_GENERATOR_INSTANCE} for platform ${CMAKE_GENERATOR_PLATFORM}") endif() ``` -------------------------------- ### Accessing FBX SDK Bindings in C# Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/proto.com.autodesk.fbx/README.md Explains how to access FBX SDK bindings in C# within Unity, noting that all bindings are located under the FbxSdk namespace. It demonstrates the conversion from C++ static method calls to C# static method calls. ```C++ FbxManager::Create() ``` ```C# FbxSdk.FbxManager.Create() ``` -------------------------------- ### Add new function to C++ class using SWIG %extend directive Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/docs/porting_classes.md This SWIG snippet demonstrates how to add a new function to an existing C++ class without modifying the original C++ source code. The `%extend` directive allows for injecting new methods directly into the SWIG-generated wrapper. ```SWIG %extend ClassName { void newFunction(){} } ``` -------------------------------- ### Define CMake Project Name Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt Declares the project name for the CMake build system, which is 'UnityFbxSdkNative'. This is a crucial step for CMake to identify and manage the project. ```CMake project (UnityFbxSdkNative) ``` -------------------------------- ### Configure SWIG and Fix FBX SDK Headers Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/CMakeLists.txt This section configures SWIG properties for the 'fbxsdk.i' interface file, including setting the C++ language and a namespace. It also defines extra SWIG dependencies and uses a custom 'swig_fix_header' function to modify specific FBX SDK header files, which is often necessary for SWIG to correctly parse and generate wrappers. ```CMake set_source_files_properties(Source/fbxsdk.i PROPERTIES CPLUSPLUS ON) set_source_files_properties(Source/fbxsdk.i PROPERTIES SWIG_FLAGS "-namespace;Autodesk.Fbx;-Werror") # Set up extra swig dependencies. Must be before building the typemaps. file(GLOB SWIG_MODULE_UnityFbxSdkNative_EXTRA_DEPS "${CMAKE_SOURCE_DIR}/Source/*.i") # Fix the header files we need to fix. Must be before building the typemaps. swig_fix_header(UnityFbxSdkNative "${FBXSDK_INCLUDE_DIR}/fbxsdk/core/fbxpropertytypes.h") swig_fix_header(UnityFbxSdkNative "${FBXSDK_INCLUDE_DIR}/fbxsdk/core/math/fbxmatrix.h") swig_fix_header(UnityFbxSdkNative "${FBXSDK_INCLUDE_DIR}/fbxsdk/core/math/fbxaffinematrix.h") swig_fix_header(UnityFbxSdkNative "${FBXSDK_INCLUDE_DIR}/fbxsdk/scene/geometry/fbxlayer.h") swig_fix_header(UnityFbxSdkNative "${FBXSDK_INCLUDE_DIR}/fbxsdk/core/fbxobject.h") ``` -------------------------------- ### Accessing FBX SDK Global Variables in C# Source: https://github.com/unity-technologies/com.autodesk.fbx/blob/main/proto.com.autodesk.fbx/README.md Describes how to access global variables and functions from the FBX SDK in C#. These are located in the Globals class under the FbxSdk namespace. ```C# FbxSdk.Globals.IOSROOT ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.