2
我試圖從fbx文件中使用fbx sdk獲取信息時卡住了。我在瑪雅創建了一個帶有紋理的fbx模型。所有我想要做的就是找到完整的文件名在代碼中使用的紋理...從fbx讀取紋理文件名與fbx sdk C++
這裏是一些代碼:
void Model::GetFbxInfo(FbxNode* Node)
{
int numKids = Node->GetChildCount();
FbxNode* childNode = 0;
for (int i = 0; i < numKids; i++)
{
childNode = Node->GetChild(i);
FbxMesh* mesh = childNode->GetMesh();
if (mesh != NULL)
{
// get vertices, indices, uv, etc
// some more code...
// get vertices, indices, uv, etc
//================= Texture ========================================
int materialCount = childNode->GetSrcObjectCount<FbxSurfaceMaterial>();
for (int index = 0; index < materialCount; index++)
{
FbxSurfaceMaterial* material = (FbxSurfaceMaterial*)childNode->GetSrcObject<FbxSurfaceMaterial>(index);
if (material != NULL)
{
LOG(INFO) << "\nmaterial: " << material->GetName() << std::endl;
// This only gets the material of type sDiffuse, you probably need to traverse all Standard Material Property by its name to get all possible textures.
FbxProperty prop = material->FindProperty(FbxSurfaceMaterial::sDiffuse);
// Check if it's layeredtextures
int layeredTextureCount = prop.GetSrcObjectCount<FbxLayeredTexture>();
if (layeredTextureCount > 0)
{
for (int j = 0; j < layeredTextureCount; j++)
{
FbxLayeredTexture* layered_texture = FbxCast<FbxLayeredTexture>(prop.GetSrcObject<FbxLayeredTexture>(j));
int lcount = layered_texture->GetSrcObjectCount<FbxTexture>();
for (int k = 0; k < lcount; k++)
{
FbxTexture* texture = FbxCast<FbxTexture>(layered_texture->GetSrcObject<FbxTexture>(k));
// Then, you can get all the properties of the texture, include its name
const char* textureName = texture->GetName();
LOG(INFO) << textureName;
}
}
}
else
{
// Directly get textures
int textureCount = prop.GetSrcObjectCount<FbxTexture>();
for (int j = 0; j < textureCount; j++)
{
FbxTexture* texture = FbxCast<FbxTexture>(prop.GetSrcObject<FbxTexture>(j));
// Then, you can get all the properties of the texture, include its name
const char* textureName = texture->GetName();
LOG(INFO) << textureName;
FbxProperty p = texture->RootProperty.Find("Filename");
LOG(INFO) << p.Get<FbxString>() << std::endl;
HRESULT hr;
D3DX11CreateTextureFromFile(Game::GetInstance()->GetRenderer()->GetDevice(), textureName, 0, 0, &m_texture, &hr);
if(FAILED(hr))
{
std::string message;
message.append("Load Texture: ");
message.append(texture->GetName());
message.append(" failed");
SHOWMESSAGEBOX(hr, message.c_str());
}
}
}
}
}
this->GetFbxInfo(childNode);
}
}
}
這是一個瀰漫性非層狀紋理......所以, else分支是重要的...... textureCount是1 - 這樣的紋理被發現,但文件名和質地的getName只返回「文件1」
這裏有一塊從ASCII-FBX文件數據的,我裝
Video: 900530112, "Video::file1", "Clip" {
Type: "Clip"
Properties70: {
P: "Path", "KString", "XRefUrl", "", "D:/Dropbox/Projects/MyModel/MyTexture.jpg"
}
UseMipMap: 0
Filename: "D:/Dropbox/Projects/MyModel/MyTexture.jpg"
RelativeFilename: "MyTexture.jpg"
}
Texture: 785759328, "Texture::file1", "" {
Type: "TextureVideoClip"
Version: 202
TextureName: "Texture::file1"
Properties70: {
P: "CurrentTextureBlendMode", "enum", "", "",0
P: "UVSet", "KString", "", "", "map1"
P: "UseMaterial", "bool", "", "",1
}
Media: "Video::file1"
FileName: "D:/Dropbox/Projects/MyModel/MyTexture.jpg"
RelativeFilename: "MyTexture.jpg"
ModelUVTranslation: 0,0
ModelUVScaling: 1,1
Texture_Alpha_Source: "None"
Cropping: 0,0,0,0
}
任何人都可以幫我理解我做錯了什麼嗎?
thx!