shared_ptr<Mesh> MeshImporter::createFromFBX(string filename) { FbxManager *manager = FbxManager::Create(); FbxIOSettings *ioSettings = FbxIOSettings::Create(manager, IOSROOT); manager->SetIOSettings(ioSettings); FbxImporter *importer = FbxImporter::Create(manager, ""); importer->Initialize(filename.c_str(), -1, manager->GetIOSettings()); FbxScene *scene = FbxScene::Create(manager, "tempName"); importer->Import(scene); importer->Destroy(); FbxNode* rootNode = scene->GetRootNode(); if(rootNode) { vector<Vector3> vertices; vector<Color> colors; vector<Vector2> uvs; vector<Vector3> normals; vector<uint32> elements; importFBXNode(rootNode, vertices, colors, uvs, normals, elements); return shared_ptr<Mesh>(new Mesh(vertices, colors, uvs, elements)); } return nullptr; }
int FbxLoader::LoadFbx(const char* fbxName) { m_fbxManager = FbxManager::Create(); FbxIOSettings *ios = FbxIOSettings::Create(m_fbxManager, IOSROOT); m_fbxManager->SetIOSettings(ios); FbxImporter* lImporter = FbxImporter::Create(m_fbxManager, ""); if (!lImporter->Initialize(fbxName, -1, m_fbxManager->GetIOSettings())) { printf("Call to FbxImporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString()); return -1; } FbxScene* lScene = FbxScene::Create(m_fbxManager, "myScene"); lImporter->Import(lScene); lImporter->Destroy(); m_rootNode = lScene->GetRootNode(); if (m_rootNode) { m_firstNode = m_rootNode->GetChild(0); for (int i = 0; i < m_rootNode->GetChildCount(); i++) LoadNode(m_rootNode->GetChild(i)); } m_animEvaluator = lScene->GetAnimationEvaluator(); return 0; }
bool Model::loadFBXFromFile(const string& fileName) { //initialize the sdk manager FbxManager *manager = FbxManager::Create(); //setting up the IO settings object FbxIOSettings *settings = FbxIOSettings::Create(manager, IOSROOT); manager->SetIOSettings(settings); //creating the importer FbxImporter *importer = FbxImporter::Create(manager, ""); //initializing the importer with contents of file if (!importer->Initialize(fileName.c_str(), -1, settings)) return false; //creating a scene to be filled with objects FbxScene *scene = FbxScene::Create(manager, "myScene"); importer->Import(scene); FbxGeometryConverter geomConverter(manager); geomConverter.Triangulate(scene, true); FbxNode *root = scene->GetRootNode(); if (root) { //printf("Root Node: %s\n", root->GetName()); int childCount = root->GetChildCount(); for (int i = 0; i < childCount; i++) processNode(root->GetChild(i), 1); } importer->Destroy(); return true; }
FbxScene* ImportFbxScene(const string& fileName, FbxManager* manager) { LOG("Importing \"%\"", fileName); FbxImporter* importer = FbxImporter::Create(manager, ""); FbxIOSettings* iosettings = FbxIOSettings::Create(manager, IOSROOT); manager->SetIOSettings(iosettings); auto importStatus = importer->Initialize(fileName.c_str(), -1, iosettings); //bool if (!importStatus) { LOG("Error initializing fbx importer: %", importer->GetStatus().GetErrorString()); return nullptr; } FbxScene* scene = FbxScene::Create(manager, "Scene"); importer->Import(scene); int major, minor, revision; importer->GetFileVersion(major, minor, revision); LOG("Success! File version is %.%.%", major, minor, revision); return scene; }
/** * FBX ファイルをシーンに読み込む * * @param file_path FBX ファイルパス */ bool FbxFileLoader::load_fbx( const char_t* file_path ) { bool result = false; if ( fbx_scene_ ) { fbx_scene_->Destroy( true ); } fbx_scene_ = FbxScene::Create( fbx_manager_, "scene" ); FbxImporter* importer = FbxImporter::Create( fbx_manager_, "" ); if ( importer->Initialize( file_path, -1, fbx_manager_->GetIOSettings() ) ) { result = importer->Import( fbx_scene_ ); } importer->Destroy(); FbxGeometryConverter converter( fbx_manager_ ); converter.Triangulate( fbx_scene_, true ); return result; }
void FbxUtil::LoadScene(const std::string &filePath, const std::shared_ptr<SceneNode> &rootNode, float scaleFactor, unsigned int options) { FbxManager* sdkManager = FbxManager::Create(); FbxIOSettings* ios = FbxIOSettings::Create(sdkManager, IOSROOT); sdkManager->SetIOSettings(ios); FbxImporter* importer = FbxImporter::Create(sdkManager, ""); m_ScaleFactor = scaleFactor; m_Options = options; if (importer->Initialize(filePath.c_str(), -1, sdkManager->GetIOSettings())) { FbxScene* lScene = FbxScene::Create(sdkManager, ""); importer->Import(lScene); importer->Destroy(); FbxNode* lRootNode = lScene->GetRootNode(); if (lRootNode) { for (int i = 0; i < lRootNode->GetChildCount(); i++) LoadNode(rootNode, lRootNode->GetChild(i)); rootNode->Recompose(); } } else ASSERT_MSG(false, "Error: " << importer->GetStatus().GetErrorString()); // Destroy the SDK manager and all the other objects it was handling. sdkManager->Destroy(); }
void LoadScene(FbxManager* pManager,FbxScene*& pScene, const char* fileName) { FbxImporter* sceneImporter = FbxImporter::Create(pManager,""); sceneImporter->Initialize(fileName,-1,pManager->GetIOSettings()); sceneImporter->Import(pScene); sceneImporter->Destroy(); }
FbxScene* getScene(std::string filePath, FbxManager* manager) { // Create an importer using the SDK manager. FbxImporter* importer = FbxImporter::Create(manager,""); // Use the first argument as the filename for the importer. if(!importer->Initialize(filePath.c_str(), -1, manager->GetIOSettings())) { printf("Call to FbxImporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", importer->GetStatus().GetErrorString()); return nullptr; } // Create a new scene so that it can be populated by the imported file. FbxScene* scene = FbxScene::Create(manager,"myScene"); // Import the contents of the file into the scene. if (importer->Import(scene)) { std::cout << "Scene is succefully loaded." << std::endl; } else { std::cout << "Scene is NOT loaded." << std::endl; } // The file is imported; so get rid of the importer. importer->Destroy(); return scene; }
void FBXImporter::LoadScene(const char* fileName) { FbxImporter* sceneImporter = FbxImporter::Create(mSDKManager, "importer"); sceneImporter->Initialize(fileName, -1, mSDKManager->GetIOSettings()); sceneImporter->Import(mScene); sceneImporter->Destroy(); }
void MyGameFbxSceneLoader::loadSceneFromFbx( MyGameScene::MyGameSceneManager* sceneMgr, const string& fileName, MyGameSceneNode* node, vector<MyGameSceneEntity*>& entityList ) { FbxManager* fbxMgr= FbxManager::Create(); FbxIOSettings* fbxIO = FbxIOSettings::Create( fbxMgr, IOSROOT ); fbxMgr->SetIOSettings( fbxIO ); FbxScene* fbxScene = FbxScene::Create( fbxMgr, "test" ); FbxImporter* importer = FbxImporter::Create( fbxMgr, "" ); importer->Initialize( fileName.c_str(), -1, fbxMgr->GetIOSettings() ); importer->Import( fbxScene ); fbxIO->Destroy(); FbxNode* rootNode = fbxScene->GetRootNode(); FbxGeometryConverter converter( fbxMgr ); converter.TriangulateInPlace( rootNode ); getNodeFromFbxNode( sceneMgr, rootNode, node, entityList ); rootNode->Destroy(); fbxScene->Destroy(); fbxMgr->Destroy(); }
//FbxManager* lSdkManager = FbxManager::Create(); sb7fbxmodel::sb7fbxmodel(char *fileName) { 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(fileName, -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); ProcessNode(lScene->GetRootNode()); // The file is imported; so get rid of the importer. lImporter->Destroy(); }
//----------------------------------------------------------------------------------- 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; }
// FBXデータから頂点データにコンバート // ※パスは「/」でしか通らない //const char* filename = "../datas/box.fbx"; bool LoadFBXConvertToVertexData(const char* filename, VertexDataArray& outVertexData) { //============================================================================== // FBXオブジェクト初期化 //============================================================================== // FBXマネージャー作成 FbxManager* pFBXManager = FbxManager::Create(); // シーン作成 FbxScene* pScene = FbxScene::Create(pFBXManager, ""); // FBXのIO設定オブジェクト作成 FbxIOSettings *pIO = FbxIOSettings::Create(pFBXManager, IOSROOT); pFBXManager->SetIOSettings(pIO); // インポートオブジェクト作成 FbxImporter* pImporter = FbxImporter::Create(pFBXManager, ""); // ファイルインポート if(pImporter->Initialize(filename, -1, pFBXManager->GetIOSettings()) == false) { return false; } // シーンへインポート if(pImporter->Import(pScene) == false) { return false; } // ※この時点でインポートオブジェクトはいらない pImporter->Destroy(); //============================================================================== // FBXオブジェクトの処理 //============================================================================== // シーンのものすべてを三角化 FbxGeometryConverter geometryConverte(pFBXManager); geometryConverte.Triangulate(pScene, true); // メッシュ情報処理 GetMeshData(pScene->GetRootNode(), outVertexData); //============================================================================== // FBXオブジェクト色々破棄 //============================================================================== pIO->Destroy(); pScene->Destroy(); pFBXManager->Destroy(); getchar(); return true; }
//=============================================================================================================================== bool FBXLoader::LoadScene() { LARGE_INTEGER start; LARGE_INTEGER end; int fileMinor, fileRevision; int sdkMajor, sdkMinor, sdkRevision; int fileFormat; QueryPerformanceCounter(&start); { FbxString filePath = FbxGetApplicationDirectory(); m_pFBXManager->LoadPluginsDirectory(filePath.Buffer()); FbxManager::GetFileFormatVersion(sdkMajor, sdkMinor, sdkRevision); FbxImporter* pImporter = FbxImporter::Create(m_pFBXManager, ""); m_pFbxScene = FbxScene::Create(m_pFBXManager, ""); if(!m_pFBXManager->GetIOPluginRegistry()->DetectReaderFileFormat(mInputFilePath.c_str(), fileFormat)) { //Unrecognizable file format. Try to fall back on FbxImorter::eFBX_BINARY fileFormat = m_pFBXManager->GetIOPluginRegistry()->FindReaderIDByDescription("FBX binary (*.fbx)"); } bool bSuccess = pImporter->Initialize(mInputFilePath.c_str(), fileFormat, m_pFBXManager->GetIOSettings()); pImporter->GetFileVersion(fileMinor, fileMinor, fileRevision); if(!bSuccess) { printf( "ERROR %s : %d FbxImporter Initialize failed!\n", __FILE__, __LINE__ ); return false; } bSuccess = pImporter->Import(m_pFbxScene); if (!bSuccess) { return false; } pImporter->Destroy(); // Very Important!! Triangulate all meshes in the scene // DirectX must have this to render the mesh properly FbxGeometryConverter clsConv(m_pFBXManager); bool triangulate = clsConv.Triangulate(m_pFbxScene, true); } QueryPerformanceCounter(&end); float finalTime = ((end.QuadPart - start.QuadPart) / static_cast<float>(mCPUFreq.QuadPart)); string finalTimeStr = ZShadeSandboxGlobal::Convert::ConvertToString<float>(finalTime); outFile << "Loading FBX File: " << finalTimeStr << "s\n"; }
//-------------------------------------------------------------------------- void ConvertorFBX(const char* lFilename, const VeDirectoryPtr& spDest) noexcept { FbxManager* lSdkManager = FbxManager::Create(); VE_ASSERT_ALWAYS(lSdkManager); VeUserLogI("Autodesk FBX SDK version ", lSdkManager->GetVersion()); FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT); VE_ASSERT_ALWAYS(ios); lSdkManager->SetIOSettings(ios); FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "Import for Venus3D"); VE_ASSERT_ALWAYS(lImporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings())); FbxScene* lScene = FbxScene::Create(lSdkManager, "ImportedScnee"); VE_ASSERT_ALWAYS(lImporter->Import(lScene)); SaveContent(lScene, spDest); lSdkManager->Destroy(); }
// Load Fbx File void GenerateLOD::LoadFbx() { FbxManager *fbxManager = FbxManager::Create(); //Create an IOSetting FbxIOSettings *ios = FbxIOSettings::Create(fbxManager, IOSROOT); fbxManager->SetIOSettings(ios); //Create an impoter FbxImporter *lImporter = FbxImporter::Create(fbxManager, "myImporter"); std::string tmp = std::string(".\\LODs\\") + srcFbxName; bool lImporterStatus = lImporter->Initialize(tmp.c_str(), -1, fbxManager->GetIOSettings()); if (!lImporterStatus) { MessageBox(NULL, "No Scuh File in .\\LODs\\ directory !", "Warning", 0); return; } FbxScene *fbxScene = FbxScene::Create(fbxManager, "myScene"); lImporter->Import(fbxScene); FbxNode *rootNode = fbxScene->GetRootNode(); if (rootNode != NULL) { for (int i = 0; i < rootNode->GetChildCount(); ++i) { FbxNode *node = rootNode->GetChild(i); FbxNodeAttribute *Att = node->GetNodeAttribute(); if (Att != NULL && Att->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh *lMesh = (FbxMesh *)(Att); //FbxMesh *lMesh = dynamic_cast<FbxMesh *>(Att); if (!lMesh->IsTriangleMesh()) { FbxGeometryConverter converter = FbxGeometryConverter(fbxManager); FbxNodeAttribute *Attr = converter.Triangulate(lMesh, true); lMesh = (FbxMesh *)(Attr); } //Following is the SImplification Reduction_EdgesCollapse_UV(node, lMesh, fbxManager, fbxScene); } } } //MessageBox(NULL, "Export Succeed!", "Export", 0); fbxManager->Destroy(); }
Model::Model(char* name) { FbxManager* lSdkManager = FbxManager::Create(); FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT); this->modelName = name; lSdkManager->SetIOSettings(ios); FbxImporter* lImporter = FbxImporter::Create(lSdkManager, ""); std::string path = MODELS_SUBDIR + std::string(name); if (!lImporter->Initialize(path.c_str(), -1, lSdkManager->GetIOSettings())) TriggerCrash("Nie mo¿na znaleœæ modelu!"); FbxScene* lScene = FbxScene::Create(lSdkManager, "myScene"); //pobranie calego fbx'a lImporter->Import(lScene); for (int i = 0; i < lScene->GetRootNode()->GetChildCount(); i++){ //leci po wszystkich modelach w fbx FbxNode* node = lScene->GetRootNode()->GetChild(i); char* texBaseName = (char*) node->GetName(); this->objects.push_back(new ModelObject(node)); } Models.push_back(this); }
GameObject * loadFBXFromFile(const std::string& filename) { GameObject *rootGo = NULL; level = 0; // Initialize the SDK manager. This object handles 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, ""); // Create a new scene so that it can be populated by the imported file. if (!lImporter->Initialize(filename.c_str(), -1, lSdkManager->GetIOSettings())) { return rootGo; } // 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); // 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) { rootGo = new GameObject(); rootGo->setTransform(new Transform()); std::cout << "Root Node " << lRootNode->GetName() << std::endl; for (int i = 0; i < lRootNode->GetChildCount(); i++) { processNode(lRootNode->GetChild(i), rootGo); } } return rootGo; }
Model::Model(const std::string &filename) { key = filename; if (ResourceManager::access<Data *>(key)) return; int level = 0; // Initialize the SDK manager. This object handles 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, ""); Data *model = new Data(); // Create a new scene so that it can be populated by the imported file. if (!lImporter->Initialize(filename.c_str(), -1, lSdkManager->GetIOSettings())) { LOG(FATAL) << "Failed to load model " << filename; } // 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); // 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) { LOG(INFO) << "Root Node " << lRootNode->GetName(); for (int i = 0; i < lRootNode->GetChildCount(); i++) { level = processNode(lRootNode->GetChild(i), level, *model); } } ResourceManager::store(filename, Resource::Type::Model, model); }
void initializeFbxSdk() { const char* lFilename = "testCube.fbx"; mySdkManager = FbxManager::Create(); // Create the IO settings object. FbxIOSettings *ios = FbxIOSettings::Create(mySdkManager, IOSROOT); mySdkManager->SetIOSettings(ios); // Create an importer using the SDK manager. FbxImporter* lImporter = FbxImporter::Create(mySdkManager,""); // Use the first argument as the filename for the importer. if(!lImporter->Initialize(lFilename, -1, mySdkManager->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(mySdkManager,"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. 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. mySdkManager->Destroy(); }
//----------------------------------------------------------------------------------- void FbxListScene(const char* filename) { FbxManager* fbxManager = FbxManager::Create(); if (nullptr == fbxManager) { Console::instance->PrintLine("Could not create fbx manager."); DebuggerPrintf("Could not create fbx manager."); return; } 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(filename, -1, fbxManager->GetIOSettings()); if (loadSuccessful) { //We have imported the FBX FbxScene* scene = FbxScene::Create(fbxManager, ""); bool importSuccessful = importer->Import(scene); if (importSuccessful) { FbxNode* root = scene->GetRootNode(); PrintNode(root, 0); } FBX_SAFE_DESTROY(scene); } else { Console::instance->PrintLine(Stringf("Could not import scene: %s", filename)); DebuggerPrintf("Could not import scene: %s", filename); } FBX_SAFE_DESTROY(importer); FBX_SAFE_DESTROY(ioSettings); FBX_SAFE_DESTROY(fbxManager); }
bool FbxSerializer::load(const String &path, void *&pData) { if (mFbxManager == nullptr) { T3D_LOG_ERROR("FBX Manager haven't been initialized !"); return false; } // Create an importer FbxImporter *pFbxImporter = FbxImporter::Create(mFbxManager, ""); // Initialize the importer by providing a filename. bool bImportStatus = pFbxImporter->Initialize(path.c_str(), -1, mFbxManager->GetIOSettings()); if (!bImportStatus) { T3D_LOG_ERROR("Unable to initialize FBX importer !"); return false; } // Import the scene bool bStatus = pFbxImporter->Import(mFbxScene); // Destroy the importer pFbxImporter->Destroy(); // 统一切换成OpenGL的右手坐标系和以米为单位的坐标系 FbxAxisSystem::OpenGL.ConvertScene(mFbxScene); // 统一以1米为单位 FbxSystemUnit::m.ConvertScene(mFbxScene); // 不是三角形为面的mesh,统一转换成三角形为面的mesh FbxGeometryConverter converter(mFbxManager); converter.Triangulate(mFbxScene, true); pData = mFbxScene; return bStatus; }
JNIEXPORT jboolean JNICALL Java_de_tesis_dynaware_javafx_graphics_importers_fbx_JFbxLib_open(JNIEnv *env, jobject obj, jstring filePath) { sdkManager = FbxManager::Create(); FbxIOSettings *ios = FbxIOSettings::Create(sdkManager, IOSROOT); sdkManager->SetIOSettings(ios); FbxImporter *importer = FbxImporter::Create(sdkManager,""); if(!importer->Initialize(env->GetStringUTFChars(filePath, 0), -1, sdkManager->GetIOSettings())) { throwIOException(env); } FbxScene *scene = FbxScene::Create(sdkManager,""); importer->Import(scene); importer->Destroy(); currentNode = scene->GetRootNode(); return JNI_TRUE; }
FbxFileReader::FbxFileReader(const string& filename) : m_pScene(nullptr), m_pSdkManager(nullptr) { // Initialize the resources needed to import fbx files m_pSdkManager = FbxManager::Create(); FbxIOSettings* pIOSettings = FbxIOSettings::Create(m_pSdkManager, IOSROOT); m_pSdkManager->SetIOSettings(pIOSettings); FbxImporter* pImporter = FbxImporter::Create(m_pSdkManager,""); if( !pImporter->Initialize(filename.c_str(), -1, pIOSettings) ) throw exception("Failed to initialize FbxImporter."); // Prepare a scene to contain the fbx data m_pScene = FbxScene::Create(m_pSdkManager,"myScene"); pImporter->Import(m_pScene); // Done importing pImporter->Destroy(); //Check if the scene contains a root node if( !m_pScene->GetRootNode() ) throw std::exception("No RootNode could be found."); }
bool FbxParser::LoadScene(const char* pFilename) { if(!mpFbxManager) if (mpFbxScene) mpFbxScene->Clear(); int lSDKMajor, lSDKMinor, lSDKRevision; int lFileMajor, lFileMinor, lFileRevision; // Get the file version number generate by the FBX SDK. FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); // Create an importer. FbxImporter* lImporter = FbxImporter::Create(mpFbxManager,""); // Initialize the importer by providing a filename. const bool lImportStatus = lImporter->Initialize(pFilename, -1, mpFbxManager->GetIOSettings()); lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision); if (!lImportStatus) { lImporter->Destroy(); return false ; } if (lImporter->IsFBX()) { // Set the import states. By default, the import states are always set to // true. The code below shows how to change these states. mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_MATERIAL, true); mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_TEXTURE, true); mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_LINK, true); mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_SHAPE, true); mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_GOBO, true); mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_ANIMATION, true); mpFbxManager->GetIOSettings()->SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true); } // Import the scene. bool lStatus = lImporter->Import(mpFbxScene); lImporter->Destroy(); return lStatus; }
FbxScene* FBXLoader::LoadScene(const char* aFile) { // Create an importer using the SDK manager. FbxImporter* lImporter = FbxImporter::Create(myFbxManager,""); // Use the first argument as the filename for the importer. if(!lImporter->Initialize(aFile, -1, myFbxManager->GetIOSettings())) { printf("Call to FbxImporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString()); std::string errorMessage = "Could not find fbx file: " + std::string(aFile); FBX_LOG(errorMessage.c_str()); MessageBoxA(nullptr, errorMessage.c_str(), "ERROR", 0); //DL_ASSERT("Fbx file not found. Check the debug logger!"); } // Create a new scene so that it can be populated by the imported file. FbxScene* lScene = FbxScene::Create(myFbxManager, "myScene"); // Import the contents of the file into the scene. lImporter->Import(lScene); // The file is imported; so get rid of the importer.a lImporter->Destroy(); FbxGeometryConverter lGeomConverter(myFbxManager); lGeomConverter.Triangulate(lScene, /*replace*/true); //FbxMesh mesh; //mesh.GenerateTangentsData( //lGeomConverter.Comp //lGeomConverter.tr // Split meshes per material, so that we only have one material per mesh (for VBO support) lGeomConverter.SplitMeshesPerMaterial(lScene, /*replace*/true); return lScene; }
void reFBXAsset::import() { FbxImporter* importer = FbxImporter::Create(sdk,""); meshes = new reFileAsset(this); meshes->setPath("meshes"); children.push_back(meshes); if(!importer->Initialize(path().toUtf8().constData(), -1, sdk->GetIOSettings())) { printf("Call to FbxImporter::Initialize() failed.\n"); printf("Error returned: %s\n\n", importer->GetLastErrorString()); return; } FbxScene* lScene = FbxScene::Create(sdk, "myScene"); FbxAxisSystem ga(FbxAxisSystem::OpenGL); ga.ConvertScene(lScene); importer->Import(lScene); FbxNode* lRootNode = lScene->GetRootNode(); if(lRootNode) { reNode* node = importNode(lRootNode, NULL); node->name(info.baseName().toStdString()); QString path = dataDir() + QDir::separator() + node->name().c_str() + ".json"; node->save(path.toStdString()); } importer->Destroy(); }
FBXSceneImporter::FBXSceneImporter(std::string file_name) { std::string log_file_name = file_name; log_file_name.append("log.txt"); myfile.open(log_file_name.c_str()); // Initialize the SDK manager. This object handles memory management. lSdkManager = FbxManager::Create(); 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(file_name.c_str(), -1, lSdkManager->GetIOSettings())) { myfile << "Call to FbxImporter::Initialize() failed.\n"; myfile << "Error returned: " << lImporter->GetStatus().GetErrorString() << ""; myfile.close(); exit(-1); } // Create a new scene so that it can be populated by the imported file. 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(); FbxGeometryConverter converter(lSdkManager); converter.Triangulate(lScene, true); scene_to_fill = new Scene(Utilities::get_file_name_from_path_wo_extension(file_name)); resource_manager.add_scene(scene_to_fill); // 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++) { read_node(lRootNode->GetChild(i)); } } 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. myfile.close(); lSdkManager->Destroy(); }
bool FBXScene::LoadScene(const char* filename, std::ostream& output, Vector3& minPos, Vector3& maxPos) { int lFileMajor, lFileMinor, lFileRevision; int i, lAnimStackCount; bool lStatus; FbxIOSettings *ios = FbxIOSettings::Create(mSdkManager, IOSROOT); mSdkManager->SetIOSettings(ios); FbxGeometryConverter lGConverter(mSdkManager); // Create an importer using our sdk manager. FbxImporter* pFBXImporter = FbxImporter::Create(mSdkManager,""); // Initialize the importer by providing a filename. const bool lImportStatus = pFBXImporter->Initialize(filename, -1, mSdkManager->GetIOSettings()); pFBXImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision); if( !lImportStatus ) { output << "FBX Importer Error: " << pFBXImporter->GetStatus().GetErrorString() << std::endl; if ( pFBXImporter->GetStatus() == FbxStatus::eInvalidFileVersion ) { output << "FBX version number for file " << filename << " is " << lFileMajor << " " << lFileMinor << " " << lFileRevision << std::endl; } return false; } if (pFBXImporter->IsFBX()) { output << "FBX version number for file " << filename << " is " << lFileMajor << " " << lFileMinor << " " << lFileRevision << std::endl; // From this point, it is possible to access animation stack information without // the expense of loading the entire file. output << "Animation Stack Information" << std::endl; lAnimStackCount = pFBXImporter->GetAnimStackCount(); output << " Number of Animation Stacks: " << lAnimStackCount << std::endl; output << " Current Animation Stack: " << pFBXImporter->GetActiveAnimStackName().Buffer() << std::endl; for(i = 0; i < lAnimStackCount; i++) { FbxTakeInfo* lTakeInfo = pFBXImporter->GetTakeInfo(i); output << " Animation Stack " << i << std::endl; output << " Name: " << lTakeInfo->mName.Buffer() << std::endl; output << " Description: " << lTakeInfo->mDescription.Buffer() << std::endl; output << " Import Name: " << lTakeInfo->mImportName.Buffer() << std::endl; output << " Import State: " << (lTakeInfo->mSelect ? "true" : "false") << std::endl; } } // Import the scene. lStatus = pFBXImporter->Import(mScene); if ( !lStatus ) { output << "Failed Importing FBX!" << std::endl; output << "FBX is password protected!" << std::endl; if ( pFBXImporter->GetStatus() == FbxStatus::ePasswordError ) { output << "FBX is password protected!" << std::endl; } } mFilename = pFBXImporter->GetFileName().Buffer(); // Destroy the importer. pFBXImporter->Destroy(); ios->Destroy(); ProcessScene(mScene); return lStatus; }
void FbxLoader::LoadFromFile(const std::string& folder, const std::string& name, AxisMode axismode, float scaleFactor) { FbxManager* fbxManager = FbxManager::Create(); FbxIOSettings* ios = FbxIOSettings::Create(fbxManager, IOSROOT); fbxManager->SetIOSettings(ios); std::string path = folder + "\\" + name; relativeFolder = folder; FbxImporter* importer = (FbxImporter::Create(fbxManager, "")); bool b = importer->Initialize(path.c_str(), -1, fbxManager->GetIOSettings()); if(!b) { } scene = FbxScene::Create(fbxManager, path.c_str()); importer->Import(scene); int fileMajor, fileMinor, fileRevision; importer->GetFileVersion(fileMajor, fileMinor, fileRevision); importer->Destroy(); factor = scaleFactor; this->axismode = axismode; FbxNode* root = scene->GetRootNode(); FbxGeometryConverter geometryConverter(fbxManager); FbxAxisSystem axis = FbxAxisSystem::MayaYUp; axis.ConvertScene(scene); geometryConverter.Triangulate(scene, false); ProcessMaterial(scene); LoadAnimationClipData(); ProcessMeshNode(root, rootNode); }