예제 #1
0
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;
}
예제 #2
0
//===============================================================================================================================
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";
}
예제 #3
0
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;
}
예제 #4
0
파일: FBXScene.cpp 프로젝트: Malow/NDYGFX
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;
}
예제 #5
0
bool FBXReader::loadScene(FbxManager* fbxManager, FbxDocument* scene, string fileName)
{
    int lFileMajor, lFileMinor, lFileRevision;
    int lSDKMajor, lSDKMinor, lSDKRevision;
    //int lFileFormat = -1;
    int i, lAnimStackCount;
    bool lStatus;
    char lPassword[1024];

    // Get the file version number generate by the FBX SDK.
    FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision);

    // Create an importer.
    FbxImporter* lImporter = FbxImporter::Create(fbxManager, "");

    // Initialize the importer by providing a filename.
    const bool lImportStatus = lImporter->Initialize(fileName.c_str(), -1, fbxManager->GetIOSettings());
    lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);

    if (!lImportStatus)
    {
        FbxString error = lImporter->GetStatus().GetErrorString();
        FBXSDK_printf("Call to FbxImporter::Initialize() failed.\n");
        FBXSDK_printf("Error returned: %s\n\n", error.Buffer());

        if (lImporter->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion)
        {
            FBXSDK_printf("FBX file format version for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
            FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", fileName, lFileMajor, lFileMinor, lFileRevision);
        }

        return false;
    }

    FBXSDK_printf("FBX file format version for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);

    if (lImporter->IsFBX())
    {
        FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", fileName, lFileMajor, lFileMinor, lFileRevision);

        // From this point, it is possible to access animation stack information without
        // the expense of loading the entire file.

        FBXSDK_printf("Animation Stack Information\n");

        lAnimStackCount = lImporter->GetAnimStackCount();

        FBXSDK_printf("    Number of Animation Stacks: %d\n", lAnimStackCount);
        FBXSDK_printf("    Current Animation Stack: \"%s\"\n", lImporter->GetActiveAnimStackName().Buffer());
        FBXSDK_printf("\n");

        for (i = 0; i < lAnimStackCount; i++)
        {
            FbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i);

            FBXSDK_printf("    Animation Stack %d\n", i);
            FBXSDK_printf("         Name: \"%s\"\n", lTakeInfo->mName.Buffer());
            FBXSDK_printf("         Description: \"%s\"\n", lTakeInfo->mDescription.Buffer());

            // Change the value of the import name if the animation stack should be imported 
            // under a different name.
            FBXSDK_printf("         Import Name: \"%s\"\n", lTakeInfo->mImportName.Buffer());

            // Set the value of the import state to false if the animation stack should be not
            // be imported. 
            FBXSDK_printf("         Import State: %s\n", lTakeInfo->mSelect ? "true" : "false");
            FBXSDK_printf("\n");
        }

        // Set the import states. By default, the import states are always set to 
        // true. The code below shows how to change these states.
        IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true);
        IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true);
        IOS_REF.SetBoolProp(IMP_FBX_LINK, true);
        IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true);
        IOS_REF.SetBoolProp(IMP_FBX_GOBO, true);
        IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true);
        IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
    }

    // Import the scene.
    lStatus = lImporter->Import(scene);

    if (lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::ePasswordError)
    {
        FBXSDK_printf("Please enter password: "******"%s", lPassword);
        FBXSDK_CRT_SECURE_NO_WARNING_END

            FbxString lString(lPassword);

        IOS_REF.SetStringProp(IMP_FBX_PASSWORD, lString);
        IOS_REF.SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true);

        lStatus = lImporter->Import(scene);

        if (lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::ePasswordError)
        {
            FBXSDK_printf("\nPassword is wrong, import aborted.\n");
        }
    }

    // Destroy the importer.
    lImporter->Destroy();

    return lStatus;
}
예제 #6
0
파일: Scene.cpp 프로젝트: linuxaged/m3d
void LoadMeshes(Scene* pScene, std::vector<uint32_t>* loadedMeshIDs)
{
    FbxManager* fbxManager = FbxManager::Create();

    FbxIOSettings* pFbxIOSettings = FbxIOSettings::Create(fbxManager, IOSROOT);
    fbxManager->SetIOSettings(pFbxIOSettings);

    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_MATERIAL, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_TEXTURE, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_LINK, false);
    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_SHAPE, false);
    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_GOBO, false);
    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_ANIMATION, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);

    bool bEmbedMedia = true;
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_MATERIAL, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_TEXTURE, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_EMBEDDED, bEmbedMedia);
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_SHAPE, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_GOBO, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_ANIMATION, true);
    (*(fbxManager->GetIOSettings())).SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true);

    FbxImporter* pFbxImporter = FbxImporter::Create(fbxManager, "");

    // Initialize the importer.
    bool result = pFbxImporter->Initialize(pScene->loadPath.c_str(), -1, fbxManager->GetIOSettings());
    if (!result) {
        printf("Get error when init FBX Importer: %s\n\n",
            pFbxImporter->GetStatus().GetErrorString());
        exit(-1);
    }

    // fbx version number
    int major, minor, revision;
    pFbxImporter->GetFileVersion(major, minor, revision);

    // import pFbxScene
    FbxScene* pFbxScene = FbxScene::Create(fbxManager, "myScene");
    pFbxImporter->Import(pFbxScene);
    pFbxImporter->Destroy();
    pFbxImporter = nullptr;

    // check axis system
    FbxAxisSystem axisSystem = pFbxScene->GetGlobalSettings().GetAxisSystem();
    FbxAxisSystem vulkanAxisSystem(FbxAxisSystem::eYAxis,
        FbxAxisSystem::eParityOdd,
        FbxAxisSystem::eRightHanded);
    if (axisSystem != vulkanAxisSystem) {
        axisSystem.ConvertScene(pFbxScene);
    }

    // check unit system
    FbxSystemUnit systemUnit = pFbxScene->GetGlobalSettings().GetSystemUnit();
    if (systemUnit.GetScaleFactor() != 1.0) {
        FbxSystemUnit::cm.ConvertScene(pFbxScene);
    }

    // Triangulate Mesh
    FbxGeometryConverter fbxGeometryConverter(fbxManager);
    fbxGeometryConverter.Triangulate(pFbxScene, true);

    // Load Texture
    int textureCount = pFbxScene->GetTextureCount();
    for (int i = 0; i < textureCount; ++i) {
        FbxTexture* pFbxTexture = pFbxScene->GetTexture(i);
        FbxFileTexture* pFbxFileTexture = FbxCast<FbxFileTexture>(pFbxTexture);
        if (pFbxTexture && pFbxFileTexture->GetUserDataPtr()) {
        }
    }
    LoadMeshes(pFbxScene->GetRootNode(), pScene->meshes);
}
float UFBXBLUEPRINT::getCircleAreaDLL() //(float radius)
{
	// 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());

	if (!lImportStatus) {
		printf("Call to FbxImporter::Initialize() failed.\n");
		printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString());
		exit(-1);
	}

	// Create a new scene so 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 has been imported; we can get rid of the importer.
	lImporter->Destroy();

	// 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);


	int numofgeometrys = lScene->GetGeometryCount();

	for (int i = 0; i < numofgeometrys; i++)
	{
		fbxsdk::FbxGeometry* fbxgeo = lScene->GetGeometry(i);

	//	fbxsdk::FbxMesh* fbxmesh = fbxgeo->Get

		if (fbxgeo != 0)
		{
			int numofcontrolpoints =fbxgeo->GetControlPointsCount();
			FbxVector4* controlpoints = fbxgeo->GetControlPoints(0);
			// x[12] = controlpoints[12]->mData[0];

			//Fbxsdk::FbxVector4* pNormalArray;
			//fbxgeo->GetNormals(pNormalArray);
			//fbxgeo->GetNormalsIndices();

		//	fbxgeo->GetNormals();

		//	fbxgeo->get
		}
	}

	/*
	FbxClassId lShaderClassID = lSdkManager->FindFbxFileClass("Shader", "FlatShader");
	for(int i = 0; i < lNode->GetSrcObjectCount(lShaderClassID); i++) 
	{
		FbxObject* lObject = lNode->GetSrcObject(lShaderClassID, i);
	}
	*/
	return 1.00f;
}
예제 #8
0
bool LoaderFbx::loadScene(std::string filename)
{
	bool success = true;

	int fileMajor, fileMinor, fileRevision;
	int sdkMajor, sdkMinor, sdkRevision;
	std::stringstream message;

	FbxManager::GetFileFormatVersion(sdkMajor, sdkMinor, sdkRevision);

	FbxImporter* fbxImporter = FbxImporter::Create(fbxManager_, "");
	success = fbxImporter->Initialize(filename.c_str(), -1, fbxManager_->GetIOSettings());
	fbxImporter->GetFileVersion(fileMajor, fileMinor, fileRevision);

	if(!success)
	{
		message.str("");
		message << "LoaderFbx::loadScene | Call to FbxImporter::Initialize() failed! \n Error returned: " 
				<< fbxImporter->GetStatus().GetErrorString();
		ERROR_MESSAGEBOX(message.str());

		if(fbxImporter->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion)
		{
			std::stringstream message;
			message.str("");
			message << "FBX file format version for this FBX SDK is " << sdkMajor << "." << sdkMinor << "." << sdkRevision << "\n"
					<< "FBX file format version for file " << filename << " is " << fileMajor << "." << fileMinor << "." << fileRevision;
			ERROR_MESSAGEBOX(message.str());
		}
	}
	if(fbxImporter->IsFBX())
	{
		FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", filename, fileMajor, fileMinor, fileRevision);

        // From this point, it is possible to access animation stack information without
        // the expense of loading the entire file.

        FBXSDK_printf("Animation Stack Information\n");

        int animStackCount = fbxImporter->GetAnimStackCount();

        FBXSDK_printf("    Number of Animation Stacks: %d\n", animStackCount);
        FBXSDK_printf("    Current Animation Stack: \"%s\"\n", fbxImporter->GetActiveAnimStackName().Buffer());
        FBXSDK_printf("\n");

        for(int i = 0; i < animStackCount; i++)
        {
            FbxTakeInfo* takeInfo = fbxImporter->GetTakeInfo(i);

            FBXSDK_printf("    Animation Stack %d\n", i);
            FBXSDK_printf("         Name: \"%s\"\n", takeInfo->mName.Buffer());
			const char* debug = takeInfo->mDescription.Buffer();
	//		FBXSDK_printf("         Description: \"%s\"\n", takeInfo->mDescription.Buffer());
            
			// Change the value of the import name if the animation stack should be imported 
            // under a different name.
            FBXSDK_printf("         Import Name: \"%s\"\n", takeInfo->mImportName.Buffer());

            // Set the value of the import state to false if the animation stack should be not
            // be imported. 
            FBXSDK_printf("         Import State: %s\n", takeInfo->mSelect ? "true" : "false");
            FBXSDK_printf("\n");

			
        }

        // Set the import states. By default, the import states are always set to 
        // true. The code below shows how to change these states.
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_MATERIAL,        true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_TEXTURE,         true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_LINK,            true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_SHAPE,           true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_GOBO,            true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_ANIMATION,       true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
	}
	
	if(success)
	{
		success = fbxImporter->Import(fbxScene_);
	}

	if(!success)
	{
		message.str("");
		message << "LoaderFbx::loadScene | Call to FbxImporter::Import() failed! \n Error returned: "
				<< fbxImporter->GetStatus().GetErrorString();
		ERROR_MESSAGEBOX(message.str());
	}

	return success;
}
void GeometryLoaderDX11::loadFBXFile( std::string szFilename, std::vector<GeometryPtr>& vGeomVector, std::vector<std::string>& vNames )
{
	FileSystem fs;
	szFilename = fs.GetModelsFolderS() + szFilename;
	pFBXManager = FbxManager::Create();
	if( !pFBXManager )
		Log::Get().Write( L"CGeometryLoader11.cpp: Error creating FBX Manager!" );

	FbxIOSettings* pIOS = FbxIOSettings::Create( pFBXManager, IOSROOT );
	pFBXManager->SetIOSettings( pIOS );

	FbxString lPath = FbxGetApplicationDirectory();
	pFBXManager->LoadPluginsDirectory( lPath.Buffer() );

	FbxScene* pScene = FbxScene::Create( pFBXManager, "" );

	int /*nFileMajor,*/ nFileMinor, nFileRevision;
	int nSDKMajor, nSDKMinor, nSDKRevision;

	int i, /*nAnimationStack,*/ lFileFormat;
	//	bool bStatus;
	//	char szPassword[1024];

	FbxManager::GetFileFormatVersion( nSDKMajor, nSDKMinor, nSDKRevision );

	FbxImporter* pImporter = FbxImporter::Create( pFBXManager, "" );

	if (!pFBXManager->GetIOPluginRegistry()->DetectReaderFileFormat(szFilename.c_str(), lFileFormat) )
	{
		// Unrecognizable file format. Try to fall back to FbxImporter::eFBX_BINARY
		lFileFormat = pFBXManager->GetIOPluginRegistry()->FindReaderIDByDescription( "FBX binary (*.fbx)" );;
	}

	bool ImportStatus = pImporter->Initialize( szFilename.c_str(), lFileFormat, pFBXManager->GetIOSettings() );
	pImporter->GetFileVersion( nFileMinor, nFileMinor, nFileRevision );

	if( !ImportStatus )
	{
		Log::Get().Write( L"CGeometryLoader11.cpp: FbxImporter Initialize failed!" );
		return;
	}

	ImportStatus = pImporter->Import( pScene );

	if( !ImportStatus )
	{
		Log::Get().Write( L"CGeometryLoader11.cpp: FbxImporter failed to import the file to the scene!" );
		return;
	}

	FbxAxisSystem SceneAxisSystem = pScene->GetGlobalSettings().GetAxisSystem();
	FbxAxisSystem AxisSystem( FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eLeftHanded );
	if( SceneAxisSystem != AxisSystem )
	{
		AxisSystem.ConvertScene( pScene );
	}

	//FbxSystemUnit SceneSystemUnit = pScene->GetGlobalSettings().GetSystemUnit();
	//if( SceneSystemUnit.GetScaleFactor() != 1.0f )
	//	FbxSystemUnit::cm.ConvertScene( pScene );

	FBXTriangulateRecursive( pScene->GetRootNode() );

	FbxArray<FbxMesh*> vMeshs;
	FBXFillMeshArray( pScene, vMeshs );

	unsigned short usVertexCount = 0;
	unsigned short usTriangleCount = 0;
	unsigned short usGroupCount = 0;
	unsigned short usMaterialCount = 0;
	unsigned short usIndicesCount = 0;

	for( i = 0; i < vMeshs.GetCount(); i++ )
	{
		Log::Get().Write( L"CGeometryLoader11.cpp: Loading File!" );
		std::string name = vMeshs[i]->GetNode()->GetName();
		vNames.push_back( name );
		usVertexCount = vMeshs[i]->GetControlPointsCount();
		if( usVertexCount == 0 )
			continue;

		usTriangleCount = vMeshs[i]->GetPolygonVertexCount() / 3;
		usIndicesCount = vMeshs[i]->GetPolygonVertexCount();

		VertexElementDX11* pPositions = new VertexElementDX11( 3, usTriangleCount * 3 );
		pPositions->m_SemanticName = VertexElementDX11::PositionSemantic;
		pPositions->m_uiSemanticIndex = 0;
		pPositions->m_Format = DXGI_FORMAT_R32G32B32_FLOAT;
		pPositions->m_uiInputSlot = 0;
		pPositions->m_uiAlignedByteOffset = 0;
		pPositions->m_InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
		pPositions->m_uiInstanceDataStepRate = 0;

		VertexElementDX11* pTexCoords = new VertexElementDX11( 2, usTriangleCount * 3 );
		pTexCoords->m_SemanticName = VertexElementDX11::TexCoordSemantic;
		pTexCoords->m_uiSemanticIndex = 0;
		pTexCoords->m_Format = DXGI_FORMAT_R32G32_FLOAT;
		pTexCoords->m_uiInputSlot = 0;
		pTexCoords->m_uiAlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
		pTexCoords->m_InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
		pTexCoords->m_uiInstanceDataStepRate = 0;

		VertexElementDX11* pNormals = new VertexElementDX11( 3, usTriangleCount * 3 );
		pNormals->m_SemanticName = VertexElementDX11::NormalSemantic;
		pNormals->m_uiSemanticIndex = 0;
		pNormals->m_Format = DXGI_FORMAT_R32G32B32_FLOAT;
		pNormals->m_uiInputSlot = 0;
		pNormals->m_uiAlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
		pNormals->m_InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
		pNormals->m_uiInstanceDataStepRate = 0;

		Vector3f* pPos = pPositions->Get3f(0);
		Vector3f* pNorm = pNormals->Get3f(0);
		Vector2f* pTex = pTexCoords->Get2f(0);

		FbxVector4* pFBXVerts = new FbxVector4[usVertexCount];
		memcpy( pFBXVerts, vMeshs[i]->GetControlPoints(), usVertexCount * sizeof(FbxVector4));

		TriangleIndices face;

		GeometryPtr pGeomPointer( new GeometryDX11() );

		for( int j = 0; j < usTriangleCount; j++ )
		{	
			int nIndex = 0;
			FbxVector4 FBXNorm( 0, 0, 0, 0 );
			FbxVector2 FBXUV( 0, 0 );

			face.P1() = nIndex = vMeshs[i]->GetPolygonVertex( j, 0 );
			pPos[nIndex].x = (float)pFBXVerts[ nIndex ][0];
			pPos[nIndex].y = (float)pFBXVerts[ nIndex ][1];
			pPos[nIndex].z = (float)pFBXVerts[ nIndex ][2];
			vMeshs[i]->GetPolygonVertexNormal( j, 0, FBXNorm );
			pNorm[nIndex].x = (float)FBXNorm[0];
			pNorm[nIndex].y = (float)FBXNorm[1];
			pNorm[nIndex].z = (float)FBXNorm[2];
			vMeshs[i]->GetPolygonVertexUV( j, 0, "map1", FBXUV );
			pTex[nIndex].x = (float)FBXUV[0];
			pTex[nIndex].y = (float)FBXUV[1];

			face.P2() = nIndex = vMeshs[i]->GetPolygonVertex( j, 1 );
			pPos[nIndex].x = (float)pFBXVerts[ nIndex ][0];
			pPos[nIndex].y = (float)pFBXVerts[ nIndex ][1];
			pPos[nIndex].z = (float)pFBXVerts[ nIndex ][2];
			vMeshs[i]->GetPolygonVertexNormal( j, 1, FBXNorm );
			pNorm[nIndex].x = (float)FBXNorm[0];
			pNorm[nIndex].y = (float)FBXNorm[1];
			pNorm[nIndex].z = (float)FBXNorm[2];
			vMeshs[i]->GetPolygonVertexUV( j, 1, "map1", FBXUV );
			pTex[nIndex].x = (float)FBXUV[0];
			pTex[nIndex].y = (float)FBXUV[1];

			face.P3() = nIndex = vMeshs[i]->GetPolygonVertex( j, 2 );
			pPos[nIndex].x = (float)pFBXVerts[ nIndex ][0];
			pPos[nIndex].y = (float)pFBXVerts[ nIndex ][1];	
			pPos[nIndex].z = (float)pFBXVerts[ nIndex ][2];
			vMeshs[i]->GetPolygonVertexNormal( j, 2, FBXNorm );
			pNorm[nIndex].x = (float)FBXNorm[0];
			pNorm[nIndex].y = (float)FBXNorm[1];
			pNorm[nIndex].z = (float)FBXNorm[2];
			vMeshs[i]->GetPolygonVertexUV( j, 2, "map1", FBXUV );
			pTex[nIndex].x = (float)FBXUV[0];
			pTex[nIndex].y = (float)FBXUV[1];

			pGeomPointer->AddFace( face );
		}

		for( int j = 0; j < usVertexCount; j++ )
		{
			pNorm[j].Normalize();
		}

		pGeomPointer->AddElement( pPositions );
		pGeomPointer->AddElement( pNormals );
		pGeomPointer->AddElement( pTexCoords );

		delete[] pFBXVerts;
		vGeomVector.push_back( pGeomPointer );

		vMeshs[i]->Destroy();
		vMeshs[i] = NULL;
	}


	pImporter->Destroy();
	pImporter = NULL;

	pScene->Destroy();
	pScene = NULL;

	pIOS->Destroy();
	pIOS = NULL;

	pFBXManager->Destroy();
	pFBXManager = NULL;
}
예제 #10
-1
		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);			
		}