// 三角形化 void CFBXLoader::TriangulateRecursive(FbxNode* pNode) { FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh || lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eNurbs || lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eNurbsSurface || lNodeAttribute->GetAttributeType() == FbxNodeAttribute::ePatch) { FbxGeometryConverter lConverter(pNode->GetFbxManager()); // これでどんな形状も三角形化 #if 0 lConverter.TriangulateInPlace(pNode); // 古い手法 #endif // 0 lConverter.Triangulate( mScene, true ); } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { // 子ノードを探索 TriangulateRecursive(pNode->GetChild(lChildIndex)); } }
HRESULT CFBXLoader::LoadFBX(const char* filename, const eAXIS_SYSTEM axis) { if(!filename) return E_FAIL; HRESULT hr = S_OK; InitializeSdkObjects( mSdkManager, mScene ); if(!mSdkManager) return E_FAIL; // インポータ作成 int lFileFormat = -1; mImporter = FbxImporter::Create(mSdkManager,""); if (!mSdkManager->GetIOPluginRegistry()->DetectReaderFileFormat(filename, lFileFormat) ) { // Unrecognizable file format. Try to fall back to FbxImporter::eFBX_BINARY lFileFormat = mSdkManager->GetIOPluginRegistry()->FindReaderIDByDescription( "FBX binary (*.fbx)" );; } // Initialize the importer by providing a filename. if(!mImporter || mImporter->Initialize(filename, lFileFormat) == false) return E_FAIL; // if( !mImporter || mImporter->Import(mScene) == false ) return E_FAIL; FbxAxisSystem OurAxisSystem = FbxAxisSystem::DirectX; if(axis==eAXIS_OPENGL) OurAxisSystem = FbxAxisSystem::OpenGL; // DirectX系 FbxAxisSystem SceneAxisSystem = mScene->GetGlobalSettings().GetAxisSystem(); if(SceneAxisSystem != OurAxisSystem) { FbxAxisSystem::DirectX.ConvertScene(mScene); } // 単位系の統一 // 不要でもいいかも FbxSystemUnit SceneSystemUnit = mScene->GetGlobalSettings().GetSystemUnit(); if( SceneSystemUnit.GetScaleFactor() != 1.0 ) { // センチメーター単位にコンバートする FbxSystemUnit::cm.ConvertScene( mScene ); } // 三角形化(三角形以外のデータでもコレで安心) TriangulateRecursive(mScene->GetRootNode()); Setup(); return hr; }
// Triangulate all NURBS, patch and mesh under this node recursively. void TriangulateRecursive(FbxNode* pNode) { FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { FbxNodeAttribute::EType eAttrType = lNodeAttribute->GetAttributeType(); if (eAttrType == FbxNodeAttribute::eMesh || eAttrType == FbxNodeAttribute::eNurbs || eAttrType == FbxNodeAttribute::eNurbsSurface || eAttrType == FbxNodeAttribute::ePatch) { FbxGeometryConverter lConverter(pNode->GetFbxManager()); lConverter.TriangulateInPlace(pNode); } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { TriangulateRecursive(pNode->GetChild(lChildIndex)); } }
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; }