コード例 #1
0
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;
}
コード例 #2
0
ファイル: SceneImporter.cpp プロジェクト: fawnha/morftech
/*
Imports all the scene data and creates the mesh and bone instances from it
*/
void SceneImporter::loadFile()
{
	bool lResult = false;
	if (mImporter->Import(mScene) == true)
	{
		// 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);
		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);
		// Create the animator
		Animator::create(mScene);

		// Convert mesh, NURBS and patch into triangle mesh
		FbxGeometryConverter lGeomConverter(mSdkManager);
		lGeomConverter.Triangulate(mScene, /*replace*/true);

		// Split meshes per material, so that we only have one material per mesh (for VBO support)
		lGeomConverter.SplitMeshesPerMaterial(mScene, /*replace*/true);
		// Extract all bone nodes
		extractBonesRecursive(mScene->GetRootNode());

		// Load all meshes from scene
		FbxAMatrix lDummyGlobalPosition;

		// Extract all meshes
		loadCacheRecursive(mScene->GetRootNode());

		// Load all the animation keyframe data
		Animator::get()->precacheAnimationData();
	}

	// Destroy the importer to release the file.
	mImporter->Destroy();
	mImporter = NULL;
}
コード例 #3
0
ファイル: BImporter.cpp プロジェクト: milkProvider/glProject
BGameObject * BImporter::loadObject(string pPath)
{
    //do i really need importer??
    mImporter = FbxImporter::Create(lSdkManager,"");
    int lFileFormat = -1;
	const char* mFileName = pPath.c_str();
    if (!lSdkManager->GetIOPluginRegistry()->DetectReaderFileFormat(mFileName, lFileFormat) )
    {
        // Unrecognizable file format. Try to fall back to FbxImporter::eFBX_BINARY
        lFileFormat = lSdkManager->GetIOPluginRegistry()->FindReaderIDByDescription( "FBX binary (*.fbx)" );;
    }

	if(mImporter->Initialize(pPath.c_str(), lFileFormat) == true)
    {

    }
    //else error
    //mScene->GetRootNode()


        if (mImporter->Import(lScene) == true)
        {
			printf("Importing...");
            // Convert Axis System to what is used in this example, if needed
            FbxAxisSystem SceneAxisSystem = lScene->GetGlobalSettings().GetAxisSystem();
            FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded);
            if( SceneAxisSystem != OurAxisSystem )
            {
                OurAxisSystem.ConvertScene(lScene);
            }

            // Convert Unit System to what is used in this example, if needed
            FbxSystemUnit SceneSystemUnit = lScene->GetGlobalSettings().GetSystemUnit();
            if( SceneSystemUnit.GetScaleFactor() != 1.0 )
            {
                //The unit in this example is centimeter.
                FbxSystemUnit::cm.ConvertScene( lScene);
            }

            // Get the list of all the animation stack.
            lScene->FillAnimStackNameArray(mAnimStackNameArray);
            // Convert mesh, NURBS and patch into triangle mesh
			FbxGeometryConverter lGeomConverter(lSdkManager);
			lGeomConverter.Triangulate(lScene, true);

			// Split meshes per material, so that we only have one material per mesh (for VBO support)
			lGeomConverter.SplitMeshesPerMaterial(lScene, true);


			BGameObject *lGameObject = prepareVBOMeshes(lScene);
            return lGameObject;
            // Bake the scene for one frame
            //LoadCacheRecursive(mScelGeomConverterne, 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 frame period.
            //mFrameTime.SetTime(0, 0, 0, 1, 0, lScene->GetGlobalSettings().GetTimeMode());
            //lResult = true;
        }
        printf("Cant import this object");
        return NULL;
}
コード例 #4
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);
}
コード例 #5
0
ファイル: SceneContext.cpp プロジェクト: artint-liu/Marimo
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;
}