### Traversing FBX SDK Hierarchy Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_fbx_sdk_object_model_connections_html Provides a comprehensive example of traversing an FBX SDK hierarchy, starting from a specific object. It demonstrates accessing source objects, source properties, and destination objects, showcasing how to navigate complex connection structures. This involves methods like GetSrcPropertyCount(), GetSrcProperty(), GetDstObject(), GetSrcObject(), and GetDstProperty(). ```cpp // ... Assume obj2 has been initialized to reflect the diagram above... // Access prop2 using obj2. FbxProperty* prop2 = obj2->GetSrcProperty(); // For illustrative purposes, count the number of source properties of prop2. int numSrcProperties = prop2->GetSrcPropertyCount(); // numSrcProperties = 2 // Access prop3 and prop4, which are sources with respect to prop2, // respectively indexed at 0 and 1. FbxProperty* prop3 = prop2->GetSrcProperty(0); FbxProperty* prop4 = prop2->GetSrcProperty(1); // Access obj0 using obj2. FbxObject* obj0 = obj2->GetDstObject(); // Access prop0 using obj0. FbxProperty* prop0 = obj0->GetSrcProperty(); // Access obj1 using obj0. // Here, we assume obj1 is indexed at 0, whereas obj2 is indexed at 1. FbxObject* obj1 = obj0->GetSrcObject(0); // Access prop1 using obj1. FbxProperty* prop1 = obj1->GetSrcProperty(); ``` -------------------------------- ### Sample Code for Maya FBX Extensions Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_fbx_extensions_sdk_fbx_extensions_to_maya_html Locations of sample Visual Studio projects provided within the FBX Extensions SDK that can serve as a starting point for developing Maya FBX extensions. ```APIDOC ## Sample code The following FBX Extensions SDK subdirectories contain sample Visual Studio projects: | Directory | Description | |-------------------------------|-----------------------------------------------------| | `plugins/template/mayatemplateplugin.cxx` | Skeleton code and comments for Maya. | | `plugins/simple/mayacustomdataplugin.cxx` | Fully functional sample extension for Maya. | ``` -------------------------------- ### Set FBX Light Type Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_nodes_and_scene_graph_fbx_node_attributes_lights_html Shows how to set the type of a light using the `FbxLight::LightType` property. The example specifically sets the light to be a spotlight (`FbxLight::eSpot`). Other types include `ePoint` and `eDirectional`. ```cpp // Set the type of the light to a spotlight. lLight->LightType.Set(FbxLight::eSpot); ``` -------------------------------- ### Configure Export Settings (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_io_settings_html Shows how to configure boolean properties for export operations using FbxIOSettings::SetBoolProp(). This enables control over aspects like embedding media, exporting materials, textures, and animations. The example explicitly sets several export options. ```cpp // Set the export states. By default, the export states are always set to // true except for the option eEXPORT_TEXTURE_AS_EMBEDDED. The code below // shows how to change these states. bool lEmbedMedia = true; (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_MATERIAL, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_TEXTURE, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_EMBEDDED, lEmbedMedia); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_SHAPE, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_GOBO, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_ANIMATION, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true); ``` -------------------------------- ### Traverse FBX Scene Nodes and Attributes Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_getting_started_your_first_fbx_sdk_program_html This C++ code snippet demonstrates how to recursively traverse the nodes of an FBX scene, starting from the root node's children. It utilizes a helper function `PrintNode` to process each node and its attributes. The SDK manager is destroyed at the end. ```cpp // Print the nodes of the scene and their attributes recursively. // Note that we are not printing the root node because it should // not contain any attributes. FbxNode* lRootNode = lScene->GetRootNode(); if(lRootNode) { for(int i = 0; i < lRootNode->GetChildCount(); i++) PrintNode(lRootNode->GetChild(i)); } // Destroy the SDK manager and all the other objects it was handling. lSdkManager->Destroy(); ``` -------------------------------- ### Iterate and Print FBX Scene Nodes (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_getting_started_your_first_fbx_sdk_program_html This C++ code snippet demonstrates how to get the root node of an FBX scene, iterate through its children, and print them. It utilizes the Autodesk FBX SDK. Ensure the FBX SDK is correctly linked and initialized before using this code. The snippet concludes with the destruction of the SDK manager. ```cpp FbxNode* lRootNode = lScene->GetRootNode(); if(lRootNode) { for(int i = 0; i < lRootNode->GetChildCount(); i++) PrintNode(lRootNode->GetChild(i)); } // Destroy the SDK manager and all the other objects it was handling. lSdkManager->Destroy(); return 0; ``` -------------------------------- ### Creating and Initializing FbxIOSettings Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_io_settings_html Demonstrates how to create an FbxIOSettings object and associate it with the FbxManager. ```APIDOC ## Creating an IO settings object The `FbxIOSettings` class is responsible for specifying which elements of a scene are imported from a file, or exported to a file. A `FbxIOSettings` object must be instantiated and configured before it is passed to a `FbxImporter` or `FbxExporter` object. ### Method ```cpp // C++ Example #include #include // ... // Create the FBX SDK manager FbxManager* lSdkManager = FbxManager::Create(); // Create an IOSettings object. IOSROOT is defined in Fbxiosettingspath.h. FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT ); lSdkManager->SetIOSettings(ios); ``` ``` -------------------------------- ### Accessing Default TRS Properties Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_nodes_and_scene_graph_fbx_nodes_transformation_data_html Demonstrates how to get the default translation, rotation, and scaling vectors for an FBX node. ```APIDOC ## Accessing Default TRS Properties ### Description Retrieves the default translation, rotation, and scaling vectors for a given FBX node. These properties represent the local transformation of the node relative to its parent. ### Method `Get()` method of `FbxNode::LclTranslation`, `FbxNode::LclRotation`, `FbxNode::LclScaling` ### Endpoint N/A (This is an SDK code example) ### Parameters None directly for the `Get()` method, but requires a valid `FbxNode` object. ### Request Example ```cpp // Get the node’s default TRS properties FbxDouble3 lTranslation = lNode->LclTranslation.Get(); FbxDouble3 lRotation = lNode->LclRotation.Get(); FbxDouble3 lScaling = lNode->LclScaling.Get(); ``` ### Response #### Success Response - **FbxDouble3** (type) - A structure containing X, Y, and Z coordinates for translation, rotation, or scaling. #### Response Example ```json { "translation": {"x": 0.0, "y": 0.0, "z": 0.0}, "rotation": {"x": 0.0, "y": 0.0, "z": 0.0}, "scaling": {"x": 1.0, "y": 1.0, "z": 1.0} } ``` ``` -------------------------------- ### Create and Configure FbxIOSettings Object (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_io_settings_html Demonstrates the creation of an FbxManager and an FbxIOSettings object, which is essential for specifying scene elements during import or export. The IOSettings object is then associated with the FbxManager. ```cpp #include #include // ... // Create the FBX SDK manager FbxManager* lSdkManager = FbxManager::Create(); // Create an IOSettings object. IOSROOT is defined in Fbxiosettingspath.h. FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT ); lSdkManager->SetIOSettings(ios); ``` -------------------------------- ### Configuring Import Settings Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_io_settings_html Shows how to set boolean properties for import options using FbxIOSettings::SetBoolProp(). ```APIDOC ## Configuring the I/O settings - Import settings ### Description Import options determine what kind of data is to be imported. The `IMP_` prefix pertains to import options. ### Method ```cpp // C++ Example // Import options determine what kind of data is to be imported. // True is the default, but here we’ll set some to true explicitly, and others to false. (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_MATERIAL, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_TEXTURE, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_LINK, false); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_SHAPE, false); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_GOBO, false); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_ANIMATION, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true); ``` ``` -------------------------------- ### Get FBX File Version Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_exporting_a_scene_html Retrieves the major, minor, and revision numbers for the exported FBX file format using FbxManager::GetFileFormatVersion(). ```cpp // File format version numbers to be populated. int lMajor, lMinor, lRevision; // Populate the exported file format version numbers. FbxManager::GetFileFormatVersion(lMajor, lMinor, lRevision); ``` -------------------------------- ### Running your FBX Extension for Maya Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_fbx_extensions_sdk_fbx_extensions_to_maya_html Instructions on how to compile and deploy your FBX Extension for Maya, ensuring it is correctly placed for Maya to recognize and load it. ```APIDOC ## Running your FBX Extension for Maya FBX Extensions for Maya must be compiled as dynamic library files (_`.dll`_ for Windows) and placed in the following Maya subdirectory: * `/bin/plug-ins/fbx_` ``` -------------------------------- ### Get FBX File Version Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_importing_a_scene_html Retrieves the major, minor, and revision numbers of the FBX file format that was imported. This information can be useful for compatibility checks or logging. ```cpp // File format version numbers to be populated. int lFileMajor, lFileMinor, lFileRevision; // Populate the FBX file format version numbers with the import file. lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision); ``` -------------------------------- ### Get FBX Manager from Importer Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_fbx_sdk_object_model_fbx_objects_html Retrieves the `FbxManager` singleton associated with an `FbxImporter` instance. This is useful for accessing global SDK settings and managing objects. ```cpp // Assume pImporter is an instance of FbxImporter. FbxManager* lSdkManager = pImporter->GetFbxManager(); ``` -------------------------------- ### FBX SDK: Load and Print Scene Hierarchy (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_getting_started_your_first_fbx_sdk_program_html This C++ code snippet demonstrates the core functionality of loading an FBX file using the FBX SDK and printing its scene hierarchy. It initializes the SDK manager, creates an importer, loads the scene, and then recursively prints node and attribute information. Dependencies include the FBX SDK. The input is an FBX file path, and the output is an XML-like representation to stdout. ```cpp #include /* Tab character ("\t") counter */ int numTabs = 0; /** * Print the required number of tabs. */ void PrintTabs() { for(int i = 0; i < numTabs; i++) printf("\t"); } /** * Return a string-based representation based on the attribute type. */ FbxString GetAttributeTypeName(FbxNodeAttribute::EType type) { switch(type) { case FbxNodeAttribute::eUnknown: return "unidentified"; case FbxNodeAttribute::eNull: return "null"; case FbxNodeAttribute::eMarker: return "marker"; case FbxNodeAttribute::eSkeleton: return "skeleton"; case FbxNodeAttribute::eMesh: return "mesh"; case FbxNodeAttribute::eNurbs: return "nurbs"; case FbxNodeAttribute::ePatch: return "patch"; case FbxNodeAttribute::eCamera: return "camera"; case FbxNodeAttribute::eCameraStereo: return "stereo"; case FbxNodeAttribute::eCameraSwitcher: return "camera switcher"; case FbxNodeAttribute::eLight: return "light"; case FbxNodeAttribute::eOpticalReference: return "optical reference"; case FbxNodeAttribute::eOpticalMarker: return "marker"; case FbxNodeAttribute::eNurbsCurve: return "nurbs curve"; case FbxNodeAttribute::eTrimNurbsSurface: return "trim nurbs surface"; case FbxNodeAttribute::eBoundary: return "boundary"; case FbxNodeAttribute::eNurbsSurface: return "nurbs surface"; case FbxNodeAttribute::eShape: return "shape"; case FbxNodeAttribute::eLODGroup: return "lodgroup"; case FbxNodeAttribute::eSubDiv: return "subdiv"; default: return "unknown"; } } /** * Print an attribute. */ void PrintAttribute(FbxNodeAttribute* pAttribute) { if(!pAttribute) return; FbxString typeName = GetAttributeTypeName(pAttribute->GetAttributeType()); FbxString attrName = pAttribute->GetName(); PrintTabs(); // Note: to retrieve the character array of a FbxString, use its Buffer() method. printf("\n", typeName.Buffer(), attrName.Buffer()); } /** * Print a node, its attributes, and all its children recursively. */ void PrintNode(FbxNode* pNode) { PrintTabs(); const char* nodeName = pNode->GetName(); FbxDouble3 translation = pNode->LclTranslation.Get(); FbxDouble3 rotation = pNode->LclRotation.Get(); FbxDouble3 scaling = pNode->LclScaling.Get(); // Print the contents of the node. printf("\n", nodeName, translation[0], translation[1], translation[2], rotation[0], rotation[1], rotation[2], scaling[0], scaling[1], scaling[2] ); numTabs++; // Print the node's attributes. for(int i = 0; i < pNode->GetNodeAttributeCount(); i++) PrintAttribute(pNode->GetNodeAttributeByIndex(i)); // Recursively print the children. for(int j = 0; j < pNode->GetChildCount(); j++) PrintNode(pNode->GetChild(j)); numTabs--; PrintTabs(); printf("\n"); } /** * Main function - loads the hard-coded fbx file, * and prints its contents in an xml format to stdout. */ int main(int argc, char** argv) { // Change the following filename to a suitable filename value. const char* lFilename = "file.fbx"; // Initialize the SDK manager. This object handles all our memory management. FbxManager* lSdkManager = FbxManager::Create(); // Create the IO settings object. FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT); lSdkManager->SetIOSettings(ios); // Create an importer using the SDK manager. FbxImporter* lImporter = FbxImporter::Create(lSdkManager,""); // Use the first argument as the filename for the importer. if(!lImporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings())) { printf("Call to FbxImporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString()); exit(-1); } // Create a new scene so that it can be populated by the imported file. FbxScene* lScene = FbxScene::Create(lSdkManager,"myScene"); // Import the contents of the file into the scene. lImporter->Import(lScene); // The file is imported; so get rid of the importer. lImporter->Destroy(); // Print the nodes of the scene and their attributes recursively. // Note that we are not printing the root node because it should // not contain any attributes. ``` -------------------------------- ### Create FBX Light Node Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_nodes_and_scene_graph_fbx_node_attributes_lights_html Demonstrates the creation of a light node and a FbxLight object, associating them, and adding the light node to the scene's root. This is the foundational step for implementing any light in the FBX SDK. ```cpp // Create a node for our light in the scene. FbxNode* lLightNode = FbxNode::Create(pScene, "lightNode"); // Create a light. FbxLight* lLight = FbxLight::Create(pScene, "light"); // Set the node attribute of the light node. lLightNode->SetNodeAttribute(lLight); // Add the light node to the root node in the scene. FbxNode* lRootNode = pScene->GetRootNode(); lRootNode->AddChild(lLightNode); ``` -------------------------------- ### Get FBX Scene Evaluator Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_evaluating_animation_in_scene_html Retrieves an animation evaluator object from an FBX scene. This evaluator is essential for accessing and interpolating animated property values over time. It requires a valid FbxScene object. ```cpp // Let us assume that myScene is already created FbxAnimEvaluator* mySceneEvaluator = MyScene->GetAnimationEvaluator(); ``` -------------------------------- ### Initialize FBX Importer Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_importing_a_scene_html Initializes the FbxImporter with the specified file path, format, and IO settings. It requires the FbxManager singleton and an FbxIOSettings object. The function returns a boolean indicating success or failure. ```cpp #include #include // ... // Create the FBX SDK manager FbxManager* lSdkManager = FbxManager::Create(); // Create an IOSettings object. FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT ); lSdkManager->SetIOSettings(ios); // ... Configure the FbxIOSettings object ... // Create an importer. FbxImporter* lImporter = FbxImporter::Create(lSdkManager, ""); // Declare the path and filename of the file containing the scene. // In this case, we are assuming the file is in the same directory as the executable. const char* lFilename = "file.fbx"; // Initialize the importer. bool lImportStatus = lImporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings()); ``` -------------------------------- ### Extract Animation Stacks from FBX Scene (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_extracting_animation_data_html This snippet demonstrates how to get the total number of animation stacks within an FBX scene. It requires a pointer to an FbxScene object. ```cpp int numStacks = pScene->GetSrcObjectCount(FBX_TYPE(FbxAnimStack)); ``` -------------------------------- ### Main Execution Block for FBX Scene Creation and Saving in Python Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_scripting_with_python_fbx_using_python_fbx_with_eclipse_html This is the main execution block that sets up the FBX SDK environment, creates a scene, adds a cube to it, and then saves the scene to a file. It also includes essential cleanup steps to destroy the FBX manager and release memory. ```python ############################################################### # Main. # ############################################################### if __name__ == '__main__': # Create the required FBX SDK data structures. fbxManager = fbx.FbxManager.Create() fbxScene = fbx.FbxScene.Create( fbxManager, '' ) # Add a cube to the scene. addCube( fbxScene ) # Save the scene. saveScene( saveFilename, fbxManager, fbxScene, pAsASCII=True ) ### CLEANUP ### # # Destroy the fbx manager explicitly, which recursively destroys # all the objects that have been created with it. fbxManager.Destroy() # # Once the memory has been freed, it is good practice to delete # the currently invalid references contained in our variables. del fbxManager, fbxScene # ############### ``` -------------------------------- ### Configuring Export Settings Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_io_settings_html Demonstrates setting boolean properties for export options using FbxIOSettings::SetBoolProp(). ```APIDOC ## Configuring the I/O settings - Export settings ### Description Export options control which elements are included when exporting a scene. The `EXP_` prefix pertains to export options. ### Method ```cpp // C++ Example // Set the export states. By default, the export states are always set to // true except for the option eEXPORT_TEXTURE_AS_EMBEDDED. The code below // shows how to change these states. bool lEmbedMedia = true; (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_MATERIAL, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_TEXTURE, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_EMBEDDED, lEmbedMedia); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_SHAPE, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_GOBO, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_ANIMATION, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true); ``` ``` -------------------------------- ### Get Default TRS Properties for FBX Node Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_nodes_and_scene_graph_fbx_nodes_transformation_data_html Retrieves the default translation, rotation, and scaling vectors for an FBX node. These properties are of type FbxDouble3 and represent local offsets from the parent node's transformation. ```cpp // Get the node’s default TRS properties FbxDouble3 lTranslation = lNode->LclTranslation.Get(); FbxDouble3 lRotation = lNode->LclRotation.Get(); FbxDouble3 lScaling = lNode->LclScaling.Get(); ``` -------------------------------- ### Get Number of Animation Layers in FBX Stack (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_extracting_animation_data_html This snippet shows how to determine the number of animation layers contained within a given animation stack. It takes an FbxAnimStack pointer as input. ```cpp int numAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(FbxAnimLayer)); ``` -------------------------------- ### Create and Export FBX Cube Scene with Python Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_scripting_with_python_fbx_using_python_fbx_with_eclipse_html This Python code snippet demonstrates how to use the FBX SDK to create an FbxManager, an FbxScene, add a cubic mesh to the scene, and then save the scene to an FBX file. It defines the cube's vertices and polygons and exports the scene in ASCII format. ```python ''' myFbxProgram.py > Creates a cube in a scene, and saves the scene to 'myFbxSaveFile.fbx' in ASCII format. ''' import fbx # A set of vertices which we will use to create a cube in the scene. cubeVertices = [ fbx.FbxVector4( -5, -5, 5 ), # 0 - vertex index. fbx.FbxVector4( 5, -5, 5 ), # 1 fbx.FbxVector4( 5, 5, 5 ), # 2 fbx.FbxVector4( -5, 5, 5 ), # 3 fbx.FbxVector4( -5, -5, -5 ), # 4 fbx.FbxVector4( 5, -5, -5 ), # 5 fbx.FbxVector4( 5, 5, -5 ), # 6 fbx.FbxVector4( -5, 5, -5 )] # 7 # The polygons (faces) of the cube. polygonVertices = [ ( 0, 1, 2, 3 ), # Face 1 - composed of the vertex index sequence: 0, 1, 2, and 3. ( 4, 5, 6, 7 ), # Face 2 ( 8, 9, 10, 11 ), # Face 3 ( 12, 13, 14, 15 ), # Face 4 ( 16, 17, 18, 19 ), # Face 5 ( 20, 21, 22, 23 )] # Face 6 saveFilename = 'myFbxSaveFile.fbx' ############################################################### # Helper Function(s). # ############################################################### def addCube( pScene ): ''' Adds a cubic mesh to the scene. ''' # Obtain a reference to the scene's root node. rootNode = pScene.GetRootNode() # Create a new node in the scene. newNode = fbx.FbxNode.Create( pScene, 'myNode' ) rootNode.AddChild( newNode ) # Create a new mesh node attribute in the scene, and set it as the new node's attribute newMesh = fbx.FbxMesh.Create( pScene, 'myMesh' ) newNode.SetNodeAttribute( newMesh ) # Define the new mesh's control points. Since we are defining a cubic mesh, # there are 4 control points per face, and there are six faces, for a total # of 24 control points. global cubeVertices newMesh.InitControlPoints( 24 ) # Face 1 newMesh.SetControlPointAt( cubeVertices[0], 0 ) newMesh.SetControlPointAt( cubeVertices[1], 1 ) newMesh.SetControlPointAt( cubeVertices[2], 2 ) newMesh.SetControlPointAt( cubeVertices[3], 3 ) # Face 2 newMesh.SetControlPointAt( cubeVertices[1], 4 ) newMesh.SetControlPointAt( cubeVertices[5], 5 ) newMesh.SetControlPointAt( cubeVertices[6], 6 ) newMesh.SetControlPointAt( cubeVertices[2], 7 ) ``` -------------------------------- ### Initialize FBX SDK Objects and Load Plug-ins Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_customizing_file_formats_with_fbx_html Initializes the FBX SDK manager and scene objects, and loads plug-ins from the application directory. This function is essential for setting up the FBX environment and enabling custom file format support. ```cpp void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene) { // The first thing to do is to create the FBX SDK manager which is the // object allocator for almost all the classes in the SDK. pSdkManager = FbxManager::Create(); if (!pSdkManager) { printf("Unable to create the FBX SDK manager\n"); exit(1); } // create an IOSettings object FbxIOSettings * ios = FbxIOSettings::Create(pSdkManager, IOSROOT ); pSdkManager->SetIOSettings(ios); // Load plugins from the executable directory FbxString lPath = FbxGetApplicationDirectory(); pSdkManager->LoadPluginsDirectory(lPath.Buffer(), lExtension.Buffer()); // Create the entity that will hold the scene. pScene = FbxScene::Create(pSdkManager,""); } ``` -------------------------------- ### Get FBX Node Local Transform Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_evaluating_animation_in_scene_html Retrieves the local transformation matrix of an FbxNode at a specific FbxTime. This matrix represents the node's transformation relative to its parent. It requires the scene evaluator, the node, and the time object. ```cpp // Get a reference to node’s local transform. FbxMatrix& GlobalMatrix = mySceneEvaluator->GetNodeLocalTransform(myMeshNode, myTime); ``` -------------------------------- ### Get FBX Scene Evaluator Instance Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_animation_data_structures_writing_and_using_your_evaluator_html Retrieves an instance of the FbxAnimEvaluator for a given FBX scene. This is typically used to access and manage animation evaluation within the scene. The returned evaluator is an instance of FbxAnimEvalClassic by default. ```cpp FbxAnimEvaluator* mySceneEvaluator = MyScene->GetEvaluator(); ``` -------------------------------- ### Set FBX Light Decay Type Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_nodes_and_scene_graph_fbx_node_attributes_lights_html Explains how to set the decay type for an FBX light using the `FbxLight::DecayType` property. The example sets the decay to quadratic (`FbxLight::eQuadratic`). Other options include `eNone`, `eLinear`, and `eCubic`. ```cpp // Set the decay type of the light to quadratic decay. lLight->DecayType.Set(FbxLight::eQuadratic); ``` -------------------------------- ### Get ASCII Export Format Index in Python Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_scripting_with_python_fbx_using_python_fbx_with_eclipse_html This function retrieves the specific format index required for exporting FBX files in ASCII format. It iterates through available writer formats to find the one with 'ascii' in its description, falling back to the native binary format if not found. ```python def getASCIIFormatIndex( pManager ): ''' Obtain the index of the ASCII export format. ''' # Count the number of formats we can write to. numFormats = pManager.GetIOPluginRegistry().GetWriterFormatCount() # Set the default format to the native binary format. formatIndex = pManager.GetIOPluginRegistry().GetNativeWriterFormat() # Get the FBX format index whose corresponding description contains "ascii". for i in range( 0, numFormats ): # First check if the writer is an FBX writer. if pManager.GetIOPluginRegistry().WriterIsFBX( i ): # Obtain the description of the FBX writer. description = pManager.GetIOPluginRegistry().GetWriterFormatDescription( i ) # Check if the description contains 'ascii'. if 'ascii' in description: formatIndex = i break # Return the file format. return formatIndex ``` -------------------------------- ### Configure Import Settings (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_io_settings_html Illustrates how to set boolean properties for import operations using FbxIOSettings::SetBoolProp(). This allows control over which data types (e.g., materials, textures, animations) are imported from an FBX file. Default values are typically true, but can be explicitly set. ```cpp // Import options determine what kind of data is to be imported. // True is the default, but here we’ll set some to true explicitly, and others to false. (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_MATERIAL, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_TEXTURE, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_LINK, false); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_SHAPE, false); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_GOBO, false); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_ANIMATION, true); (*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true); ``` -------------------------------- ### Import FBX File Contents (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_getting_started_your_first_fbx_sdk_program_html Imports an FBX file into an FbxScene. This involves creating FbxIOSettings and FbxImporter objects. The FbxImporter is initialized with the filename and configured IO settings. If initialization fails, an error message is printed, and the program exits. ```cpp // Create the IO settings object. FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT); lSdkManager->SetIOSettings(ios); // Create an importer using the SDK manager. FbxImporter* lImporter = FbxImporter::Create(lSdkManager,""); // Use the first argument as the filename for the importer. if(!lImporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings())) { printf("Call to FbxImporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString()); exit(-1); ``` -------------------------------- ### Get Animation Curve for Node Translation (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_extracting_animation_data_html This snippet retrieves the animation curve for the local translation (X component) of an FBX node within a specific animation layer. It requires node and layer pointers. ```cpp FbxAnimCurve* lAnimCurve = lNode->LclTranslation.GetCurve(lAnimLayer, FBXSDK_CURVENODE_COMPONENT_X); ``` -------------------------------- ### Get FBX Node Global Transform Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_evaluating_animation_in_scene_html Retrieves the global transformation matrix of an FbxNode at a specific FbxTime. This matrix represents the node's position, rotation, and scale in world space. It requires the scene evaluator, the node, and the time object. ```cpp // Get a reference to node’s global transform. FbxMatrix& GlobalMatrix = mySceneEvaluator->GetNodeGlobalTransform(myMeshNode, myTime); ``` -------------------------------- ### Define Keyframes for FBX Animation Curve (C++) Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_animation_example_animating_a_node_html This code snippet demonstrates how to define keyframes for an animation curve, setting the time, value, and interpolation type. It includes adding start and stop keyframes to animate a property over a specified duration. ```cpp // First the start keyframe myAnimCurve->KeyModifyBegin(); myTime.SetSecondDouble(0.0); // Starting time myKeyIndex = myAnimCurve->KeyAdd(lTime); // Add the start key; returns 0 myAnimCurve->KeySet(lKeyIndex, // Set the zero’th key lTime, // Starting time 0.0, // Starting X value FbxAnimCurveDef::eInterpolationLinear); // Straight line between 2 points // Then the stop keyframe lTime.SetSecondDouble(20.0); lKeyIndex = myAnimCurve->KeyAdd(lTime); myAnimCurve->KeySet(lKeyIndex, lTime, 500.0, FbxAnimCurveDef::eInterpolationLinear); myAnimCurve->KeyModifyEnd(); ``` -------------------------------- ### Initialize FBX Exporter Source: https://help.autodesk.com/view/FBX/2020/ENU/index_guid=FBX_Developer_Help_importing_and_exporting_a_scene_exporting_a_scene_html Initializes the FBX exporter with a specified filename, file format, and I/O settings. The file format is often set to -1 to auto-detect based on the filename extension. Error handling is crucial as initialization can fail. ```cpp #include #include // ... // Create the FBX SDK manager FbxManager* lSdkManager = FbxManager::Create(); // Create an IOSettings object. FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT ); lSdkManager->SetIOSettings(ios); // ... Configure the FbxIOSettings object here ... // Create an exporter. FbxExporter* lExporter = FbxExporter::Create(lSdkManager, ""); // Declare the path and filename of the file to which the scene will be exported. // In this case, the file will be in the same directory as the executable. const char* lFilename = "file.fbx"; // Initialize the exporter. bool lExportStatus = lExporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings()); ```