Esempio n. 1
0
    // Unload the cache and release the memory fro this scene and release the textures in GPU
    void UnloadCacheRecursive(FbxScene * pScene)
    {
        const int lTextureCount = pScene->GetTextureCount();
        for (int lTextureIndex = 0; lTextureIndex < lTextureCount; ++lTextureIndex)
        {
            FbxTexture * lTexture = pScene->GetTexture(lTextureIndex);
            FbxFileTexture * lFileTexture = FbxCast<FbxFileTexture>(lTexture);
            if (lFileTexture && lFileTexture->GetUserDataPtr())
            {
                int * lTextureName = static_cast<int *>(lFileTexture->GetUserDataPtr());
                lFileTexture->SetUserDataPtr(NULL);
                //glDeleteTextures(1, lTextureName);
                delete lTextureName;
            }
        }

        UnloadCacheRecursive(pScene->GetRootNode());
    }
Esempio n. 2
0
    // Bake node attributes and materials for this scene and load the textures.
    void LoadCacheRecursive(SceneContext* pSceneCtx, FbxScene * pScene, FbxAnimLayer * pAnimLayer, GXLPCWSTR pFbxFileName, bool pSupportVBO)
    {
        // Load the textures into GPU, only for file texture now
        const int lTextureCount = pScene->GetTextureCount();
        for (int lTextureIndex = 0; lTextureIndex < lTextureCount; ++lTextureIndex)
        {
            FbxTexture * lTexture = pScene->GetTexture(lTextureIndex);
            FbxFileTexture * lFileTexture = FbxCast<FbxFileTexture>(lTexture);
            if (lFileTexture && !lFileTexture->GetUserDataPtr())
            {
                // Try to load the texture from absolute path
                const FbxString lFileName = lFileTexture->GetFileName();
                
                // Only TGA textures are supported now.
                //if (lFileName.Right(3).Upper() != "TGA")
                //{
                //    FBXSDK_printf("Only TGA textures are supported now: %s\n", lFileName.Buffer());
                //    continue;
                //}

                //unsigned int lTextureObject = 0;
                //bool lStatus = LoadTextureFromFile(lFileName, lTextureObject);

                //const FbxString lAbsFbxFileName = FbxPathUtils::Resolve(pFbxFileName);
                //const FbxString lAbsFolderName = FbxPathUtils::GetFolderName(lAbsFbxFileName);
                //if (!lStatus)
                //{
                //    // Load texture from relative file name (relative to FBX file)
                //    const FbxString lResolvedFileName = FbxPathUtils::Bind(lAbsFolderName, lFileTexture->GetRelativeFileName());
                //    lStatus = LoadTextureFromFile(lResolvedFileName, lTextureObject);
                //}

                //if (!lStatus)
                //{
                //    // Load texture from file name only (relative to FBX file)
                //    const FbxString lTextureFileName = FbxPathUtils::GetFileName(lFileName);
                //    const FbxString lResolvedFileName = FbxPathUtils::Bind(lAbsFolderName, lTextureFileName);
                //    lStatus = LoadTextureFromFile(lResolvedFileName, lTextureObject);
                //}

                //if (!lStatus)
                //{
                //    FBXSDK_printf("Failed to load texture file: %s\n", lFileName.Buffer());
                //    continue;
                //}

                //if (lStatus)
                //{
                //    int * lTextureName = new int(lTextureObject);
                //    lFileTexture->SetUserDataPtr(lTextureName);
                //}
            }
        }

        LoadCacheRecursive(pSceneCtx, pScene->GetRootNode(), pAnimLayer, pSupportVBO);
    }
Esempio n. 3
0
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);
}
Esempio n. 4
0
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;
}