FbxModelData* FBXLoader::loadModel( const char* aFile ) { FBX_LOG("FBXLoader Creating ModelData..."); myLoadingModel = new FbxModelData; FBX_LOG("Success!"); FBX_LOG("FBXLoader Creating TextureData..."); myLoadingModel->myTextureData = new TextureData(); FBX_LOG("Success!"); FBX_LOG("FBXLoader Loading Scene..."); auto scene = LoadScene(aFile); FBX_LOG("Successfully loaded scene!"); FBX_LOG("FBXLoader Loading Textures..."); //TextureData const int lTextureCount = scene->GetTextureCount(); for (int lTextureIndex = 0; lTextureIndex < lTextureCount; ++lTextureIndex) { FbxTexture * lTexture = scene->GetTexture(lTextureIndex); FbxFileTexture * lFileTexture = reinterpret_cast<FbxFileTexture*>(lTexture); if (lFileTexture && !lFileTexture->GetUserDataPtr()) { const FbxString lFileName = lFileTexture->GetFileName(); unsigned int lTextureObject = 0; lTextureObject; bool lStatus = false; lStatus; const FbxString lAbsFbxFileName = FbxPathUtils::Resolve(aFile); const FbxString lAbsFolderName = FbxPathUtils::GetFolderName(lAbsFbxFileName); const FbxString lTextureFileName = lAbsFolderName + "\\" + lFileTexture->GetRelativeFileName();// FbxPathUtils::GetFileName(lFileName); const FbxString lResolvedFileName = lAbsFolderName + "\\" + FbxPathUtils::GetFileName(lFileName);// lFileTexture->GetRelativeFileName();;// FbxPathUtils::Bind(lAbsFolderName, lTextureFileName); TextureInfo info; info.myFileName = lResolvedFileName; //info.myFileName += "\\"; info.myFileName = lFileTexture->GetRelativeFileName(); myLoadingModel->myTextureData->myTextures.push_back(info); lFileTexture->SetFileName(lResolvedFileName); } } FBX_LOG("Success!"); FBX_LOG("FBXLoader Loading Animations..."); FbxArray<FbxString*> animationNames; FbxArray<FbxPose*> poses; scene->FillAnimStackNameArray(animationNames); scene->FillPoseArray(poses); FbxAnimStack * lCurrentAnimationStack = nullptr; FbxAnimLayer* lCurrentAnimLayer = nullptr; if(animationNames.GetCount() > 0) { lCurrentAnimationStack = scene->FindMember<FbxAnimStack>(animationNames[0]->Buffer()); if (lCurrentAnimationStack != NULL) { lCurrentAnimLayer = lCurrentAnimationStack->GetMember<FbxAnimLayer>(); } } //lCurrentAnimLayer->IsR myLoadingModel->myAnimation = new AnimationData(); FbxPose* pose = nullptr; if(poses.GetCount() > 0) { pose = poses[0]; } LoadAnimation(*myLoadingModel->myAnimation,scene->GetRootNode(),FbxAMatrix(),pose, lCurrentAnimLayer,-1); LoadNodeRecursive(myLoadingModel, *myLoadingModel->myAnimation, scene->GetRootNode(), FbxAMatrix(), pose, lCurrentAnimLayer, -1); FBX_LOG("Success!"); return myLoadingModel; }
bool SceneContext::LoadFile() { bool lResult = false; // Make sure that the scene is ready to load. if (mStatus == MUST_BE_LOADED) { if (mImporter->Import(mScene) == true) { // Set the scene status flag to refresh // the scene in the first timer callback. mStatus = MUST_BE_REFRESHED; // Convert Axis System to what is used in this example, if needed FbxAxisSystem SceneAxisSystem = mScene->GetGlobalSettings().GetAxisSystem(); //FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded); FbxAxisSystem OurAxisSystem(FbxAxisSystem::eOpenGL); //m_matGlobal.SetRow(1, float4(0,0,-1,0)); //m_matGlobal.SetRow(2, float4(0,1,0,0)); if( SceneAxisSystem != OurAxisSystem ) { OurAxisSystem.ConvertScene(mScene); } // Convert Unit System to what is used in this example, if needed FbxSystemUnit SceneSystemUnit = mScene->GetGlobalSettings().GetSystemUnit(); if( SceneSystemUnit.GetScaleFactor() != 1.0 ) { //The unit in this example is centimeter. FbxSystemUnit::cm.ConvertScene( mScene); } // Get the list of all the animation stack. mScene->FillAnimStackNameArray(mAnimStackNameArray); SetCurrentAnimStack(0); // Get the list of all the cameras in the scene. FillCameraArray(mScene, mCameraArray); // Convert mesh, NURBS and patch into triangle mesh TriangulateRecursive(mScene->GetRootNode()); // Bake the scene for one frame //LoadCacheRecursive(this, mScene, mCurrentAnimLayer, mFileName, mSupportVBO); // Convert any .PC2 point cache data into the .MC format for // vertex cache deformer playback. PreparePointCacheData(mScene, mCache_Start, mCache_Stop); // Get the list of pose in the scene FillPoseArray(mScene, mPoseArray); // Initialize the window message. mWindowMessage = "File "; mWindowMessage += WS2AS(m_FileName); mWindowMessage += "\nClick on the right mouse button to enter menu."; mWindowMessage += "\nEsc to exit."; // Initialize the frame period. mFrameTime.SetTime(0, 0, 0, 1, 0, mScene->GetGlobalSettings().GetTimeMode()); // Print the keyboard shortcuts. //FBXSDK_printf("Play/Pause Animation: Space Bar.\n"); //FBXSDK_printf("Camera Rotate: Left Mouse Button.\n"); //FBXSDK_printf("Camera Pan: Left Mouse Button + Middle Mouse Button.\n"); //FBXSDK_printf("Camera Zoom: Middle Mouse Button.\n"); lResult = true; } else { // Import failed, set the scene status flag accordingly. mStatus = UNLOADED; mWindowMessage = "Unable to import file "; mWindowMessage += WS2AS(m_FileName); mWindowMessage += "\nError reported: "; mWindowMessage += mImporter->GetLastErrorString(); } // Destroy the importer to release the file. mImporter->Destroy(); mImporter = NULL; } // Bake the scene for one frame LoadCacheRecursive(this, mScene, mCurrentAnimLayer, m_FileName, m_bSupportVBO); return lResult; }