//----------------------------------------------------------------------------------- SceneImport* FbxLoadSceneFromFile(const char* fbxFilename, const Matrix4x4& engineBasis, bool isEngineBasisRightHanded, const Matrix4x4& transform) { FbxScene* scene = nullptr; FbxManager* fbxManager = FbxManager::Create(); if (nullptr == fbxManager) { Console::instance->PrintLine("Could not create fbx manager."); DebuggerPrintf("Could not create fbx manager."); return nullptr; } FbxIOSettings* ioSettings = FbxIOSettings::Create(fbxManager, IOSROOT); //Name of object is blank, we don't care fbxManager->SetIOSettings(ioSettings); //Create an importer FbxImporter* importer = FbxImporter::Create(fbxManager, ""); bool loadSuccessful = importer->Initialize(fbxFilename, -1, fbxManager->GetIOSettings()); if (loadSuccessful) { //We have imported the FBX scene = FbxScene::Create(fbxManager, ""); bool importSuccessful = importer->Import(scene); ASSERT_OR_DIE(importSuccessful, "Scene import failed!"); } else { Console::instance->PrintLine(Stringf("Could not import scene: %s", fbxFilename)); DebuggerPrintf("Could not import scene: %s", fbxFilename); } SceneImport* import = new SceneImport(); MatrixStack4x4 matrixStack; matrixStack.Push(transform); //Set up our initial transforms Matrix4x4 sceneBasis = GetSceneBasis(scene); Matrix4x4::MatrixTranspose(&sceneBasis); if (!isEngineBasisRightHanded) { Vector3 forward = Matrix4x4::MatrixGetForward(&sceneBasis); Matrix4x4::MatrixSetForward(&sceneBasis, -forward); //3rd row or column } matrixStack.Push(sceneBasis); ImportScene(import, scene, matrixStack); FBX_SAFE_DESTROY(importer); FBX_SAFE_DESTROY(ioSettings); FBX_SAFE_DESTROY(scene); FBX_SAFE_DESTROY(fbxManager); return import; }
//-------------------------------------------------------- // import the XML and convert from collada to mesh //-------------------------------------------------------- SyncBool TLFileSys::TFileCollada::ExportAsset(TPtr<TLAsset::TAsset>& pAsset,TRefRef ExportAssetType) { if ( pAsset ) { TLDebug_Break("Async export not supported yet. asset should be NULL"); return SyncFalse; } // import xml SyncBool ImportResult = TFileXml::Import(); if ( ImportResult != SyncTrue ) return ImportResult; // get the root svg tag (all items are under this and contains scene info) TPtr<TXmlTag> pRootTag = m_XmlData.GetChild("collada"); // malformed SVG maybe if ( !pRootTag ) return SyncFalse; // import material information TLDebug_Print("Collada: Importing material libraries..."); if ( !ImportMaterialLibraries( *pRootTag ) ) return SyncFalse; // import geometry information TLDebug_Print("Collada: Importing geometry libraries..."); if ( !ImportGeometryLibraries( *pRootTag ) ) return SyncFalse; // create mesh asset TPtr<TLAsset::TMesh> pNewMesh = new TLAsset::TMesh( GetFileRef() ); pNewMesh->SetLoadingState( TLAsset::LoadingState_Loaded ); // pull out scene information (ie. what geometry is used, what matierals theyre bound to etc) TLDebug_Print("Collada: Importing scene..."); if ( !ImportScene( *pNewMesh, *pRootTag ) ) return SyncFalse; // assign resulting asset pAsset = pNewMesh; // pre-calc bounds boxes pNewMesh->CalcBounds(); return SyncTrue; }